Resubmit Python2 updates

This commit is contained in:
ddawson
2023-09-05 13:58:05 -07:00
parent 3de3aa68f0
commit 757bfd4c07
17 changed files with 1406 additions and 352 deletions

View File

@@ -1,6 +1,6 @@
---
html: py-transfer-nfts.html
parent: send-payments-using-python.html
parent: quickstart-python.html
blurb: Use a Python test harness to create and accept NFT buy and sell offers.
labels:
- Quickstart
@@ -8,7 +8,7 @@ labels:
- Non-fungible Tokens, NFTs
---
# Transfer NFTs Using Python
# 4. Transfer NFTs (Python)
This example shows how to:
@@ -21,7 +21,7 @@ This example shows how to:
[![Quickstart form with NFT transfer fields](img/quickstart-py15.png)](img/quickstart-py15.png)
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to try each of the samples in your own browser.
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/py/){.github-code-download} archive to try each of the samples in your own browser.
# Usage
@@ -120,7 +120,7 @@ To cancel a buy or sell offer that you have created:
# Code Walkthrough
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to try each of the samples in your own browser.
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/python/){.github-code-download} archive to try each of the samples in your own browser.
## mod4.py
This module contains the new methods `create_sell_offer`, `create_buy_offer`, `accept_sell_offer`, `accept_buy_offer`, `get_offers`, and `cancel_offer`.
@@ -152,7 +152,7 @@ def create_sell_offer(seed, amount, nftoken_id, expiration, destination):
Get the owner wallet and create a client connection.
```python
owner_wallet = Wallet(seed, sequence=16237283)
owner_wallet = Wallet.from_seed(seed)
client = JsonRpcClient(testnet_url)
```
@@ -169,7 +169,7 @@ Define the sell offer transaction.
```python
sell_offer_tx=xrpl.models.transactions.NFTokenCreateOffer(
account=owner_wallet.classic_address,
account=owner_wallet.address,
nftoken_id=nftoken_id,
amount=amount,
```
@@ -192,19 +192,12 @@ Set the `flags` value to _1_, indicating that this is a sell offer.
)
```
Sign the transaction.
```python
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
sell_offer_tx, owner_wallet, client)
```
Submit the transaction.
```python
reply=""
try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
response=xrpl.transaction.submit_and_wait(sell_offer_tx,client,owner_wallet)
reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}"
@@ -228,7 +221,7 @@ def accept_sell_offer(seed, offer_index):
Get the wallet and a client instance.
```python
buyer_wallet=Wallet(seed, sequence=16237283)
buyer_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url)
```
@@ -253,7 +246,7 @@ Submit the transaction and report the results.
```python
reply=""
try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
response=xrpl.transaction.submit_and_wait(accept_offer_tx,client,buyer_wallet)
reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}"
@@ -272,7 +265,7 @@ def create_buy_offer(seed, amount, nft_id, owner, expiration, destination):
Get the buyer wallet and a client instance.
```python
buyer_wallet=Wallet(seed, sequence=16237283)
buyer_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url)
```
@@ -289,7 +282,7 @@ Define the buy offer transaction.
```python
buy_offer_tx=xrpl.models.transactions.NFTokenCreateOffer(
account=buyer_wallet.classic_address,
account=buyer_wallet.address,
nftoken_id=nft_id,
amount=amount,
owner=owner,
@@ -314,19 +307,12 @@ Set the _flags_ value to _0_, indicating that this is a "buy" offer.
)
```
Sign and fill the transaction.
```python
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
buy_offer_tx, buyer_wallet, client)
```
Submit the transaction and report the results.
```python
reply=""
try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
response=xrpl.transaction.submit_and_wait(buy_offer_tx,client,buyer_wallet)
reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}"
@@ -345,7 +331,7 @@ def accept_buy_offer(seed, offer_index):
Get the buyer wallet and a client instance.
```python
buyer_wallet=Wallet(seed, sequence=16237283)
buyer_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url)
```
@@ -353,24 +339,17 @@ Define the accept offer transaction.
```python
accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer(
account=buyer_wallet.classic_address,
account=buyer_wallet.address,
nftoken_buy_offer=offer_index
)
```
Sign and fill the transaction.
```python
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
accept_offer_tx, buyer_wallet, client)
```
Submit the transaction and report the results
```python
reply=""
try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
response=xrpl.transaction.submit_and_wait(accept_offer_tx,client,buyer_wallet)
reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}"
@@ -469,19 +448,12 @@ Define the cancel offer transaction.
)
```
Sign the transaction.
```python
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
cancel_offer_tx, owner_wallet, client)
```
Submit the transaction and return the result.
```python
reply=""
try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
response=xrpl.transaction.submit_and_wait(cancel_offer_tx,client,owner_wallet)
reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}"
@@ -1044,4 +1016,4 @@ btn_op_cancel_offer.grid(row=16, column=3, sticky="nsew")
# Start the application
window.mainloop()
```
```