mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-20 19:55:54 +00:00
Fixes per GregW
This commit is contained in:
@@ -118,42 +118,44 @@ testnet_url = "https://s.altnet.rippletest.net:51234"
|
||||
Pass the _seed_, _sell___offer___index_, _buy___offer___index_, and _broker___fee_.
|
||||
|
||||
```python
|
||||
def broker_sale(_seed, _sell_offer_index, _buy_offer_index, _broker_fee):
|
||||
def broker_sale(seed, sell_offer_index, buy_offer_index, broker_fee):
|
||||
"""broker_sale"""
|
||||
```
|
||||
|
||||
Get the broker wallet and establish a client connection.
|
||||
|
||||
```python
|
||||
broker_wallet = Wallet(_seed, sequence = 16237283)
|
||||
client = JsonRpcClient(testnet_url)
|
||||
broker_wallet=Wallet(seed, sequence=16237283)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
Define the accept offer transaction, matching a sell offer with the selected buy offer.
|
||||
|
||||
```python
|
||||
accept_offer_tx = xrpl.models.transactions.NFTokenAcceptOffer(
|
||||
account = broker_wallet.classic_address,
|
||||
nftoken_sell_offer = _sell_offer_index,
|
||||
nftoken_buy_offer = _buy_offer_index,
|
||||
nftoken_broker_fee = _broker_fee
|
||||
accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer(
|
||||
account=broker_wallet.classic_address,
|
||||
nftoken_sell_offer=sell_offer_index,
|
||||
nftoken_buy_offer=buy_offer_index,
|
||||
nftoken_broker_fee=broker_fee
|
||||
)
|
||||
```
|
||||
|
||||
Sign and fill the transaction.
|
||||
|
||||
```python
|
||||
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
accept_offer_tx, broker_wallet, client)
|
||||
```
|
||||
|
||||
Submit the transaction and report the results.
|
||||
|
||||
```python
|
||||
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}"
|
||||
```
|
||||
|
||||
## lesson5-broker-nfts.py
|
||||
@@ -169,28 +171,28 @@ import json
|
||||
Import the `broker_sale` method.
|
||||
|
||||
```python
|
||||
from mod1 import get_account, get_account_info, send_xrp
|
||||
from mod2 import (
|
||||
create_trust_line,
|
||||
send_currency,
|
||||
get_balance,
|
||||
configure_account,
|
||||
)
|
||||
from mod3 import (
|
||||
mint_token,
|
||||
get_tokens,
|
||||
burn_token,
|
||||
)
|
||||
from mod4 import (
|
||||
create_sell_offer,
|
||||
create_buy_offer,
|
||||
get_offers,
|
||||
cancel_offer,
|
||||
accept_sell_offer,
|
||||
accept_buy_offer,
|
||||
)
|
||||
from mod5 import broker_sale
|
||||
|
||||
from mod4 import create_sell_offer
|
||||
from mod4 import create_buy_offer
|
||||
from mod4 import get_offers
|
||||
from mod4 import cancel_offer
|
||||
from mod4 import accept_sell_offer
|
||||
from mod4 import accept_buy_offer
|
||||
|
||||
from mod3 import mint_token
|
||||
from mod3 import get_tokens
|
||||
from mod3 import burn_token
|
||||
|
||||
from mod2 import create_trust_line
|
||||
from mod2 import send_currency
|
||||
from mod2 import get_balance
|
||||
from mod2 import configure_account
|
||||
|
||||
from mod1 import get_account
|
||||
from mod1 import get_account_info
|
||||
from mod1 import send_xrp
|
||||
|
||||
#############################################
|
||||
## Handlers #################################
|
||||
#############################################
|
||||
@@ -207,12 +209,16 @@ def get_broker_account():
|
||||
ent_broker_seed.delete(0, tk.END)
|
||||
ent_broker_account.insert(0, new_wallet.classic_address)
|
||||
ent_broker_seed.insert(0, new_wallet.seed)
|
||||
|
||||
|
||||
def get_broker_account_info():
|
||||
accountInfo = get_account_info(ent_broker_account.get())
|
||||
ent_broker_balance.delete(0, tk.END)
|
||||
ent_broker_balance.insert(0,accountInfo['Balance'])
|
||||
text_broker_results.delete("1.0", tk.END)
|
||||
text_broker_results.insert("1.0",json.dumps(accountInfo, indent=4))
|
||||
|
||||
|
||||
def broker_broker_sale():
|
||||
results = broker_sale(
|
||||
ent_broker_seed.get(),
|
||||
@@ -222,10 +228,14 @@ def broker_broker_sale():
|
||||
)
|
||||
text_broker_results.delete("1.0", tk.END)
|
||||
text_broker_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def broker_get_offers():
|
||||
results = get_offers(ent_broker_nft_id.get())
|
||||
text_broker_results.delete("1.0", tk.END)
|
||||
text_broker_results.insert("1.0", results)
|
||||
|
||||
|
||||
def broker_cancel_offer():
|
||||
results = cancel_offer(
|
||||
ent_broker_seed.get(),
|
||||
@@ -247,6 +257,8 @@ def standby_create_sell_offer():
|
||||
)
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def standby_accept_sell_offer():
|
||||
results = accept_sell_offer (
|
||||
ent_standby_seed.get(),
|
||||
@@ -254,6 +266,8 @@ def standby_accept_sell_offer():
|
||||
)
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def standby_create_buy_offer():
|
||||
results = create_buy_offer(
|
||||
ent_standby_seed.get(),
|
||||
@@ -265,6 +279,8 @@ def standby_create_buy_offer():
|
||||
)
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def standby_accept_buy_offer():
|
||||
results = accept_buy_offer (
|
||||
ent_standby_seed.get(),
|
||||
@@ -272,10 +288,14 @@ def standby_accept_buy_offer():
|
||||
)
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def standby_get_offers():
|
||||
results = get_offers(ent_standby_nft_id.get())
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0", results)
|
||||
|
||||
|
||||
def standby_cancel_offer():
|
||||
results = cancel_offer(
|
||||
ent_standby_seed.get(),
|
||||
@@ -283,6 +303,8 @@ def standby_cancel_offer():
|
||||
)
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def op_create_sell_offer():
|
||||
results = create_sell_offer(
|
||||
ent_operational_seed.get(),
|
||||
@@ -293,6 +315,8 @@ def op_create_sell_offer():
|
||||
)
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def op_accept_sell_offer():
|
||||
results = accept_sell_offer (
|
||||
ent_operational_seed.get(),
|
||||
@@ -300,6 +324,8 @@ def op_accept_sell_offer():
|
||||
)
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def op_create_buy_offer():
|
||||
results = create_buy_offer(
|
||||
ent_operational_seed.get(),
|
||||
@@ -311,6 +337,8 @@ def op_create_buy_offer():
|
||||
)
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def op_accept_buy_offer():
|
||||
results = accept_buy_offer (
|
||||
ent_operational_seed.get(),
|
||||
@@ -318,10 +346,14 @@ def op_accept_buy_offer():
|
||||
)
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def op_get_offers():
|
||||
results = get_offers(ent_operational_nft_id.get())
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0", results)
|
||||
|
||||
|
||||
def op_cancel_offer():
|
||||
results = cancel_offer(
|
||||
ent_operational_seed.get(),
|
||||
@@ -344,10 +376,14 @@ def standby_mint_token():
|
||||
)
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def standby_get_tokens():
|
||||
results = get_tokens(ent_standby_account.get())
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def standby_burn_token():
|
||||
results = burn_token(
|
||||
ent_standby_seed.get(),
|
||||
@@ -355,6 +391,8 @@ def standby_burn_token():
|
||||
)
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def operational_mint_token():
|
||||
results = mint_token(
|
||||
ent_operational_seed.get(),
|
||||
@@ -365,10 +403,14 @@ def operational_mint_token():
|
||||
)
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def operational_get_tokens():
|
||||
results = get_tokens(ent_operational_account.get())
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def operational_burn_token():
|
||||
results = burn_token(
|
||||
ent_operational_seed.get(),
|
||||
@@ -377,6 +419,7 @@ def operational_burn_token():
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
# Module 2 Handlers
|
||||
|
||||
def standby_create_trust_line():
|
||||
@@ -386,6 +429,8 @@ def standby_create_trust_line():
|
||||
ent_standby_amount.get())
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def standby_send_currency():
|
||||
results = send_currency(ent_standby_seed.get(),
|
||||
ent_standby_destination.get(),
|
||||
@@ -393,12 +438,16 @@ def standby_send_currency():
|
||||
ent_standby_amount.get())
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def standby_configure_account():
|
||||
results = configure_account(
|
||||
ent_standby_seed.get(),
|
||||
standbyRippling)
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def operational_create_trust_line():
|
||||
results = create_trust_line(ent_operational_seed.get(),
|
||||
ent_operational_destination.get(),
|
||||
@@ -406,6 +455,8 @@ def operational_create_trust_line():
|
||||
ent_operational_amount.get())
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def operational_send_currency():
|
||||
results = send_currency(ent_operational_seed.get(),
|
||||
ent_operational_destination.get(),
|
||||
@@ -413,12 +464,16 @@ def operational_send_currency():
|
||||
ent_operational_amount.get())
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def operational_configure_account():
|
||||
results = configure_account(
|
||||
ent_operational_seed.get(),
|
||||
operationalRippling)
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def get_balances():
|
||||
results = get_balance(ent_operational_account.get(), ent_standby_account.get())
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
@@ -427,6 +482,7 @@ def get_balances():
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
# Module 1 Handlers
|
||||
def get_standby_account():
|
||||
new_wallet = get_account(ent_standby_seed.get())
|
||||
@@ -434,12 +490,16 @@ def get_standby_account():
|
||||
ent_standby_seed.delete(0, tk.END)
|
||||
ent_standby_account.insert(0, new_wallet.classic_address)
|
||||
ent_standby_seed.insert(0, new_wallet.seed)
|
||||
|
||||
|
||||
def get_standby_account_info():
|
||||
accountInfo = get_account_info(ent_standby_account.get())
|
||||
ent_standby_balance.delete(0, tk.END)
|
||||
ent_standby_balance.insert(0,accountInfo['Balance'])
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0",json.dumps(accountInfo, indent=4))
|
||||
|
||||
|
||||
def standby_send_xrp():
|
||||
response = send_xrp(ent_standby_seed.get(),ent_standby_amount.get(),
|
||||
ent_standby_destination.get())
|
||||
@@ -447,26 +507,35 @@ def standby_send_xrp():
|
||||
text_standby_results.insert("1.0",json.dumps(response.result, indent=4))
|
||||
get_standby_account_info()
|
||||
get_operational_account_info()
|
||||
|
||||
|
||||
def get_operational_account():
|
||||
new_wallet = get_account(ent_operational_seed.get())
|
||||
ent_operational_account.delete(0, tk.END)
|
||||
ent_operational_account.insert(0, new_wallet.classic_address)
|
||||
ent_operational_seed.delete(0, tk.END)
|
||||
ent_operational_seed.insert(0, new_wallet.seed)
|
||||
|
||||
|
||||
def get_operational_account_info():
|
||||
accountInfo = get_account_info(ent_operational_account.get())
|
||||
ent_operational_balance.delete(0, tk.END)
|
||||
ent_operational_balance.insert(0,accountInfo['Balance'])
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0",json.dumps(accountInfo, indent=4))
|
||||
|
||||
|
||||
def operational_send_xrp():
|
||||
response = send_xrp(ent_operational_seed.get(),ent_operational_amount.get(), ent_operational_destination.get())
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0",json.dumps(response.result,indent=4))
|
||||
get_standby_account_info()
|
||||
get_operational_account_info()
|
||||
```
|
||||
|
||||
# Create a new window with the title "Quickstart - Broker Sale"
|
||||
Create a new window with the title _Quickstart - Broker Sale_.
|
||||
|
||||
```python
|
||||
window = tk.Tk()
|
||||
window.title("Quickstart - Broker Sale")
|
||||
|
||||
@@ -474,12 +543,11 @@ myscrollbar=tk.Scrollbar(window,orient="vertical")
|
||||
myscrollbar.pack(side="right",fill="y")
|
||||
|
||||
|
||||
|
||||
standbyRippling = tk.BooleanVar()
|
||||
operationalRippling = tk.BooleanVar()
|
||||
```
|
||||
|
||||
Add a new Frame to hold the Broker fields and buttons.
|
||||
Add a new frame to hold the broker fields and buttons.
|
||||
|
||||
```python
|
||||
# Broker frame
|
||||
@@ -538,7 +606,7 @@ lbl_broker_results.grid(row=9, column=0)
|
||||
text_broker_results.grid(row=9, column=1)
|
||||
```
|
||||
|
||||
Define and place the Broker buttons.
|
||||
Define and place the broker buttons.
|
||||
|
||||
```python
|
||||
btn_broker_get_account = tk.Button(master=frm_broker, text="Get Broker Account",
|
||||
@@ -566,12 +634,12 @@ lbl_standy_seed = tk.Label(master=frm_form, text="Standby Seed")
|
||||
ent_standby_seed = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standby_account = tk.Label(master=frm_form, text="Standby Account")
|
||||
ent_standby_account = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standby_balance = tk.Label(master=frm_form, text="XRP Balance")
|
||||
ent_standby_balance = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standy_amount = tk.Label(master=frm_form, text="Amount")
|
||||
ent_standby_amount = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standby_destination = tk.Label(master=frm_form, text="Destination")
|
||||
ent_standby_destination = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standby_balance = tk.Label(master=frm_form, text="XRP Balance")
|
||||
ent_standby_balance = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standby_currency = tk.Label(master=frm_form, text="Currency")
|
||||
ent_standby_currency = tk.Entry(master=frm_form, width=50)
|
||||
cb_standby_allow_rippling = tk.Checkbutton(master=frm_form, text="Allow Rippling", variable=standbyRippling, onvalue=True, offvalue=False)
|
||||
@@ -591,8 +659,6 @@ lbl_standby_owner = tk.Label(master=frm_form, text="Owner")
|
||||
ent_standby_owner = tk.Entry(master=frm_form, width="50")
|
||||
lbl_standby_expiration = tk.Label(master=frm_form, text="Expiration")
|
||||
ent_standby_expiration = tk.Entry(master=frm_form, width="50")
|
||||
lbl_standby_transfer_fee = tk.Label(master=frm_form, text="Transfer Fee")
|
||||
ent_standby_transfer_fee = tk.Entry(master=frm_form, width="50")
|
||||
lbl_standby_results = tk.Label(master=frm_form,text='Results')
|
||||
text_standby_results = tk.Text(master=frm_form, height = 10, width = 65)
|
||||
|
||||
@@ -640,12 +706,12 @@ lbl_operational_seed = tk.Label(master=frm_form, text="Operational Seed")
|
||||
ent_operational_seed = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_account = tk.Label(master=frm_form, text="Operational Account")
|
||||
ent_operational_account = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_balance = tk.Label(master=frm_form, text="XRP Balance")
|
||||
ent_operational_balance = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_amount = tk.Label(master=frm_form, text="Amount")
|
||||
ent_operational_amount = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_destination = tk.Label(master=frm_form, text="Destination")
|
||||
ent_operational_destination = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_balance = tk.Label(master=frm_form, text="XRP Balance")
|
||||
ent_operational_balance = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_currency = tk.Label(master=frm_form, text="Currency")
|
||||
ent_operational_currency = tk.Entry(master=frm_form, width=50)
|
||||
cb_operational_allow_rippling = tk.Checkbutton(master=frm_form, text="Allow Rippling", variable=operationalRippling, onvalue=True, offvalue=False)
|
||||
@@ -665,8 +731,6 @@ lbl_operational_owner = tk.Label(master=frm_form, text="Owner")
|
||||
ent_operational_owner = tk.Entry(master=frm_form, width="50")
|
||||
lbl_operational_expiration = tk.Label(master=frm_form, text="Expiration")
|
||||
ent_operational_expiration = tk.Entry(master=frm_form, width="50")
|
||||
lbl_operational_transfer_fee = tk.Label(master=frm_form, text="Transfer Fee")
|
||||
ent_operational_transfer_fee = tk.Entry(master=frm_form, width="50")
|
||||
lbl_operational_results = tk.Label(master=frm_form,text="Results")
|
||||
text_operational_results = tk.Text(master=frm_form, height = 10, width = 65)
|
||||
|
||||
|
||||
@@ -69,11 +69,14 @@ You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-port
|
||||
|
||||
The mod1.py module contains the business logic for interacting with the XRP Ledger.
|
||||
|
||||
Import the XRPL and JSON libraries.
|
||||
Import the XRPL and JSON libraries, and the module 1 methods.
|
||||
|
||||
```python
|
||||
import xrpl
|
||||
import json
|
||||
import xrpl.clients
|
||||
import xrpl.wallet
|
||||
|
||||
```
|
||||
|
||||
### get_account
|
||||
@@ -83,9 +86,8 @@ This method lets you get an existing account by providing a seed value. If you p
|
||||
Import required methods.
|
||||
|
||||
```python
|
||||
def get_account(_seed):
|
||||
from xrpl.clients import JsonRpcClient
|
||||
from xrpl.wallet import Wallet
|
||||
def get_account(seed):
|
||||
"""get_account"""
|
||||
```
|
||||
|
||||
This example uses the _Testnet_ ledger. You can update the URI to choose a different XRP Ledger instance.
|
||||
@@ -97,16 +99,16 @@ This example uses the _Testnet_ ledger. You can update the URI to choose a diffe
|
||||
Request a new client from the XRP Ledger.
|
||||
|
||||
```python
|
||||
client = JsonRpcClient(JSON_RPC_URL)
|
||||
client = xrpl.clients.JsonRpcClient(JSON_RPC_URL)
|
||||
```
|
||||
|
||||
If you do not enter a seed, generate and return a new wallet. If you provide a seed value, return the wallet for that seed.
|
||||
|
||||
```python
|
||||
if (_seed == ''):
|
||||
if (seed == ''):
|
||||
new_wallet = xrpl.wallet.generate_faucet_wallet(client)
|
||||
else:
|
||||
new_wallet = Wallet(_seed, sequence = 79396029)
|
||||
new_wallet = xrpl.wallet.Wallet(seed, sequence = 79396029)
|
||||
return(new_wallet)
|
||||
```
|
||||
|
||||
@@ -115,29 +117,22 @@ If you do not enter a seed, generate and return a new wallet. If you provide a s
|
||||
Pass the account ID to the `get_account_info` method.
|
||||
|
||||
```python
|
||||
def get_account_info(_accountId):
|
||||
```
|
||||
|
||||
Import required methods and the JSON library.
|
||||
|
||||
```python
|
||||
from xrpl.clients import JsonRpcClient
|
||||
from xrpl.models.requests.account_info import AccountInfo
|
||||
import json
|
||||
def get_account_info(accountId):
|
||||
"""get_account_info"""
|
||||
```
|
||||
|
||||
Get a client instance from Testnet.
|
||||
|
||||
```python
|
||||
JSON_RPC_URL = 'wss://s.altnet.rippletest.net:51234'
|
||||
client = JsonRpcClient(JSON_RPC_URL)
|
||||
client = xrpl.clients.JsonRpcClient(JSON_RPC_URL)
|
||||
```
|
||||
|
||||
Create the account info request, passing the account ID and the ledger index (in this case, the latest validated ledger).
|
||||
|
||||
```python
|
||||
acct_info = AccountInfo(
|
||||
account=_accountId,
|
||||
acct_info = xrpl.models.requests.account_info.AccountInfo(
|
||||
account=accountId,
|
||||
ledger_index="validated"
|
||||
)
|
||||
```
|
||||
@@ -145,7 +140,7 @@ Create the account info request, passing the account ID and the ledger index (in
|
||||
Send the request to the XRP Ledger instance.
|
||||
|
||||
```python
|
||||
response = client.request(acct_info)
|
||||
response=client.request(acct_info)
|
||||
```
|
||||
|
||||
Return the account data.
|
||||
@@ -159,26 +154,24 @@ Return the account data.
|
||||
Transfer XRP to another account by passing the client seed, amount to transfer, and the destination account.
|
||||
|
||||
```python
|
||||
def send_xrp(_seed, _amount, _destination):
|
||||
def send_xrp(seed, amount, destination):
|
||||
```
|
||||
|
||||
Get the sending wallet.
|
||||
|
||||
```python
|
||||
from xrpl.clients import JsonRpcClient
|
||||
from xrpl.wallet import Wallet
|
||||
sending_wallet = Wallet(_seed, sequence = 16237283)
|
||||
sending_wallet = xrpl.wallet.Wallet(seed, sequence = 16237283)
|
||||
testnet_url = "https://s.altnet.rippletest.net:51234"
|
||||
client = JsonRpcClient(testnet_url)
|
||||
client = xrpl.clients.JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
Create a transaction request, passing the sending account, amount, and destination account.
|
||||
|
||||
```python
|
||||
payment = xrpl.models.transactions.Payment(
|
||||
payment=xrpl.models.transactions.Payment(
|
||||
account=sending_wallet.classic_address,
|
||||
amount=xrpl.utils.xrp_to_drops(int(_amount)),
|
||||
destination=_destination,
|
||||
amount=xrpl.utils.xrp_to_drops(int(amount)),
|
||||
destination=destination,
|
||||
)
|
||||
```
|
||||
|
||||
@@ -215,9 +208,7 @@ import json
|
||||
Import the methods from mod1.py.
|
||||
|
||||
```python
|
||||
from mod1 import get_account
|
||||
from mod1 import get_accountInfo
|
||||
from mod1 import send_xrp
|
||||
from .mod1 import get_account, get_account_info, send_xrp
|
||||
```
|
||||
|
||||
### getStandbyAccount
|
||||
@@ -307,12 +298,16 @@ def get_operational_account():
|
||||
ent_operational_account.insert(0, new_wallet.classic_address)
|
||||
ent_operational_seed.delete(0, tk.END)
|
||||
ent_operational_seed.insert(0, new_wallet.seed)
|
||||
|
||||
|
||||
def get_operational_account_info():
|
||||
account_info = get_account_info(ent_operational_account.get())
|
||||
ent_operational_balance.delete(0, tk.END)
|
||||
ent_operational_balance.insert(0,accountInfo['Balance'])
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0",json.dumps(accountInfo, indent=4))
|
||||
|
||||
|
||||
def operational_send_xrp():
|
||||
response = send_xrp(ent_operational_seed.get(),ent_operational_amount.get(),
|
||||
ent_operational_destination.get())
|
||||
@@ -343,12 +338,12 @@ lbl_standy_seed = tk.Label(master=frm_form, text="Standby Seed")
|
||||
ent_standby_seed = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standby_account = tk.Label(master=frm_form, text="Standby Account")
|
||||
ent_standby_account = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standby_balance = tk.Label(master=frm_form, text="XRP Balance")
|
||||
ent_standby_balance = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standy_amount = tk.Label(master=frm_form, text="Amount")
|
||||
ent_standby_amount = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standby_destination = tk.Label(master=frm_form, text="Destination")
|
||||
ent_standby_destination = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standby_balance = tk.Label(master=frm_form, text="XRP Balance")
|
||||
ent_standby_balance = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standby_results = tk.Label(master=frm_form,text='Results')
|
||||
text_standby_results = tk.Text(master=frm_form, height = 20, width = 65)
|
||||
```
|
||||
@@ -377,12 +372,12 @@ lbl_operational_seed = tk.Label(master=frm_form, text="Operational Seed")
|
||||
ent_operational_seed = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_account = tk.Label(master=frm_form, text="Operational Account")
|
||||
ent_operational_account = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_balance = tk.Label(master=frm_form, text="XRP Balance")
|
||||
ent_operational_balance = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_amount = tk.Label(master=frm_form, text="Amount")
|
||||
ent_operational_amount = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_destination = tk.Label(master=frm_form, text="Destination")
|
||||
ent_operational_destination = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_balance = tk.Label(master=frm_form, text="XRP Balance")
|
||||
ent_operational_balance = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_results = tk.Label(master=frm_form,text='Results')
|
||||
text_operational_results = tk.Text(master=frm_form, height = 20, width = 65)
|
||||
```
|
||||
|
||||
@@ -96,6 +96,7 @@ import xrpl
|
||||
import json
|
||||
from xrpl.clients import JsonRpcClient
|
||||
from xrpl.wallet import Wallet
|
||||
from xrpl.models.requests.account_info import AccountInfo
|
||||
|
||||
testnet_url = "https://s.altnet.rippletest.net:51234"
|
||||
```
|
||||
@@ -105,25 +106,26 @@ testnet_url = "https://s.altnet.rippletest.net:51234"
|
||||
Pass the wallet seed, the issuer account, the currency code, and the maximum amount of currency to send.
|
||||
|
||||
```python
|
||||
def create_trust_line(_seed, _issuer, _currency, _amount):
|
||||
def create_trust_line(seed, issuer, currency, amount):
|
||||
"""create_trust_line"""
|
||||
```
|
||||
|
||||
Get the wallet and a new client instance.
|
||||
|
||||
```python
|
||||
receiving_wallet = Wallet(_seed, sequence = 16237283)
|
||||
receiving_wallet = Wallet(seed, sequence = 16237283)
|
||||
client = JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
Define the `TrustSet` transaction.
|
||||
|
||||
```python
|
||||
trustline_tx = xrpl.models.transactions.TrustSet(
|
||||
account = receiving_wallet.classic_address,
|
||||
limit_amount = xrpl.models.amounts.IssuedCurrencyAmount(
|
||||
currency = _currency,
|
||||
issuer = _issuer,
|
||||
value = int(_amount)
|
||||
trustline_tx=xrpl.models.transactions.TrustSet(
|
||||
account=receiving_wallet.classic_address,
|
||||
limit_amount=xrpl.models.amounts.IssuedCurrencyAmount(
|
||||
currency=currency,
|
||||
issuer=issuer,
|
||||
value=int(amount)
|
||||
)
|
||||
)
|
||||
```
|
||||
@@ -138,66 +140,71 @@ Sign the transaction.
|
||||
Submit the transaction to the XRP Ledger.
|
||||
|
||||
```python
|
||||
reply = ""
|
||||
try:
|
||||
response = xrpl.transaction.send_reliable_submission(signed_tx,client)
|
||||
reply = response.result
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
response = f"Submit failed: {e}"
|
||||
reply = f"Submit failed: {e}"
|
||||
```
|
||||
|
||||
Return the results.
|
||||
|
||||
```python
|
||||
return response.result
|
||||
return reply
|
||||
```
|
||||
## send_currency
|
||||
|
||||
Send currency to another account based on the sender wallet, destination account, the currency type, and the amount of the currency.
|
||||
|
||||
```python
|
||||
def send_currency(_seed, _destination, _currency, _amount):
|
||||
def send_currency(seed, destination, currency, amount):
|
||||
"""send_currency"""
|
||||
```
|
||||
|
||||
Get the sending wallet and a client instance on Testnet.
|
||||
|
||||
```python
|
||||
sending_wallet = Wallet(_seed, sequence = 16237283)
|
||||
client = JsonRpcClient(testnet_url)
|
||||
sending_wallet=Wallet(seed, sequence=16237283)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
Define the payment transaction. The amount requires further description to identify the type of currency and issuer.
|
||||
|
||||
```python
|
||||
send_currency_tx = xrpl.models.transactions.Payment(
|
||||
account = sending_wallet.classic_address,
|
||||
amount = xrpl.models.amounts.IssuedCurrencyAmount(
|
||||
currency = _currency,
|
||||
value = int(_amount),
|
||||
issuer = sending_wallet.classic_address
|
||||
send_currency_tx=xrpl.models.transactions.Payment(
|
||||
account=sending_wallet.classic_address,
|
||||
amount=xrpl.models.amounts.IssuedCurrencyAmount(
|
||||
currency=currency,
|
||||
value=int(amount),
|
||||
issuer=sending_wallet.classic_address
|
||||
),
|
||||
destination=_destination
|
||||
destination=destination
|
||||
)
|
||||
```
|
||||
|
||||
Sign and fill the transaction.
|
||||
|
||||
```python
|
||||
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
send_currency_tx, sending_wallet, client)
|
||||
```
|
||||
|
||||
Submit the transaction and get the response.
|
||||
|
||||
```python
|
||||
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}"
|
||||
reply = f"Submit failed: {e}"
|
||||
```
|
||||
|
||||
Return the JSON response, or an error message if the transaction fails.
|
||||
|
||||
```python
|
||||
return response.result
|
||||
return reply
|
||||
```
|
||||
|
||||
### get_balance
|
||||
@@ -205,30 +212,24 @@ Return the JSON response, or an error message if the transaction fails.
|
||||
Update the **XRP Balance** fields and list the balance information for issued currencies in the **Results** text areas.
|
||||
|
||||
```python
|
||||
def get_balance(_sb_account_id, _op_account_id):
|
||||
```
|
||||
|
||||
Import the `AccountInfo` request method.
|
||||
|
||||
```python
|
||||
from xrpl.models.requests.account_info import AccountInfo
|
||||
def get_balance(sb_account_id, op_account_id):
|
||||
"""get_balance"""
|
||||
```
|
||||
|
||||
Connect to the XRP Ledger and instantiate a client.
|
||||
|
||||
```python
|
||||
JSON_RPC_URL = 'wss://s.altnet.rippletest.net:51234'
|
||||
client = JsonRpcClient(JSON_RPC_URL)
|
||||
JSON_RPC_URL='wss://s.altnet.rippletest.net:51234'
|
||||
client=JsonRpcClient(JSON_RPC_URL)
|
||||
```
|
||||
|
||||
Create the `GatewayBalances` request.
|
||||
|
||||
```python
|
||||
balance = xrpl.models.requests.GatewayBalances(
|
||||
account=_sb_account_id ,
|
||||
strict=True,
|
||||
balance=xrpl.models.requests.GatewayBalances(
|
||||
account=sb_account_id,
|
||||
ledger_index="validated",
|
||||
hotwallet=[_op_account_id]
|
||||
hotwallet=[op_account_id]
|
||||
)
|
||||
```
|
||||
|
||||
@@ -245,51 +246,54 @@ This example shows how to set and clear configuration flags using the `AccountSe
|
||||
|
||||
Send the account seed and a Boolean value for whether to enable or disable rippling.
|
||||
```python
|
||||
def configure_account(_seed, _default_setting):
|
||||
def configure_account(seed, default_setting):
|
||||
"""configure_account"
|
||||
```
|
||||
|
||||
Get the account wallet and instantiate a client.
|
||||
|
||||
```python
|
||||
wallet = Wallet(_seed, sequence = 16237283)
|
||||
client = JsonRpcClient(testnet_url)
|
||||
wallet=Wallet(seed, sequence = 16237283)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
If `_default_setting` is true, create a `set_flag` transaction to enable rippling. If false, create a `clear_flag` transaction to disable rippling.
|
||||
If `default_setting` is true, create a `set_flag` transaction to enable rippling. If false, create a `clear_flag` transaction to disable rippling.
|
||||
|
||||
```python
|
||||
if (_default_setting.get()):
|
||||
setting_tx = xrpl.models.transactions.AccountSet(
|
||||
account = wallet.classic_address,
|
||||
if (default_setting):
|
||||
setting_tx=xrpl.models.transactions.AccountSet(
|
||||
account=wallet.classic_address,
|
||||
set_flag=xrpl.models.transactions.AccountSetFlag.ASF_DEFAULT_RIPPLE
|
||||
)
|
||||
else:
|
||||
setting_tx = xrpl.models.transactions.AccountSet(
|
||||
account = wallet.classic_address,
|
||||
clear_flag = xrpl.models.transactions.AccountSetFlag.ASF_DEFAULT_RIPPLE
|
||||
setting_tx=xrpl.models.transactions.AccountSet(
|
||||
account=wallet.classic_address,
|
||||
clear_flag=xrpl.models.transactions.AccountSetFlag.ASF_DEFAULT_RIPPLE
|
||||
)
|
||||
```
|
||||
|
||||
Sign and fill the transaction.
|
||||
|
||||
```python
|
||||
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
setting_tx, wallet, client)
|
||||
```
|
||||
|
||||
Submit the transaction and get results.
|
||||
|
||||
```python
|
||||
reply = ""
|
||||
try:
|
||||
response = xrpl.transaction.send_reliable_submission(signed_tx,client)
|
||||
reply = response.result
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
response.result = f"Submit failed: {e}"
|
||||
reply = f"Submit failed: {e}"
|
||||
```
|
||||
|
||||
Return the results.
|
||||
|
||||
```python
|
||||
return response.result
|
||||
return reply
|
||||
```
|
||||
|
||||
## lesson2-send-currency.py
|
||||
@@ -305,18 +309,13 @@ import json
|
||||
Import methods from `mod2.py`.
|
||||
|
||||
```python
|
||||
from mod2 import create_trust_line
|
||||
from mod2 import send_currency
|
||||
from mod2 import get_balance
|
||||
from mod2 import configure_account
|
||||
|
||||
from mod1 import get_account
|
||||
from mod1 import get_account_info
|
||||
from mod1 import send_xrp
|
||||
|
||||
#############################################
|
||||
## Handlers #################################
|
||||
#############################################
|
||||
from mod1 import get_account, get_account_info, send_xrp
|
||||
from mod2 import (
|
||||
create_trust_line,
|
||||
send_currency,
|
||||
get_balance,
|
||||
configure_account,
|
||||
)
|
||||
```
|
||||
|
||||
Module 2 Handlers.
|
||||
@@ -329,6 +328,8 @@ def standby_create_trust_line():
|
||||
ent_standby_amount.get())
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def standby_send_currency():
|
||||
results = send_currency(ent_standby_seed.get(),
|
||||
ent_standby_destination.get(),
|
||||
@@ -336,12 +337,16 @@ def standby_send_currency():
|
||||
ent_standby_amount.get())
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def standby_configure_account():
|
||||
results = configure_account(
|
||||
ent_standby_seed.get(),
|
||||
standbyRippling)
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def operational_create_trust_line():
|
||||
results = create_trust_line(ent_operational_seed.get(),
|
||||
ent_operational_destination.get(),
|
||||
@@ -349,6 +354,8 @@ def operational_create_trust_line():
|
||||
ent_operational_amount.get())
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def operational_send_currency():
|
||||
results = send_currency(ent_operational_seed.get(),
|
||||
ent_operational_destination.get(),
|
||||
@@ -356,12 +363,16 @@ def operational_send_currency():
|
||||
ent_operational_amount.get())
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def operational_configure_account():
|
||||
results = configure_account(
|
||||
ent_operational_seed.get(),
|
||||
operationalRippling)
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def get_balances():
|
||||
results = get_balance(ent_operational_account.get(), ent_standby_account.get())
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
@@ -370,6 +381,7 @@ def get_balances():
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
# Module 1 Handlers
|
||||
def get_standby_account():
|
||||
new_wallet = get_account(ent_standby_seed.get())
|
||||
@@ -377,12 +389,16 @@ def get_standby_account():
|
||||
ent_standby_seed.delete(0, tk.END)
|
||||
ent_standby_account.insert(0, new_wallet.classic_address)
|
||||
ent_standby_seed.insert(0, new_wallet.seed)
|
||||
|
||||
|
||||
def get_standby_account_info():
|
||||
accountInfo = get_account_info(ent_standby_account.get())
|
||||
ent_standby_balance.delete(0, tk.END)
|
||||
ent_standby_balance.insert(0,accountInfo['Balance'])
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0",json.dumps(accountInfo, indent=4))
|
||||
|
||||
|
||||
def standby_send_xrp():
|
||||
response = send_xrp(ent_standby_seed.get(),ent_standby_amount.get(),
|
||||
ent_standby_destination.get())
|
||||
@@ -390,18 +406,24 @@ def standby_send_xrp():
|
||||
text_standby_results.insert("1.0",json.dumps(response.result, indent=4))
|
||||
get_standby_account_info()
|
||||
get_operational_account_info()
|
||||
|
||||
|
||||
def get_operational_account():
|
||||
new_wallet = get_account(ent_operational_seed.get())
|
||||
ent_operational_account.delete(0, tk.END)
|
||||
ent_operational_account.insert(0, new_wallet.classic_address)
|
||||
ent_operational_seed.delete(0, tk.END)
|
||||
ent_operational_seed.insert(0, new_wallet.seed)
|
||||
|
||||
|
||||
def get_operational_account_info():
|
||||
accountInfo = get_account_info(ent_operational_account.get())
|
||||
ent_operational_balance.delete(0, tk.END)
|
||||
ent_operational_balance.insert(0,accountInfo['Balance'])
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0",json.dumps(accountInfo, indent=4))
|
||||
|
||||
|
||||
def operational_send_xrp():
|
||||
response = send_xrp(ent_operational_seed.get(),ent_operational_amount.get(), ent_operational_destination.get())
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
@@ -410,6 +432,7 @@ def operational_send_xrp():
|
||||
get_operational_account_info()
|
||||
|
||||
# Create a new window with the title "Quickstart Module 2"
|
||||
|
||||
window = tk.Tk()
|
||||
window.title("Quickstart Module 2")
|
||||
|
||||
@@ -427,12 +450,12 @@ lbl_standy_seed = tk.Label(master=frm_form, text="Standby Seed")
|
||||
ent_standby_seed = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standby_account = tk.Label(master=frm_form, text="Standby Account")
|
||||
ent_standby_account = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standby_balance = tk.Label(master=frm_form, text="XRP Balance")
|
||||
ent_standby_balance = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standy_amount = tk.Label(master=frm_form, text="Amount")
|
||||
ent_standby_amount = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standby_destination = tk.Label(master=frm_form, text="Destination")
|
||||
ent_standby_destination = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standby_balance = tk.Label(master=frm_form, text="XRP Balance")
|
||||
ent_standby_balance = tk.Entry(master=frm_form, width=50)
|
||||
```
|
||||
|
||||
Add **Currency** field.
|
||||
@@ -481,12 +504,12 @@ lbl_operational_seed = tk.Label(master=frm_form, text="Operational Seed")
|
||||
ent_operational_seed = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_account = tk.Label(master=frm_form, text="Operational Account")
|
||||
ent_operational_account = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_balance = tk.Label(master=frm_form, text="XRP Balance")
|
||||
ent_operational_balance = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_amount = tk.Label(master=frm_form, text="Amount")
|
||||
ent_operational_amount = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_destination = tk.Label(master=frm_form, text="Destination")
|
||||
ent_operational_destination = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_balance = tk.Label(master=frm_form, text="XRP Balance")
|
||||
ent_operational_balance = tk.Entry(master=frm_form, width=50)
|
||||
```
|
||||
|
||||
Add field for **Currency** and checkbox to **Allow Rippling**.
|
||||
@@ -522,11 +545,7 @@ text_operational_results.grid(row=8, column=5, sticky="nw")
|
||||
cb_operational_allow_rippling.select()
|
||||
```
|
||||
|
||||
#############################################
|
||||
## Buttons ##################################
|
||||
#############################################
|
||||
|
||||
# Create the Standby Account Buttons
|
||||
Create the Standby Account Buttons.
|
||||
|
||||
```python
|
||||
btn_get_standby_account = tk.Button(master=frm_form, text="Get Standby Account",
|
||||
@@ -560,7 +579,7 @@ btn_standby_configure_account = tk.Button(master=frm_form,
|
||||
btn_standby_configure_account.grid(row=7,column=0, sticky = "nsew")
|
||||
```
|
||||
|
||||
# Create the Operational Account Buttons
|
||||
Create the Operational Account buttons.
|
||||
|
||||
```python
|
||||
btn_get_operational_account = tk.Button(master=frm_form,
|
||||
|
||||
@@ -84,6 +84,8 @@ import xrpl
|
||||
import json
|
||||
from xrpl.clients import JsonRpcClient
|
||||
from xrpl.wallet import Wallet
|
||||
from xrpl.models.requests import AccountNFTs
|
||||
|
||||
|
||||
testnet_url = "https://s.altnet.rippletest.net:51234"
|
||||
```
|
||||
@@ -93,25 +95,25 @@ testnet_url = "https://s.altnet.rippletest.net:51234"
|
||||
Pass the arguments account seed, NFT URI, transaction flags, the transfer fee, and optional taxon.
|
||||
|
||||
```python
|
||||
def mint_token(_seed, _uri, _flags, _transfer_fee, _taxon):
|
||||
def mint_token(seed, uri, flags, transfer_fee, taxon):
|
||||
```
|
||||
|
||||
Get the account wallet and a client instance.
|
||||
|
||||
```python
|
||||
mint_wallet = Wallet(_seed, sequence = 16237283)
|
||||
client = JsonRpcClient(testnet_url)
|
||||
mint_wallet=Wallet(seed, sequence=16237283)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
Define the mint transaction. Note that the NFT URI must be converted to a hex string.
|
||||
|
||||
```python
|
||||
mint_tx = xrpl.models.transactions.NFTokenMint(
|
||||
account = mint_wallet.classic_address,
|
||||
uri = xrpl.utils.str_to_hex(_uri),
|
||||
flags = int(_flags),
|
||||
transfer_fee = int(_transfer_fee),
|
||||
nftoken_taxon = int(_taxon)
|
||||
mint_tx=xrpl.models.transactions.NFTokenMint(
|
||||
account=mint_wallet.classic_address,
|
||||
uri=xrpl.utils.str_to_hex(uri),
|
||||
flags=int(flags),
|
||||
transfer_fee=int(transfer_fee),
|
||||
nftoken_taxon=int(taxon)
|
||||
)
|
||||
```
|
||||
|
||||
@@ -125,45 +127,40 @@ Sign and fill the transaction.
|
||||
Submit the transaction and return results.
|
||||
|
||||
```python
|
||||
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
|
||||
```
|
||||
|
||||
## getTokens
|
||||
|
||||
```python
|
||||
def get_tokens(_account):
|
||||
```
|
||||
|
||||
Import dependencies.
|
||||
|
||||
```python
|
||||
from xrpl.clients import JsonRpcClient
|
||||
from xrpl.models.requests import AccountNFTs
|
||||
import json
|
||||
def get_tokens(account):
|
||||
"""get_tokens"""
|
||||
```
|
||||
|
||||
Instantiate a client.
|
||||
|
||||
```python
|
||||
client = JsonRpcClient(testnet_url)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
Prepare the `AccountNFTs` request.
|
||||
|
||||
```python
|
||||
acct_nfts = AccountNFTs(
|
||||
account=_account
|
||||
acct_nfts=AccountNFTs(
|
||||
account=account
|
||||
)
|
||||
```
|
||||
|
||||
Send the request and return the result.
|
||||
|
||||
```python
|
||||
response = client.request(acct_nfts)
|
||||
response=client.request(acct_nfts)
|
||||
return response.result
|
||||
```
|
||||
|
||||
@@ -172,40 +169,43 @@ Send the request and return the result.
|
||||
Pass the owner's seed value and the NFT ID.
|
||||
|
||||
```python
|
||||
def burn_token(_seed, _nftoken_id):
|
||||
def burn_token(seed, nftoken_id):
|
||||
"""burn_token"""
|
||||
```
|
||||
|
||||
Get the owner wallet and client instance.
|
||||
|
||||
```python
|
||||
owner_wallet = Wallet(_seed, sequence = 16237283)
|
||||
client = JsonRpcClient(testnet_url)
|
||||
owner_wallet=Wallet(seed, sequence=16237283)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
Define the NFTokenBurn transaction.
|
||||
|
||||
```python
|
||||
burn_tx = xrpl.models.transactions.NFTokenBurn(
|
||||
account = owner_wallet.classic_address,
|
||||
nftoken_id = _nftoken_id
|
||||
burn_tx=xrpl.models.transactions.NFTokenBurn(
|
||||
account=owner_wallet.classic_address,
|
||||
nftoken_id=nftoken_id
|
||||
)
|
||||
```
|
||||
|
||||
Sign and fill the transaction.
|
||||
|
||||
```python
|
||||
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
burn_tx, owner_wallet, client)
|
||||
```
|
||||
|
||||
Submit the transaction and return results.
|
||||
|
||||
```python
|
||||
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
|
||||
```
|
||||
|
||||
|
||||
@@ -218,23 +218,27 @@ This module builds on `lesson2-create-trustline-send-currency.py`. Changes are n
|
||||
import tkinter as tk
|
||||
import xrpl
|
||||
import json
|
||||
import tkinter as tk
|
||||
import xrpl
|
||||
import json
|
||||
|
||||
from mod1 import get_account, get_account_info, send_xrp
|
||||
from mod2 import (
|
||||
create_trust_line,
|
||||
send_currency,
|
||||
get_balance,
|
||||
configure_account,
|
||||
)
|
||||
```
|
||||
|
||||
Import methods from `mod3.py`.
|
||||
|
||||
```python
|
||||
from mod3 import mint_token
|
||||
from mod3 import get_tokens
|
||||
from mod3 import burn_token
|
||||
|
||||
from mod2 import create_trust_line
|
||||
from mod2 import send_currency
|
||||
from mod2 import get_balance
|
||||
from mod2 import configure_account
|
||||
|
||||
from mod1 import get_account
|
||||
from mod1 import get_account_info
|
||||
from mod1 import send_xrp
|
||||
from mod3 import (
|
||||
mint_token,
|
||||
get_tokens,
|
||||
burn_token,
|
||||
)
|
||||
|
||||
#############################################
|
||||
## Handlers #################################
|
||||
@@ -254,10 +258,14 @@ def standby_mint_token():
|
||||
)
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def standby_get_tokens():
|
||||
results = get_tokens(ent_standby_account.get())
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def standby_burn_token():
|
||||
results = burn_token(
|
||||
ent_standby_seed.get(),
|
||||
@@ -265,6 +273,8 @@ def standby_burn_token():
|
||||
)
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def operational_mint_token():
|
||||
results = mint_token(
|
||||
ent_operational_seed.get(),
|
||||
@@ -275,10 +285,14 @@ def operational_mint_token():
|
||||
)
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def operational_get_tokens():
|
||||
results = get_tokens(ent_operational_account.get())
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def operational_burn_token():
|
||||
results = burn_token(
|
||||
ent_operational_seed.get(),
|
||||
@@ -287,15 +301,18 @@ def operational_burn_token():
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
# Module 2 Handlers
|
||||
|
||||
def standby_create_trustline():
|
||||
results = create_trustline(ent_standby_seed.get(),
|
||||
def standby_create_trust_line():
|
||||
results = create_trust_line(ent_standby_seed.get(),
|
||||
ent_standby_destination.get(),
|
||||
ent_standby_currency.get(),
|
||||
ent_standby_amount.get())
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def standby_send_currency():
|
||||
results = send_currency(ent_standby_seed.get(),
|
||||
ent_standby_destination.get(),
|
||||
@@ -303,12 +320,16 @@ def standby_send_currency():
|
||||
ent_standby_amount.get())
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def standby_configure_account():
|
||||
results = configure_account(
|
||||
ent_standby_seed.get(),
|
||||
standbyRippling)
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def operational_create_trust_line():
|
||||
results = create_trust_line(ent_operational_seed.get(),
|
||||
ent_operational_destination.get(),
|
||||
@@ -316,6 +337,8 @@ def operational_create_trust_line():
|
||||
ent_operational_amount.get())
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def operational_send_currency():
|
||||
results = send_currency(ent_operational_seed.get(),
|
||||
ent_operational_destination.get(),
|
||||
@@ -323,12 +346,16 @@ def operational_send_currency():
|
||||
ent_operational_amount.get())
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def operational_configure_account():
|
||||
results = configure_account(
|
||||
ent_operational_seed.get(),
|
||||
operationalRippling)
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0", json.dumps(results, indent=4))
|
||||
|
||||
|
||||
def get_balances():
|
||||
results = get_balance(ent_operational_account.get(), ent_standby_account.get())
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
@@ -344,12 +371,16 @@ def get_standby_account():
|
||||
ent_standby_seed.delete(0, tk.END)
|
||||
ent_standby_account.insert(0, new_wallet.classic_address)
|
||||
ent_standby_seed.insert(0, new_wallet.seed)
|
||||
|
||||
|
||||
def get_standby_account_info():
|
||||
accountInfo = get_account_info(ent_standby_account.get())
|
||||
ent_standby_balance.delete(0, tk.END)
|
||||
ent_standby_balance.insert(0,accountInfo['Balance'])
|
||||
text_standby_results.delete("1.0", tk.END)
|
||||
text_standby_results.insert("1.0",json.dumps(accountInfo, indent=4))
|
||||
|
||||
|
||||
def standby_send_xrp():
|
||||
response = send_xrp(ent_standby_seed.get(),ent_standby_amount.get(),
|
||||
ent_standby_destination.get())
|
||||
@@ -357,26 +388,35 @@ def standby_send_xrp():
|
||||
text_standby_results.insert("1.0",json.dumps(response.result, indent=4))
|
||||
get_standby_account_info()
|
||||
get_operational_account_info()
|
||||
|
||||
|
||||
def get_operational_account():
|
||||
new_wallet = get_account(ent_operational_seed.get())
|
||||
ent_operational_account.delete(0, tk.END)
|
||||
ent_operational_account.insert(0, new_wallet.classic_address)
|
||||
ent_operational_seed.delete(0, tk.END)
|
||||
ent_operational_seed.insert(0, new_wallet.seed)
|
||||
|
||||
|
||||
def get_operational_account_info():
|
||||
accountInfo = get_account_info(ent_operational_account.get())
|
||||
ent_operational_balance.delete(0, tk.END)
|
||||
ent_operational_balance.insert(0,accountInfo['Balance'])
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0",json.dumps(accountInfo, indent=4))
|
||||
|
||||
|
||||
def operational_send_xrp():
|
||||
response = send_xrp(ent_operational_seed.get(),ent_operational_amount.get(), ent_operational_destination.get())
|
||||
text_operational_results.delete("1.0", tk.END)
|
||||
text_operational_results.insert("1.0",json.dumps(response.result,indent=4))
|
||||
get_standby_account_info()
|
||||
get_operational_account_info()
|
||||
```
|
||||
|
||||
# Create a new window with the title "Quickstart Module 3"
|
||||
Create a new window with the title "Quickstart Module 3."
|
||||
|
||||
```python
|
||||
window = tk.Tk()
|
||||
window.title("Quickstart Module 3")
|
||||
|
||||
@@ -388,22 +428,22 @@ frm_form = tk.Frame(relief=tk.SUNKEN, borderwidth=3)
|
||||
frm_form.pack()
|
||||
|
||||
# Create the Label and Entry widgets for "Standby Account"
|
||||
lbl_standy_seed = tk.Label(master=frm_form, text="Standby Seed")
|
||||
ent_standby_seed = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standby_account = tk.Label(master=frm_form, text="Standby Account")
|
||||
ent_standby_account = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standby_balance = tk.Label(master=frm_form, text="XRP Balance")
|
||||
ent_standby_balance = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standy_amount = tk.Label(master=frm_form, text="Amount")
|
||||
ent_standby_amount = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standby_destination = tk.Label(master=frm_form, text="Destination")
|
||||
ent_standby_destination = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standby_currency = tk.Label(master=frm_form, text="Currency")
|
||||
ent_standby_currency = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_seed = tk.Label(master=frm_form, text="Operational Seed")
|
||||
ent_operational_seed = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_account = tk.Label(master=frm_form, text="Operational Account")
|
||||
ent_operational_account = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_amount = tk.Label(master=frm_form, text="Amount")
|
||||
ent_operational_amount = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_destination = tk.Label(master=frm_form, text="Destination")
|
||||
ent_operational_destination = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_balance = tk.Label(master=frm_form, text="XRP Balance")
|
||||
ent_operational_balance = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_currency = tk.Label(master=frm_form, text="Currency")
|
||||
ent_operational_currency = tk.Entry(master=frm_form, width=50)
|
||||
cb_standby_allow_rippling = tk.Checkbutton(master=frm_form, text="Allow Rippling", variable=standbyRippling, onvalue=True, offvalue=False)
|
||||
```
|
||||
|
||||
Add **NFT URI**, **Flags**, **Transfer Fee**, **Taxon**, **NFT ID** fields.
|
||||
Add **NFT URI**, **Flags**, **Transfer Fee**, **Taxon**, and **NFT ID** fields.
|
||||
|
||||
```python
|
||||
lbl_standby_uri = tk.Label(master=frm_form, text="NFT URI")
|
||||
@@ -461,12 +501,12 @@ lbl_operational_seed = tk.Label(master=frm_form, text="Operational Seed")
|
||||
ent_operational_seed = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_account = tk.Label(master=frm_form, text="Operational Account")
|
||||
ent_operational_account = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_balance = tk.Label(master=frm_form, text="XRP Balance")
|
||||
ent_operational_balance = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_amount = tk.Label(master=frm_form, text="Amount")
|
||||
ent_operational_amount = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_destination = tk.Label(master=frm_form, text="Destination")
|
||||
ent_operational_destination = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_balance = tk.Label(master=frm_form, text="XRP Balance")
|
||||
ent_operational_balance = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_currency = tk.Label(master=frm_form, text="Currency")
|
||||
ent_operational_currency = tk.Entry(master=frm_form, width=50)
|
||||
cb_operational_allow_rippling = tk.Checkbutton(master=frm_form, text="Allow Rippling", variable=operationalRippling, onvalue=True, offvalue=False)
|
||||
|
||||
@@ -145,13 +145,14 @@ testnet_url = "https://s.altnet.rippletest.net:51234"
|
||||
Pass the arguments _seed_, _amount_, _NFT ID_, _expiration_ (in seconds, optional), and _destination_ (optional).
|
||||
|
||||
```python
|
||||
def create_sell_offer(_seed, _amount, _nft_id, _expiration, _destination):
|
||||
def create_sell_offer(seed, amount, nftoken_id, expiration, destination):
|
||||
"""create_sell_offer"""
|
||||
```
|
||||
|
||||
Get the owner wallet and create a client connection.
|
||||
|
||||
```python
|
||||
owner_wallet = Wallet(_seed, sequence = 16237283)
|
||||
owner_wallet = Wallet(seed, sequence=16237283)
|
||||
client = JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
@@ -159,58 +160,60 @@ If there is an expiration value, convert the current date and time to Ripple tim
|
||||
|
||||
```python
|
||||
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 transaction.
|
||||
|
||||
```python
|
||||
sell_offer_tx = xrpl.models.transactions.NFTokenCreateOffer(
|
||||
account = owner_wallet.classic_address,
|
||||
nftoken_id = _nft_id,
|
||||
amount = _amount,
|
||||
sell_offer_tx=xrpl.models.transactions.NFTokenCreateOffer(
|
||||
account=owner_wallet.classic_address,
|
||||
nftoken_id=nftoken_id,
|
||||
amount=amount,
|
||||
```
|
||||
|
||||
If the sale is designated for a specific destination account, include the `destination` argument.
|
||||
|
||||
```python
|
||||
destination=_destination if _destination != '' else None,
|
||||
destination=destination if destination != '' else None,
|
||||
```
|
||||
|
||||
If the expiration date is present, include the `expiration` argument.
|
||||
|
||||
```python
|
||||
expiration = expiration_date if _expiration != '' else None,
|
||||
expiration=expiration_date if expiration != '' else None,
|
||||
```
|
||||
Set the `flags` value to _1_, indicating that this is a sell offer.
|
||||
|
||||
```python
|
||||
flags = 1
|
||||
flags=1
|
||||
)
|
||||
```
|
||||
|
||||
Sign the transaction.
|
||||
|
||||
```python
|
||||
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
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.send_reliable_submission(signed_tx,client)
|
||||
reply=response.result
|
||||
except xrpl.transaction.XRPLReliableSubmissionException as e:
|
||||
response = f"Submit failed: {e}"
|
||||
reply=f"Submit failed: {e}"
|
||||
```
|
||||
|
||||
Return the result.
|
||||
|
||||
```python
|
||||
return response.result
|
||||
return reply
|
||||
```
|
||||
|
||||
## Accept Sell Offer
|
||||
@@ -218,40 +221,43 @@ Return the result.
|
||||
Pass the buyer's seed value and the NFT sell offer index.
|
||||
|
||||
```python
|
||||
def accept_sell_offer(_seed, _offer_index):
|
||||
def accept_sell_offer(seed, offer_index):
|
||||
"""accept_sell_offer"""
|
||||
```
|
||||
|
||||
Get the wallet and a client instance.
|
||||
|
||||
```python
|
||||
buyer_wallet = Wallet(_seed, sequence = 16237283)
|
||||
client = JsonRpcClient(testnet_url)
|
||||
buyer_wallet=Wallet(seed, sequence=16237283)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
Define the accept offer transaction
|
||||
|
||||
```python
|
||||
accept_offer_tx = xrpl.models.transactions.NFTokenAcceptOffer(
|
||||
account = buyer_wallet.classic_address,
|
||||
nftoken_sell_offer = _offer_index
|
||||
accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer(
|
||||
account=buyer_wallet.classic_address,
|
||||
nftoken_sell_offer=offer_index
|
||||
)
|
||||
```
|
||||
|
||||
Sign and fill the transaction.
|
||||
|
||||
```python
|
||||
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
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.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
|
||||
```
|
||||
|
||||
## Create Buy Offer
|
||||
@@ -259,69 +265,72 @@ Submit the transaction and report the results.
|
||||
Pass the buyer _seed_, _amount_, _NFT ID_, _owner_, _expiration_ (in seconds, optional), and _destination_ account (optional).
|
||||
|
||||
```python
|
||||
def create_buy_offer(_seed, _amount, _nft_id, _owner, _expiration, _destination):
|
||||
def create_buy_offer(seed, amount, nft_id, owner, expiration, destination):
|
||||
"""create_buy_offer"""
|
||||
```
|
||||
|
||||
Get the buyer wallet and a client instance.
|
||||
|
||||
```python
|
||||
buyer_wallet = Wallet(_seed, sequence = 16237283)
|
||||
client = JsonRpcClient(testnet_url)
|
||||
buyer_wallet=Wallet(seed, sequence=16237283)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
If the _expiration_ value is present, get the current date and time, convert it to Ripple time, and add the _expiration_ value.
|
||||
|
||||
```python
|
||||
expiration_date = datetime.now()
|
||||
if (_expiration != ''):
|
||||
expiration_date = xrpl.utils.datetime_to_ripple_time(expiration_date)
|
||||
expiration_date = expiration_date + int(_expiration)
|
||||
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.
|
||||
|
||||
```python
|
||||
buy_offer_tx = xrpl.models.transactions.NFTokenCreateOffer(
|
||||
account = buyer_wallet.classic_address,
|
||||
nftoken_id = _nft_id,
|
||||
amount = _amount,
|
||||
owner = _owner,
|
||||
buy_offer_tx=xrpl.models.transactions.NFTokenCreateOffer(
|
||||
account=buyer_wallet.classic_address,
|
||||
nftoken_id=nft_id,
|
||||
amount=amount,
|
||||
owner=owner,
|
||||
```
|
||||
|
||||
IF the _expiration_ value is present, include the _expiration_ argument.
|
||||
|
||||
```python
|
||||
expiration = expiration_date if _expiration != '' else None,
|
||||
expiration=expiration_date if expiration!='' else None,
|
||||
```
|
||||
|
||||
If the _destination_ value is present, include the _destination_ argument.
|
||||
|
||||
```python
|
||||
destination=_destination if _destination != '' else None,
|
||||
destination=destination if destination!='' else None,
|
||||
```
|
||||
|
||||
Set the _flags_ value to _0_, indicating that this is a "buy" offer.
|
||||
|
||||
```python
|
||||
flags = 0
|
||||
flags=0
|
||||
)
|
||||
```
|
||||
|
||||
Sign and fill the transaction.
|
||||
|
||||
```python
|
||||
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.
|
||||
|
||||
```python
|
||||
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
|
||||
```
|
||||
|
||||
## Accept Buy Offer
|
||||
@@ -329,40 +338,43 @@ Submit the transaction and report the results.
|
||||
Pass the buyer's _seed_ value and the NFT _offer___index_.
|
||||
|
||||
```python
|
||||
def accept_buy_offer(_seed, _offer_index):
|
||||
def accept_buy_offer(seed, offer_index):
|
||||
"""accept_buy_offer"""
|
||||
```
|
||||
|
||||
Get the buyer wallet and a client instance.
|
||||
|
||||
```python
|
||||
buyer_wallet = Wallet(_seed, sequence = 16237283)
|
||||
client = JsonRpcClient(testnet_url)
|
||||
buyer_wallet=Wallet(seed, sequence=16237283)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
Define the accept offer transaction.
|
||||
|
||||
```python
|
||||
accept_offer_tx = xrpl.models.transactions.NFTokenAcceptOffer(
|
||||
account = buyer_wallet.classic_address,
|
||||
nftoken_buy_offer = _offer_index
|
||||
accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer(
|
||||
account=buyer_wallet.classic_address,
|
||||
nftoken_buy_offer=offer_index
|
||||
)
|
||||
```
|
||||
|
||||
Sign and fill the transaction.
|
||||
|
||||
```python
|
||||
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
|
||||
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.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
|
||||
```
|
||||
|
||||
## Get Offers
|
||||
@@ -372,53 +384,54 @@ This is a request, rather than a transaction, so there is no need for a wallet.
|
||||
Pass the _NFT ID_.
|
||||
|
||||
```python
|
||||
def get_offers(_nft_id):
|
||||
def get_offers(nft_id):
|
||||
"""get_offers"""
|
||||
```
|
||||
|
||||
Create a client instance.
|
||||
|
||||
```python
|
||||
client = JsonRpcClient(testnet_url)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
Define the request for buy offers.
|
||||
|
||||
```python
|
||||
offers = NFTBuyOffers(
|
||||
nft_id=_nft_id
|
||||
offers=NFTBuyOffers(
|
||||
nft_id=nft_id
|
||||
)
|
||||
```
|
||||
|
||||
Send the request and capture the response.
|
||||
|
||||
```python
|
||||
response = client.request(offers)
|
||||
response=client.request(offers)
|
||||
```
|
||||
|
||||
Create the _allOffers_ variable to accumulate the offer responses.
|
||||
|
||||
```python
|
||||
allOffers = "Buy Offers:\n" + json.dumps(response.result, indent=4)
|
||||
allOffers="Buy Offers:\n"+json.dumps(response.result, indent=4)
|
||||
```
|
||||
|
||||
Define the request for sell offers.
|
||||
|
||||
```python
|
||||
offers = NFTSellOffers(
|
||||
nft_id=_nft_id
|
||||
offers=NFTSellOffers(
|
||||
nft_id=nft_id
|
||||
)
|
||||
```
|
||||
|
||||
Send the request and capture the response.
|
||||
|
||||
```python
|
||||
response = client.request(offers)
|
||||
response=client.request(offers)
|
||||
```
|
||||
|
||||
Add the response to the _allOffers_ variable and return the results.
|
||||
|
||||
```python
|
||||
allOffers += "\n\nSell Offers:\n" + json.dumps(response.result, indent=4)
|
||||
allOffers+="\n\nSell Offers:\n"+json.dumps(response.result, indent=4)
|
||||
return allOffers
|
||||
```
|
||||
|
||||
@@ -429,28 +442,30 @@ The creator of an offer can cancel it at any time before it is accepted. Anyone
|
||||
Pass the seed and the NFT Offer ID to be canceled.
|
||||
|
||||
```python
|
||||
def cancel_offer(_seed, _nft_offer_ids):
|
||||
def cancel_offer(seed, nftoken_offer_ids):
|
||||
"""cancel_offer"""
|
||||
```
|
||||
|
||||
Get the wallet and a client instance.
|
||||
|
||||
```python
|
||||
owner_wallet = Wallet(_seed, sequence = 16237283)
|
||||
client = JsonRpcClient(testnet_url)
|
||||
owner_wallet=Wallet(seed, sequence=16237283)
|
||||
client=JsonRpcClient(testnet_url)
|
||||
```
|
||||
|
||||
The `nftoken_offers` parameter is an array, rather than a single ID. You can revise the code to accept several offer IDs at one time. Here, the value is added to a new array variable.
|
||||
|
||||
```python
|
||||
tokenOfferIDs = [_nft_offer_ids]
|
||||
tokenOfferIDs=[nftoken_offer_ids]
|
||||
```
|
||||
|
||||
Define the cancel offer transaction.
|
||||
|
||||
```python
|
||||
cancel_offer_tx = xrpl.models.transactions.NFTokenCancelOffer(
|
||||
account = owner_wallet.classic_address,
|
||||
nftoken_offers = tokenOfferIDs
|
||||
nftSellOffers="No sell offers"
|
||||
cancel_offer_tx=xrpl.models.transactions.NFTokenCancelOffer(
|
||||
account=owner_wallet.classic_address,
|
||||
nftoken_offers=tokenOfferIDs
|
||||
)
|
||||
```
|
||||
|
||||
@@ -464,11 +479,13 @@ Sign the transaction.
|
||||
Submit the transaction and return the result.
|
||||
|
||||
```python
|
||||
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
|
||||
```
|
||||
|
||||
## lesson4-transfer-tokens.py
|
||||
@@ -479,34 +496,32 @@ This module builds on `lesson3-mint-token.py`. Changes are noted below.
|
||||
import tkinter as tk
|
||||
import xrpl
|
||||
import json
|
||||
|
||||
from mod1 import get_account, get_account_info, send_xrp
|
||||
from mod2 import (
|
||||
create_trust_line,
|
||||
send_currency,
|
||||
get_balance,
|
||||
configure_account,
|
||||
)
|
||||
from mod3 import (
|
||||
mint_token,
|
||||
get_tokens,
|
||||
burn_token,
|
||||
)
|
||||
```
|
||||
|
||||
Import new methods from `mod4.py`.
|
||||
|
||||
```python
|
||||
from mod4 import create_sell_offer
|
||||
from mod4 import create_buy_offer
|
||||
from mod4 import get_offers
|
||||
from mod4 import cancel_offer
|
||||
from mod4 import accept_sell_offer
|
||||
from mod4 import accept_buy_offer
|
||||
|
||||
from mod3 import mint_token
|
||||
from mod3 import get_tokens
|
||||
from mod3 import burn_token
|
||||
|
||||
from mod2 import create_trust_line
|
||||
from mod2 import send_currency
|
||||
from mod2 import get_balance
|
||||
from mod2 import configure_account
|
||||
|
||||
from mod1 import get_account
|
||||
from mod1 import get_account_info
|
||||
from mod1 import send_xrp
|
||||
|
||||
#############################################
|
||||
## Handlers #################################
|
||||
#############################################
|
||||
from mod4 import (
|
||||
create_sell_offer,
|
||||
create_buy_offer,
|
||||
get_offers,
|
||||
cancel_offer,
|
||||
accept_sell_offer,
|
||||
accept_buy_offer,
|
||||
)
|
||||
|
||||
```
|
||||
|
||||
@@ -759,12 +774,12 @@ lbl_standy_seed = tk.Label(master=frm_form, text="Standby Seed")
|
||||
ent_standby_seed = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standby_account = tk.Label(master=frm_form, text="Standby Account")
|
||||
ent_standby_account = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standby_balance = tk.Label(master=frm_form, text="XRP Balance")
|
||||
ent_standby_balance = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standy_amount = tk.Label(master=frm_form, text="Amount")
|
||||
ent_standby_amount = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standby_destination = tk.Label(master=frm_form, text="Destination")
|
||||
ent_standby_destination = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standby_balance = tk.Label(master=frm_form, text="XRP Balance")
|
||||
ent_standby_balance = tk.Entry(master=frm_form, width=50)
|
||||
lbl_standby_currency = tk.Label(master=frm_form, text="Currency")
|
||||
ent_standby_currency = tk.Entry(master=frm_form, width=50)
|
||||
cb_standby_allow_rippling = tk.Checkbutton(master=frm_form, text="Allow Rippling", variable=standbyRippling, onvalue=True, offvalue=False)
|
||||
@@ -838,12 +853,12 @@ lbl_operational_seed = tk.Label(master=frm_form, text="Operational Seed")
|
||||
ent_operational_seed = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_account = tk.Label(master=frm_form, text="Operational Account")
|
||||
ent_operational_account = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_balance = tk.Label(master=frm_form, text="XRP Balance")
|
||||
ent_operational_balance = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_amount = tk.Label(master=frm_form, text="Amount")
|
||||
ent_operational_amount = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_destination = tk.Label(master=frm_form, text="Destination")
|
||||
ent_operational_destination = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_balance = tk.Label(master=frm_form, text="XRP Balance")
|
||||
ent_operational_balance = tk.Entry(master=frm_form, width=50)
|
||||
lbl_operational_currency = tk.Label(master=frm_form, text="Currency")
|
||||
ent_operational_currency = tk.Entry(master=frm_form, width=50)
|
||||
cb_operational_allow_rippling = tk.Checkbutton(master=frm_form, text="Allow Rippling", variable=operationalRippling, onvalue=True, offvalue=False)
|
||||
|
||||
Reference in New Issue
Block a user