mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-24 13:45:49 +00:00
update code
This commit is contained in:
@@ -9,126 +9,141 @@ from xrpl.models.requests import NFTBuyOffers
|
||||
from xrpl.models.transactions import NFTokenAcceptOffer
|
||||
testnet_url = "https://s.altnet.rippletest.net:51234"
|
||||
|
||||
def create_sell_offer(_seed, _amount, _nftoken_id, _expiration, _destination):
|
||||
def create_sell_offer(seed, amount, nftoken_id, expiration, destination):
|
||||
"""create_sell_offer"""
|
||||
# Get the client
|
||||
owner_wallet = Wallet(_seed, sequence = 16237283)
|
||||
client = JsonRpcClient(testnet_url)
|
||||
owner_wallet = Wallet(seed, sequence=16237283)
|
||||
client = JsonRpcClient(testnet_url)
|
||||
expiration_date = datetime.now()
|
||||
if (_expiration != ''):
|
||||
if expiration != '':
|
||||
expiration_date = xrpl.utils.datetime_to_ripple_time(expiration_date)
|
||||
expiration_date = expiration_date + int(_expiration)
|
||||
expiration_date = expiration_date + int(expiration)
|
||||
# Define the sell offer
|
||||
sell_offer_tx = xrpl.models.transactions.NFTokenCreateOffer(
|
||||
account = owner_wallet.classic_address,
|
||||
nftoken_id = _nftoken_id,
|
||||
amount = _amount,
|
||||
destination=_destination if _destination != '' else None,
|
||||
expiration = expiration_date if _expiration != '' else None,
|
||||
flags = 1
|
||||
sell_offer_tx=xrpl.models.transactions.NFTokenCreateOffer(
|
||||
account=owner_wallet.classic_address,
|
||||
nftoken_id=nftoken_id,
|
||||
amount=amount,
|
||||
destination=destination if destination != '' else None,
|
||||
expiration=expiration_date if expiration != '' else None,
|
||||
flags=1
|
||||
)
|
||||
# Sign and fill the transaction
|
||||
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
sell_offer_tx, owner_wallet, client)
|
||||
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
sell_offer_tx, owner_wallet, client)
|
||||
# Submit the transaction and report the results
|
||||
reply=""
|
||||
try:
|
||||
response = xrpl.transaction.send_reliable_submission(signed_tx,client)
|
||||
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
|
||||
reply=response.result
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
response = f"Submit failed: {e}"
|
||||
return response.result
|
||||
def accept_sell_offer(_seed, _offer_index):
|
||||
buyer_wallet = Wallet(_seed, sequence = 16237283)
|
||||
client = JsonRpcClient(testnet_url)
|
||||
accept_offer_tx = xrpl.models.transactions.NFTokenAcceptOffer(
|
||||
account = buyer_wallet.classic_address,
|
||||
nftoken_sell_offer = _offer_index
|
||||
)
|
||||
# Sign and fill the transaction
|
||||
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
accept_offer_tx, buyer_wallet, client)
|
||||
# Submit the transaction and report the results
|
||||
try:
|
||||
response = xrpl.transaction.send_reliable_submission(signed_tx,client)
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
response = f"Submit failed: {e}"
|
||||
return response.result
|
||||
reply=f"Submit failed: {e}"
|
||||
return reply
|
||||
|
||||
def create_buy_offer(_seed, _amount, _nft_id, _owner, _expiration, _destination):
|
||||
|
||||
def accept_sell_offer(seed, offer_index):
|
||||
"""accept_sell_offer"""
|
||||
buyer_wallet=Wallet(seed, sequence=16237283)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer(
|
||||
account=buyer_wallet.classic_address,
|
||||
nftoken_sell_offer=offer_index
|
||||
)
|
||||
# Sign and fill the transaction
|
||||
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
accept_offer_tx, buyer_wallet, client)
|
||||
# Submit the transaction and report the results
|
||||
reply=""
|
||||
try:
|
||||
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
|
||||
reply=response.result
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
reply=f"Submit failed: {e}"
|
||||
return reply
|
||||
|
||||
|
||||
def create_buy_offer(seed, amount, nft_id, owner, expiration, destination):
|
||||
"""create_buy_offer"""
|
||||
# Get the client
|
||||
buyer_wallet = Wallet(_seed, sequence = 16237283)
|
||||
client = JsonRpcClient(testnet_url)
|
||||
expiration_date = datetime.now()
|
||||
if (_expiration != ''):
|
||||
expiration_date = xrpl.utils.datetime_to_ripple_time(expiration_date)
|
||||
expiration_date = expiration_date + int(_expiration)
|
||||
buyer_wallet=Wallet(seed, sequence=16237283)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
expiration_date=datetime.now()
|
||||
if (expiration!=''):
|
||||
expiration_date=xrpl.utils.datetime_to_ripple_time(expiration_date)
|
||||
expiration_date=expiration_date + int(expiration)
|
||||
# Define the buy offer transaction with an expiration date
|
||||
buy_offer_tx = xrpl.models.transactions.NFTokenCreateOffer(
|
||||
account = buyer_wallet.classic_address,
|
||||
nftoken_id = _nft_id,
|
||||
amount = _amount,
|
||||
owner = _owner,
|
||||
expiration = expiration_date if _expiration != '' else None,
|
||||
destination=_destination if _destination != '' else None,
|
||||
flags = 0
|
||||
buy_offer_tx=xrpl.models.transactions.NFTokenCreateOffer(
|
||||
account=buyer_wallet.classic_address,
|
||||
nftoken_id=nft_id,
|
||||
amount=amount,
|
||||
owner=owner,
|
||||
expiration=expiration_date if expiration!='' else None,
|
||||
destination=destination if destination!='' else None,
|
||||
flags=0
|
||||
)
|
||||
# Sign and fill the transaction
|
||||
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
buy_offer_tx, buyer_wallet, client)
|
||||
# Submit the transaction and report the results
|
||||
reply=""
|
||||
try:
|
||||
response = xrpl.transaction.send_reliable_submission(signed_tx,client)
|
||||
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
|
||||
reply=response.result
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
response = f"Submit failed: {e}"
|
||||
return response.result
|
||||
def accept_buy_offer(_seed, _offer_index):
|
||||
buyer_wallet = Wallet(_seed, sequence = 16237283)
|
||||
client = JsonRpcClient(testnet_url)
|
||||
accept_offer_tx = xrpl.models.transactions.NFTokenAcceptOffer(
|
||||
account = buyer_wallet.classic_address,
|
||||
nftoken_buy_offer = _offer_index
|
||||
reply=f"Submit failed: {e}"
|
||||
return reply
|
||||
|
||||
|
||||
def accept_buy_offer(seed, offer_index):
|
||||
"""accept_buy_offer"""
|
||||
buyer_wallet=Wallet(seed, sequence=16237283)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer(
|
||||
account=buyer_wallet.classic_address,
|
||||
nftoken_buy_offer=offer_index
|
||||
)
|
||||
# Sign and fill the transaction
|
||||
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
accept_offer_tx, buyer_wallet, client)
|
||||
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
accept_offer_tx, buyer_wallet, client)
|
||||
# Submit the transaction and report the results
|
||||
reply=""
|
||||
try:
|
||||
response = xrpl.transaction.send_reliable_submission(signed_tx,client)
|
||||
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
|
||||
reply=response.result
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
response = f"Submit failed: {e}"
|
||||
return response.result
|
||||
reply=f"Submit failed: {e}"
|
||||
return reply
|
||||
|
||||
def get_offers(_nft_id):
|
||||
client = JsonRpcClient(testnet_url)
|
||||
offers = NFTBuyOffers(
|
||||
nft_id=_nft_id
|
||||
def get_offers(nft_id):
|
||||
"""get_offers"""
|
||||
client=JsonRpcClient(testnet_url)
|
||||
offers=NFTBuyOffers(
|
||||
nft_id=nft_id
|
||||
)
|
||||
response = client.request(offers)
|
||||
allOffers = "Buy Offers:\n" + json.dumps(response.result, indent=4)
|
||||
offers = NFTSellOffers(
|
||||
nft_id=_nft_id
|
||||
response=client.request(offers)
|
||||
allOffers="Buy Offers:\n"+json.dumps(response.result, indent=4)
|
||||
offers=NFTSellOffers(
|
||||
nft_id=nft_id
|
||||
)
|
||||
response = client.request(offers)
|
||||
allOffers += "\n\nSell Offers:\n" + json.dumps(response.result, indent=4)
|
||||
response=client.request(offers)
|
||||
allOffers+="\n\nSell Offers:\n"+json.dumps(response.result, indent=4)
|
||||
return allOffers
|
||||
|
||||
def cancel_offer(_seed, _nftoken_offer_ids):
|
||||
owner_wallet = Wallet(_seed, sequence = 16237283)
|
||||
client = JsonRpcClient(testnet_url)
|
||||
tokenOfferIDs = [_nftoken_offer_ids]
|
||||
nftSellOffers = "No sell offers"
|
||||
cancel_offer_tx = xrpl.models.transactions.NFTokenCancelOffer(
|
||||
account = owner_wallet.classic_address,
|
||||
nftoken_offers = tokenOfferIDs
|
||||
)
|
||||
def cancel_offer(seed, nftoken_offer_ids):
|
||||
"""cancel_offer"""
|
||||
owner_wallet=Wallet(seed, sequence=16237283)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
tokenOfferIDs=[nftoken_offer_ids]
|
||||
nftSellOffers="No sell offers"
|
||||
cancel_offer_tx=xrpl.models.transactions.NFTokenCancelOffer(
|
||||
account=owner_wallet.classic_address,
|
||||
nftoken_offers=tokenOfferIDs
|
||||
)
|
||||
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
cancel_offer_tx, owner_wallet, client)
|
||||
cancel_offer_tx, owner_wallet, client)
|
||||
reply=""
|
||||
try:
|
||||
response = xrpl.transaction.send_reliable_submission(signed_tx,client)
|
||||
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
|
||||
reply=response.result
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
response = f"Submit failed: {e}"
|
||||
return response.result
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
reply=f"Submit failed: {e}"
|
||||
return reply
|
||||
|
||||
Reference in New Issue
Block a user