Fixes per GregW

This commit is contained in:
ddawson
2023-06-21 11:11:07 -07:00
parent 73679228b4
commit d152f75db5
5 changed files with 485 additions and 352 deletions

View File

@@ -118,42 +118,44 @@ testnet_url = "https://s.altnet.rippletest.net:51234"
Pass the _seed_, _sell___offer___index_, _buy___offer___index_, and _broker___fee_. Pass the _seed_, _sell___offer___index_, _buy___offer___index_, and _broker___fee_.
```python ```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. Get the broker wallet and establish a client connection.
```python ```python
broker_wallet = Wallet(_seed, sequence = 16237283) broker_wallet=Wallet(seed, sequence=16237283)
client = JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
``` ```
Define the accept offer transaction, matching a sell offer with the selected buy offer. Define the accept offer transaction, matching a sell offer with the selected buy offer.
```python ```python
accept_offer_tx = xrpl.models.transactions.NFTokenAcceptOffer( accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer(
account = broker_wallet.classic_address, account=broker_wallet.classic_address,
nftoken_sell_offer = _sell_offer_index, nftoken_sell_offer=sell_offer_index,
nftoken_buy_offer = _buy_offer_index, nftoken_buy_offer=buy_offer_index,
nftoken_broker_fee = _broker_fee nftoken_broker_fee=broker_fee
) )
``` ```
Sign and fill the transaction. Sign and fill the transaction.
```python ```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) accept_offer_tx, broker_wallet, client)
``` ```
Submit the transaction and report the results. Submit the transaction and report the results.
```python ```python
reply=""
try: 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: except xrpl.transaction.XRPLReliableSubmissionException as e:
response = f"Submit failed: {e}" reply=f"Submit failed: {e}"
return response.result
``` ```
## lesson5-broker-nfts.py ## lesson5-broker-nfts.py
@@ -169,28 +171,28 @@ import json
Import the `broker_sale` method. Import the `broker_sale` method.
```python ```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 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 ################################# ## Handlers #################################
############################################# #############################################
@@ -207,12 +209,16 @@ def get_broker_account():
ent_broker_seed.delete(0, tk.END) ent_broker_seed.delete(0, tk.END)
ent_broker_account.insert(0, new_wallet.classic_address) ent_broker_account.insert(0, new_wallet.classic_address)
ent_broker_seed.insert(0, new_wallet.seed) ent_broker_seed.insert(0, new_wallet.seed)
def get_broker_account_info(): def get_broker_account_info():
accountInfo = get_account_info(ent_broker_account.get()) accountInfo = get_account_info(ent_broker_account.get())
ent_broker_balance.delete(0, tk.END) ent_broker_balance.delete(0, tk.END)
ent_broker_balance.insert(0,accountInfo['Balance']) ent_broker_balance.insert(0,accountInfo['Balance'])
text_broker_results.delete("1.0", tk.END) text_broker_results.delete("1.0", tk.END)
text_broker_results.insert("1.0",json.dumps(accountInfo, indent=4)) text_broker_results.insert("1.0",json.dumps(accountInfo, indent=4))
def broker_broker_sale(): def broker_broker_sale():
results = broker_sale( results = broker_sale(
ent_broker_seed.get(), ent_broker_seed.get(),
@@ -222,10 +228,14 @@ def broker_broker_sale():
) )
text_broker_results.delete("1.0", tk.END) text_broker_results.delete("1.0", tk.END)
text_broker_results.insert("1.0", json.dumps(results, indent=4)) text_broker_results.insert("1.0", json.dumps(results, indent=4))
def broker_get_offers(): def broker_get_offers():
results = get_offers(ent_broker_nft_id.get()) results = get_offers(ent_broker_nft_id.get())
text_broker_results.delete("1.0", tk.END) text_broker_results.delete("1.0", tk.END)
text_broker_results.insert("1.0", results) text_broker_results.insert("1.0", results)
def broker_cancel_offer(): def broker_cancel_offer():
results = cancel_offer( results = cancel_offer(
ent_broker_seed.get(), ent_broker_seed.get(),
@@ -247,6 +257,8 @@ def standby_create_sell_offer():
) )
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4)) text_standby_results.insert("1.0", json.dumps(results, indent=4))
def standby_accept_sell_offer(): def standby_accept_sell_offer():
results = accept_sell_offer ( results = accept_sell_offer (
ent_standby_seed.get(), ent_standby_seed.get(),
@@ -254,6 +266,8 @@ def standby_accept_sell_offer():
) )
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4)) text_standby_results.insert("1.0", json.dumps(results, indent=4))
def standby_create_buy_offer(): def standby_create_buy_offer():
results = create_buy_offer( results = create_buy_offer(
ent_standby_seed.get(), ent_standby_seed.get(),
@@ -265,6 +279,8 @@ def standby_create_buy_offer():
) )
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4)) text_standby_results.insert("1.0", json.dumps(results, indent=4))
def standby_accept_buy_offer(): def standby_accept_buy_offer():
results = accept_buy_offer ( results = accept_buy_offer (
ent_standby_seed.get(), ent_standby_seed.get(),
@@ -272,10 +288,14 @@ def standby_accept_buy_offer():
) )
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4)) text_standby_results.insert("1.0", json.dumps(results, indent=4))
def standby_get_offers(): def standby_get_offers():
results = get_offers(ent_standby_nft_id.get()) results = get_offers(ent_standby_nft_id.get())
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", results) text_standby_results.insert("1.0", results)
def standby_cancel_offer(): def standby_cancel_offer():
results = cancel_offer( results = cancel_offer(
ent_standby_seed.get(), ent_standby_seed.get(),
@@ -283,6 +303,8 @@ def standby_cancel_offer():
) )
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4)) text_standby_results.insert("1.0", json.dumps(results, indent=4))
def op_create_sell_offer(): def op_create_sell_offer():
results = create_sell_offer( results = create_sell_offer(
ent_operational_seed.get(), ent_operational_seed.get(),
@@ -293,6 +315,8 @@ def op_create_sell_offer():
) )
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4)) text_operational_results.insert("1.0", json.dumps(results, indent=4))
def op_accept_sell_offer(): def op_accept_sell_offer():
results = accept_sell_offer ( results = accept_sell_offer (
ent_operational_seed.get(), ent_operational_seed.get(),
@@ -300,6 +324,8 @@ def op_accept_sell_offer():
) )
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4)) text_operational_results.insert("1.0", json.dumps(results, indent=4))
def op_create_buy_offer(): def op_create_buy_offer():
results = create_buy_offer( results = create_buy_offer(
ent_operational_seed.get(), ent_operational_seed.get(),
@@ -311,6 +337,8 @@ def op_create_buy_offer():
) )
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4)) text_operational_results.insert("1.0", json.dumps(results, indent=4))
def op_accept_buy_offer(): def op_accept_buy_offer():
results = accept_buy_offer ( results = accept_buy_offer (
ent_operational_seed.get(), ent_operational_seed.get(),
@@ -318,10 +346,14 @@ def op_accept_buy_offer():
) )
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4)) text_operational_results.insert("1.0", json.dumps(results, indent=4))
def op_get_offers(): def op_get_offers():
results = get_offers(ent_operational_nft_id.get()) results = get_offers(ent_operational_nft_id.get())
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", results) text_operational_results.insert("1.0", results)
def op_cancel_offer(): def op_cancel_offer():
results = cancel_offer( results = cancel_offer(
ent_operational_seed.get(), ent_operational_seed.get(),
@@ -344,10 +376,14 @@ def standby_mint_token():
) )
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4)) text_standby_results.insert("1.0", json.dumps(results, indent=4))
def standby_get_tokens(): def standby_get_tokens():
results = get_tokens(ent_standby_account.get()) results = get_tokens(ent_standby_account.get())
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4)) text_standby_results.insert("1.0", json.dumps(results, indent=4))
def standby_burn_token(): def standby_burn_token():
results = burn_token( results = burn_token(
ent_standby_seed.get(), ent_standby_seed.get(),
@@ -355,6 +391,8 @@ def standby_burn_token():
) )
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4)) text_standby_results.insert("1.0", json.dumps(results, indent=4))
def operational_mint_token(): def operational_mint_token():
results = mint_token( results = mint_token(
ent_operational_seed.get(), ent_operational_seed.get(),
@@ -365,10 +403,14 @@ def operational_mint_token():
) )
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4)) text_operational_results.insert("1.0", json.dumps(results, indent=4))
def operational_get_tokens(): def operational_get_tokens():
results = get_tokens(ent_operational_account.get()) results = get_tokens(ent_operational_account.get())
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4)) text_operational_results.insert("1.0", json.dumps(results, indent=4))
def operational_burn_token(): def operational_burn_token():
results = burn_token( results = burn_token(
ent_operational_seed.get(), ent_operational_seed.get(),
@@ -377,6 +419,7 @@ def operational_burn_token():
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4)) text_operational_results.insert("1.0", json.dumps(results, indent=4))
# Module 2 Handlers # Module 2 Handlers
def standby_create_trust_line(): def standby_create_trust_line():
@@ -386,6 +429,8 @@ def standby_create_trust_line():
ent_standby_amount.get()) ent_standby_amount.get())
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4)) text_standby_results.insert("1.0", json.dumps(results, indent=4))
def standby_send_currency(): def standby_send_currency():
results = send_currency(ent_standby_seed.get(), results = send_currency(ent_standby_seed.get(),
ent_standby_destination.get(), ent_standby_destination.get(),
@@ -393,12 +438,16 @@ def standby_send_currency():
ent_standby_amount.get()) ent_standby_amount.get())
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4)) text_standby_results.insert("1.0", json.dumps(results, indent=4))
def standby_configure_account(): def standby_configure_account():
results = configure_account( results = configure_account(
ent_standby_seed.get(), ent_standby_seed.get(),
standbyRippling) standbyRippling)
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4)) text_standby_results.insert("1.0", json.dumps(results, indent=4))
def operational_create_trust_line(): def operational_create_trust_line():
results = create_trust_line(ent_operational_seed.get(), results = create_trust_line(ent_operational_seed.get(),
ent_operational_destination.get(), ent_operational_destination.get(),
@@ -406,6 +455,8 @@ def operational_create_trust_line():
ent_operational_amount.get()) ent_operational_amount.get())
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4)) text_operational_results.insert("1.0", json.dumps(results, indent=4))
def operational_send_currency(): def operational_send_currency():
results = send_currency(ent_operational_seed.get(), results = send_currency(ent_operational_seed.get(),
ent_operational_destination.get(), ent_operational_destination.get(),
@@ -413,12 +464,16 @@ def operational_send_currency():
ent_operational_amount.get()) ent_operational_amount.get())
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4)) text_operational_results.insert("1.0", json.dumps(results, indent=4))
def operational_configure_account(): def operational_configure_account():
results = configure_account( results = configure_account(
ent_operational_seed.get(), ent_operational_seed.get(),
operationalRippling) operationalRippling)
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4)) text_operational_results.insert("1.0", json.dumps(results, indent=4))
def get_balances(): def get_balances():
results = get_balance(ent_operational_account.get(), ent_standby_account.get()) results = get_balance(ent_operational_account.get(), ent_standby_account.get())
text_standby_results.delete("1.0", tk.END) 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.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4)) text_operational_results.insert("1.0", json.dumps(results, indent=4))
# Module 1 Handlers # Module 1 Handlers
def get_standby_account(): def get_standby_account():
new_wallet = get_account(ent_standby_seed.get()) 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_seed.delete(0, tk.END)
ent_standby_account.insert(0, new_wallet.classic_address) ent_standby_account.insert(0, new_wallet.classic_address)
ent_standby_seed.insert(0, new_wallet.seed) ent_standby_seed.insert(0, new_wallet.seed)
def get_standby_account_info(): def get_standby_account_info():
accountInfo = get_account_info(ent_standby_account.get()) accountInfo = get_account_info(ent_standby_account.get())
ent_standby_balance.delete(0, tk.END) ent_standby_balance.delete(0, tk.END)
ent_standby_balance.insert(0,accountInfo['Balance']) ent_standby_balance.insert(0,accountInfo['Balance'])
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0",json.dumps(accountInfo, indent=4)) text_standby_results.insert("1.0",json.dumps(accountInfo, indent=4))
def standby_send_xrp(): def standby_send_xrp():
response = send_xrp(ent_standby_seed.get(),ent_standby_amount.get(), response = send_xrp(ent_standby_seed.get(),ent_standby_amount.get(),
ent_standby_destination.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)) text_standby_results.insert("1.0",json.dumps(response.result, indent=4))
get_standby_account_info() get_standby_account_info()
get_operational_account_info() get_operational_account_info()
def get_operational_account(): def get_operational_account():
new_wallet = get_account(ent_operational_seed.get()) new_wallet = get_account(ent_operational_seed.get())
ent_operational_account.delete(0, tk.END) ent_operational_account.delete(0, tk.END)
ent_operational_account.insert(0, new_wallet.classic_address) ent_operational_account.insert(0, new_wallet.classic_address)
ent_operational_seed.delete(0, tk.END) ent_operational_seed.delete(0, tk.END)
ent_operational_seed.insert(0, new_wallet.seed) ent_operational_seed.insert(0, new_wallet.seed)
def get_operational_account_info(): def get_operational_account_info():
accountInfo = get_account_info(ent_operational_account.get()) accountInfo = get_account_info(ent_operational_account.get())
ent_operational_balance.delete(0, tk.END) ent_operational_balance.delete(0, tk.END)
ent_operational_balance.insert(0,accountInfo['Balance']) ent_operational_balance.insert(0,accountInfo['Balance'])
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0",json.dumps(accountInfo, indent=4)) text_operational_results.insert("1.0",json.dumps(accountInfo, indent=4))
def operational_send_xrp(): def operational_send_xrp():
response = send_xrp(ent_operational_seed.get(),ent_operational_amount.get(), ent_operational_destination.get()) 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.delete("1.0", tk.END)
text_operational_results.insert("1.0",json.dumps(response.result,indent=4)) text_operational_results.insert("1.0",json.dumps(response.result,indent=4))
get_standby_account_info() get_standby_account_info()
get_operational_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 = tk.Tk()
window.title("Quickstart - Broker Sale") window.title("Quickstart - Broker Sale")
@@ -474,12 +543,11 @@ myscrollbar=tk.Scrollbar(window,orient="vertical")
myscrollbar.pack(side="right",fill="y") myscrollbar.pack(side="right",fill="y")
standbyRippling = tk.BooleanVar() standbyRippling = tk.BooleanVar()
operationalRippling = 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 ```python
# Broker frame # Broker frame
@@ -538,7 +606,7 @@ lbl_broker_results.grid(row=9, column=0)
text_broker_results.grid(row=9, column=1) text_broker_results.grid(row=9, column=1)
``` ```
Define and place the Broker buttons. Define and place the broker buttons.
```python ```python
btn_broker_get_account = tk.Button(master=frm_broker, text="Get Broker Account", 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) ent_standby_seed = tk.Entry(master=frm_form, width=50)
lbl_standby_account = tk.Label(master=frm_form, text="Standby Account") lbl_standby_account = tk.Label(master=frm_form, text="Standby Account")
ent_standby_account = tk.Entry(master=frm_form, width=50) 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") lbl_standy_amount = tk.Label(master=frm_form, text="Amount")
ent_standby_amount = tk.Entry(master=frm_form, width=50) ent_standby_amount = tk.Entry(master=frm_form, width=50)
lbl_standby_destination = tk.Label(master=frm_form, text="Destination") lbl_standby_destination = tk.Label(master=frm_form, text="Destination")
ent_standby_destination = tk.Entry(master=frm_form, width=50) 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") lbl_standby_currency = tk.Label(master=frm_form, text="Currency")
ent_standby_currency = tk.Entry(master=frm_form, width=50) 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) 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") ent_standby_owner = tk.Entry(master=frm_form, width="50")
lbl_standby_expiration = tk.Label(master=frm_form, text="Expiration") lbl_standby_expiration = tk.Label(master=frm_form, text="Expiration")
ent_standby_expiration = tk.Entry(master=frm_form, width="50") 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') lbl_standby_results = tk.Label(master=frm_form,text='Results')
text_standby_results = tk.Text(master=frm_form, height = 10, width = 65) 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) ent_operational_seed = tk.Entry(master=frm_form, width=50)
lbl_operational_account = tk.Label(master=frm_form, text="Operational Account") lbl_operational_account = tk.Label(master=frm_form, text="Operational Account")
ent_operational_account = tk.Entry(master=frm_form, width=50) 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") lbl_operational_amount = tk.Label(master=frm_form, text="Amount")
ent_operational_amount = tk.Entry(master=frm_form, width=50) ent_operational_amount = tk.Entry(master=frm_form, width=50)
lbl_operational_destination = tk.Label(master=frm_form, text="Destination") lbl_operational_destination = tk.Label(master=frm_form, text="Destination")
ent_operational_destination = tk.Entry(master=frm_form, width=50) 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") lbl_operational_currency = tk.Label(master=frm_form, text="Currency")
ent_operational_currency = tk.Entry(master=frm_form, width=50) 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) 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") ent_operational_owner = tk.Entry(master=frm_form, width="50")
lbl_operational_expiration = tk.Label(master=frm_form, text="Expiration") lbl_operational_expiration = tk.Label(master=frm_form, text="Expiration")
ent_operational_expiration = tk.Entry(master=frm_form, width="50") 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") lbl_operational_results = tk.Label(master=frm_form,text="Results")
text_operational_results = tk.Text(master=frm_form, height = 10, width = 65) text_operational_results = tk.Text(master=frm_form, height = 10, width = 65)

View File

@@ -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. 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 ```python
import xrpl import xrpl
import json import json
import xrpl.clients
import xrpl.wallet
``` ```
### get_account ### 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. Import required methods.
```python ```python
def get_account(_seed): def get_account(seed):
from xrpl.clients import JsonRpcClient """get_account"""
from xrpl.wallet import Wallet
``` ```
This example uses the _Testnet_ ledger. You can update the URI to choose a different XRP Ledger instance. 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. Request a new client from the XRP Ledger.
```python ```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. 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 ```python
if (_seed == ''): if (seed == ''):
new_wallet = xrpl.wallet.generate_faucet_wallet(client) new_wallet = xrpl.wallet.generate_faucet_wallet(client)
else: else:
new_wallet = Wallet(_seed, sequence = 79396029) new_wallet = xrpl.wallet.Wallet(seed, sequence = 79396029)
return(new_wallet) 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. Pass the account ID to the `get_account_info` method.
```python ```python
def get_account_info(_accountId): def get_account_info(accountId):
``` """get_account_info"""
Import required methods and the JSON library.
```python
from xrpl.clients import JsonRpcClient
from xrpl.models.requests.account_info import AccountInfo
import json
``` ```
Get a client instance from Testnet. Get a client instance from Testnet.
```python ```python
JSON_RPC_URL = 'wss://s.altnet.rippletest.net:51234' 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). Create the account info request, passing the account ID and the ledger index (in this case, the latest validated ledger).
```python ```python
acct_info = AccountInfo( acct_info = xrpl.models.requests.account_info.AccountInfo(
account=_accountId, account=accountId,
ledger_index="validated" 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. Send the request to the XRP Ledger instance.
```python ```python
response = client.request(acct_info) response=client.request(acct_info)
``` ```
Return the account data. 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. Transfer XRP to another account by passing the client seed, amount to transfer, and the destination account.
```python ```python
def send_xrp(_seed, _amount, _destination): def send_xrp(seed, amount, destination):
``` ```
Get the sending wallet. Get the sending wallet.
```python ```python
from xrpl.clients import JsonRpcClient sending_wallet = xrpl.wallet.Wallet(seed, sequence = 16237283)
from xrpl.wallet import Wallet
sending_wallet = Wallet(_seed, sequence = 16237283)
testnet_url = "https://s.altnet.rippletest.net:51234" 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. Create a transaction request, passing the sending account, amount, and destination account.
```python ```python
payment = xrpl.models.transactions.Payment( payment=xrpl.models.transactions.Payment(
account=sending_wallet.classic_address, account=sending_wallet.classic_address,
amount=xrpl.utils.xrp_to_drops(int(_amount)), amount=xrpl.utils.xrp_to_drops(int(amount)),
destination=_destination, destination=destination,
) )
``` ```
@@ -215,9 +208,7 @@ import json
Import the methods from mod1.py. Import the methods from mod1.py.
```python ```python
from mod1 import get_account from .mod1 import get_account, get_account_info, send_xrp
from mod1 import get_accountInfo
from mod1 import send_xrp
``` ```
### getStandbyAccount ### getStandbyAccount
@@ -307,12 +298,16 @@ def get_operational_account():
ent_operational_account.insert(0, new_wallet.classic_address) ent_operational_account.insert(0, new_wallet.classic_address)
ent_operational_seed.delete(0, tk.END) ent_operational_seed.delete(0, tk.END)
ent_operational_seed.insert(0, new_wallet.seed) ent_operational_seed.insert(0, new_wallet.seed)
def get_operational_account_info(): def get_operational_account_info():
account_info = get_account_info(ent_operational_account.get()) account_info = get_account_info(ent_operational_account.get())
ent_operational_balance.delete(0, tk.END) ent_operational_balance.delete(0, tk.END)
ent_operational_balance.insert(0,accountInfo['Balance']) ent_operational_balance.insert(0,accountInfo['Balance'])
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0",json.dumps(accountInfo, indent=4)) text_operational_results.insert("1.0",json.dumps(accountInfo, indent=4))
def operational_send_xrp(): def operational_send_xrp():
response = send_xrp(ent_operational_seed.get(),ent_operational_amount.get(), response = send_xrp(ent_operational_seed.get(),ent_operational_amount.get(),
ent_operational_destination.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) ent_standby_seed = tk.Entry(master=frm_form, width=50)
lbl_standby_account = tk.Label(master=frm_form, text="Standby Account") lbl_standby_account = tk.Label(master=frm_form, text="Standby Account")
ent_standby_account = tk.Entry(master=frm_form, width=50) 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") lbl_standy_amount = tk.Label(master=frm_form, text="Amount")
ent_standby_amount = tk.Entry(master=frm_form, width=50) ent_standby_amount = tk.Entry(master=frm_form, width=50)
lbl_standby_destination = tk.Label(master=frm_form, text="Destination") lbl_standby_destination = tk.Label(master=frm_form, text="Destination")
ent_standby_destination = tk.Entry(master=frm_form, width=50) 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') lbl_standby_results = tk.Label(master=frm_form,text='Results')
text_standby_results = tk.Text(master=frm_form, height = 20, width = 65) 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) ent_operational_seed = tk.Entry(master=frm_form, width=50)
lbl_operational_account = tk.Label(master=frm_form, text="Operational Account") lbl_operational_account = tk.Label(master=frm_form, text="Operational Account")
ent_operational_account = tk.Entry(master=frm_form, width=50) 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") lbl_operational_amount = tk.Label(master=frm_form, text="Amount")
ent_operational_amount = tk.Entry(master=frm_form, width=50) ent_operational_amount = tk.Entry(master=frm_form, width=50)
lbl_operational_destination = tk.Label(master=frm_form, text="Destination") lbl_operational_destination = tk.Label(master=frm_form, text="Destination")
ent_operational_destination = tk.Entry(master=frm_form, width=50) 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') lbl_operational_results = tk.Label(master=frm_form,text='Results')
text_operational_results = tk.Text(master=frm_form, height = 20, width = 65) text_operational_results = tk.Text(master=frm_form, height = 20, width = 65)
``` ```

View File

@@ -96,6 +96,7 @@ import xrpl
import json import json
from xrpl.clients import JsonRpcClient from xrpl.clients import JsonRpcClient
from xrpl.wallet import Wallet from xrpl.wallet import Wallet
from xrpl.models.requests.account_info import AccountInfo
testnet_url = "https://s.altnet.rippletest.net:51234" 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. Pass the wallet seed, the issuer account, the currency code, and the maximum amount of currency to send.
```python ```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. Get the wallet and a new client instance.
```python ```python
receiving_wallet = Wallet(_seed, sequence = 16237283) receiving_wallet = Wallet(seed, sequence = 16237283)
client = JsonRpcClient(testnet_url) client = JsonRpcClient(testnet_url)
``` ```
Define the `TrustSet` transaction. Define the `TrustSet` transaction.
```python ```python
trustline_tx = xrpl.models.transactions.TrustSet( trustline_tx=xrpl.models.transactions.TrustSet(
account = receiving_wallet.classic_address, account=receiving_wallet.classic_address,
limit_amount = xrpl.models.amounts.IssuedCurrencyAmount( limit_amount=xrpl.models.amounts.IssuedCurrencyAmount(
currency = _currency, currency=currency,
issuer = _issuer, issuer=issuer,
value = int(_amount) value=int(amount)
) )
) )
``` ```
@@ -138,66 +140,71 @@ Sign the transaction.
Submit the transaction to the XRP Ledger. Submit the transaction to the XRP Ledger.
```python ```python
reply = ""
try: 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: except xrpl.transaction.XRPLReliableSubmissionException as e:
response = f"Submit failed: {e}" reply = f"Submit failed: {e}"
``` ```
Return the results. Return the results.
```python ```python
return response.result return reply
``` ```
## send_currency ## send_currency
Send currency to another account based on the sender wallet, destination account, the currency type, and the amount of the currency. Send currency to another account based on the sender wallet, destination account, the currency type, and the amount of the currency.
```python ```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. Get the sending wallet and a client instance on Testnet.
```python ```python
sending_wallet = Wallet(_seed, sequence = 16237283) sending_wallet=Wallet(seed, sequence=16237283)
client = JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
``` ```
Define the payment transaction. The amount requires further description to identify the type of currency and issuer. Define the payment transaction. The amount requires further description to identify the type of currency and issuer.
```python ```python
send_currency_tx = xrpl.models.transactions.Payment( send_currency_tx=xrpl.models.transactions.Payment(
account = sending_wallet.classic_address, account=sending_wallet.classic_address,
amount = xrpl.models.amounts.IssuedCurrencyAmount( amount=xrpl.models.amounts.IssuedCurrencyAmount(
currency = _currency, currency=currency,
value = int(_amount), value=int(amount),
issuer = sending_wallet.classic_address issuer=sending_wallet.classic_address
), ),
destination=_destination destination=destination
) )
``` ```
Sign and fill the transaction. Sign and fill the transaction.
```python ```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) send_currency_tx, sending_wallet, client)
``` ```
Submit the transaction and get the response. Submit the transaction and get the response.
```python ```python
reply = ""
try: 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: 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. Return the JSON response, or an error message if the transaction fails.
```python ```python
return response.result return reply
``` ```
### get_balance ### 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. Update the **XRP Balance** fields and list the balance information for issued currencies in the **Results** text areas.
```python ```python
def get_balance(_sb_account_id, _op_account_id): def get_balance(sb_account_id, op_account_id):
``` """get_balance"""
Import the `AccountInfo` request method.
```python
from xrpl.models.requests.account_info import AccountInfo
``` ```
Connect to the XRP Ledger and instantiate a client. Connect to the XRP Ledger and instantiate a client.
```python ```python
JSON_RPC_URL = 'wss://s.altnet.rippletest.net:51234' JSON_RPC_URL='wss://s.altnet.rippletest.net:51234'
client = JsonRpcClient(JSON_RPC_URL) client=JsonRpcClient(JSON_RPC_URL)
``` ```
Create the `GatewayBalances` request. Create the `GatewayBalances` request.
```python ```python
balance = xrpl.models.requests.GatewayBalances( balance=xrpl.models.requests.GatewayBalances(
account=_sb_account_id , account=sb_account_id,
strict=True,
ledger_index="validated", 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. Send the account seed and a Boolean value for whether to enable or disable rippling.
```python ```python
def configure_account(_seed, _default_setting): def configure_account(seed, default_setting):
"""configure_account"
``` ```
Get the account wallet and instantiate a client. Get the account wallet and instantiate a client.
```python ```python
wallet = Wallet(_seed, sequence = 16237283) wallet=Wallet(seed, sequence = 16237283)
client = JsonRpcClient(testnet_url) 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 ```python
if (_default_setting.get()): if (default_setting):
setting_tx = xrpl.models.transactions.AccountSet( setting_tx=xrpl.models.transactions.AccountSet(
account = wallet.classic_address, account=wallet.classic_address,
set_flag=xrpl.models.transactions.AccountSetFlag.ASF_DEFAULT_RIPPLE set_flag=xrpl.models.transactions.AccountSetFlag.ASF_DEFAULT_RIPPLE
) )
else: else:
setting_tx = xrpl.models.transactions.AccountSet( setting_tx=xrpl.models.transactions.AccountSet(
account = wallet.classic_address, account=wallet.classic_address,
clear_flag = xrpl.models.transactions.AccountSetFlag.ASF_DEFAULT_RIPPLE clear_flag=xrpl.models.transactions.AccountSetFlag.ASF_DEFAULT_RIPPLE
) )
``` ```
Sign and fill the transaction. Sign and fill the transaction.
```python ```python
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction( signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
setting_tx, wallet, client) setting_tx, wallet, client)
``` ```
Submit the transaction and get results. Submit the transaction and get results.
```python ```python
reply = ""
try: 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: except xrpl.transaction.XRPLReliableSubmissionException as e:
response.result = f"Submit failed: {e}" reply = f"Submit failed: {e}"
``` ```
Return the results. Return the results.
```python ```python
return response.result return reply
``` ```
## lesson2-send-currency.py ## lesson2-send-currency.py
@@ -305,18 +309,13 @@ import json
Import methods from `mod2.py`. Import methods from `mod2.py`.
```python ```python
from mod2 import create_trust_line from mod1 import get_account, get_account_info, send_xrp
from mod2 import send_currency from mod2 import (
from mod2 import get_balance create_trust_line,
from mod2 import configure_account send_currency,
get_balance,
from mod1 import get_account configure_account,
from mod1 import get_account_info )
from mod1 import send_xrp
#############################################
## Handlers #################################
#############################################
``` ```
Module 2 Handlers. Module 2 Handlers.
@@ -329,6 +328,8 @@ def standby_create_trust_line():
ent_standby_amount.get()) ent_standby_amount.get())
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4)) text_standby_results.insert("1.0", json.dumps(results, indent=4))
def standby_send_currency(): def standby_send_currency():
results = send_currency(ent_standby_seed.get(), results = send_currency(ent_standby_seed.get(),
ent_standby_destination.get(), ent_standby_destination.get(),
@@ -336,12 +337,16 @@ def standby_send_currency():
ent_standby_amount.get()) ent_standby_amount.get())
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4)) text_standby_results.insert("1.0", json.dumps(results, indent=4))
def standby_configure_account(): def standby_configure_account():
results = configure_account( results = configure_account(
ent_standby_seed.get(), ent_standby_seed.get(),
standbyRippling) standbyRippling)
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4)) text_standby_results.insert("1.0", json.dumps(results, indent=4))
def operational_create_trust_line(): def operational_create_trust_line():
results = create_trust_line(ent_operational_seed.get(), results = create_trust_line(ent_operational_seed.get(),
ent_operational_destination.get(), ent_operational_destination.get(),
@@ -349,6 +354,8 @@ def operational_create_trust_line():
ent_operational_amount.get()) ent_operational_amount.get())
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4)) text_operational_results.insert("1.0", json.dumps(results, indent=4))
def operational_send_currency(): def operational_send_currency():
results = send_currency(ent_operational_seed.get(), results = send_currency(ent_operational_seed.get(),
ent_operational_destination.get(), ent_operational_destination.get(),
@@ -356,12 +363,16 @@ def operational_send_currency():
ent_operational_amount.get()) ent_operational_amount.get())
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4)) text_operational_results.insert("1.0", json.dumps(results, indent=4))
def operational_configure_account(): def operational_configure_account():
results = configure_account( results = configure_account(
ent_operational_seed.get(), ent_operational_seed.get(),
operationalRippling) operationalRippling)
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4)) text_operational_results.insert("1.0", json.dumps(results, indent=4))
def get_balances(): def get_balances():
results = get_balance(ent_operational_account.get(), ent_standby_account.get()) results = get_balance(ent_operational_account.get(), ent_standby_account.get())
text_standby_results.delete("1.0", tk.END) 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.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4)) text_operational_results.insert("1.0", json.dumps(results, indent=4))
# Module 1 Handlers # Module 1 Handlers
def get_standby_account(): def get_standby_account():
new_wallet = get_account(ent_standby_seed.get()) 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_seed.delete(0, tk.END)
ent_standby_account.insert(0, new_wallet.classic_address) ent_standby_account.insert(0, new_wallet.classic_address)
ent_standby_seed.insert(0, new_wallet.seed) ent_standby_seed.insert(0, new_wallet.seed)
def get_standby_account_info(): def get_standby_account_info():
accountInfo = get_account_info(ent_standby_account.get()) accountInfo = get_account_info(ent_standby_account.get())
ent_standby_balance.delete(0, tk.END) ent_standby_balance.delete(0, tk.END)
ent_standby_balance.insert(0,accountInfo['Balance']) ent_standby_balance.insert(0,accountInfo['Balance'])
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0",json.dumps(accountInfo, indent=4)) text_standby_results.insert("1.0",json.dumps(accountInfo, indent=4))
def standby_send_xrp(): def standby_send_xrp():
response = send_xrp(ent_standby_seed.get(),ent_standby_amount.get(), response = send_xrp(ent_standby_seed.get(),ent_standby_amount.get(),
ent_standby_destination.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)) text_standby_results.insert("1.0",json.dumps(response.result, indent=4))
get_standby_account_info() get_standby_account_info()
get_operational_account_info() get_operational_account_info()
def get_operational_account(): def get_operational_account():
new_wallet = get_account(ent_operational_seed.get()) new_wallet = get_account(ent_operational_seed.get())
ent_operational_account.delete(0, tk.END) ent_operational_account.delete(0, tk.END)
ent_operational_account.insert(0, new_wallet.classic_address) ent_operational_account.insert(0, new_wallet.classic_address)
ent_operational_seed.delete(0, tk.END) ent_operational_seed.delete(0, tk.END)
ent_operational_seed.insert(0, new_wallet.seed) ent_operational_seed.insert(0, new_wallet.seed)
def get_operational_account_info(): def get_operational_account_info():
accountInfo = get_account_info(ent_operational_account.get()) accountInfo = get_account_info(ent_operational_account.get())
ent_operational_balance.delete(0, tk.END) ent_operational_balance.delete(0, tk.END)
ent_operational_balance.insert(0,accountInfo['Balance']) ent_operational_balance.insert(0,accountInfo['Balance'])
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0",json.dumps(accountInfo, indent=4)) text_operational_results.insert("1.0",json.dumps(accountInfo, indent=4))
def operational_send_xrp(): def operational_send_xrp():
response = send_xrp(ent_operational_seed.get(),ent_operational_amount.get(), ent_operational_destination.get()) 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.delete("1.0", tk.END)
@@ -410,6 +432,7 @@ def operational_send_xrp():
get_operational_account_info() get_operational_account_info()
# Create a new window with the title "Quickstart Module 2" # Create a new window with the title "Quickstart Module 2"
window = tk.Tk() window = tk.Tk()
window.title("Quickstart Module 2") 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) ent_standby_seed = tk.Entry(master=frm_form, width=50)
lbl_standby_account = tk.Label(master=frm_form, text="Standby Account") lbl_standby_account = tk.Label(master=frm_form, text="Standby Account")
ent_standby_account = tk.Entry(master=frm_form, width=50) 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") lbl_standy_amount = tk.Label(master=frm_form, text="Amount")
ent_standby_amount = tk.Entry(master=frm_form, width=50) ent_standby_amount = tk.Entry(master=frm_form, width=50)
lbl_standby_destination = tk.Label(master=frm_form, text="Destination") lbl_standby_destination = tk.Label(master=frm_form, text="Destination")
ent_standby_destination = tk.Entry(master=frm_form, width=50) 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. 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) ent_operational_seed = tk.Entry(master=frm_form, width=50)
lbl_operational_account = tk.Label(master=frm_form, text="Operational Account") lbl_operational_account = tk.Label(master=frm_form, text="Operational Account")
ent_operational_account = tk.Entry(master=frm_form, width=50) 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") lbl_operational_amount = tk.Label(master=frm_form, text="Amount")
ent_operational_amount = tk.Entry(master=frm_form, width=50) ent_operational_amount = tk.Entry(master=frm_form, width=50)
lbl_operational_destination = tk.Label(master=frm_form, text="Destination") lbl_operational_destination = tk.Label(master=frm_form, text="Destination")
ent_operational_destination = tk.Entry(master=frm_form, width=50) 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**. 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() cb_operational_allow_rippling.select()
``` ```
############################################# Create the Standby Account Buttons.
## Buttons ##################################
#############################################
# Create the Standby Account Buttons
```python ```python
btn_get_standby_account = tk.Button(master=frm_form, text="Get Standby Account", 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") btn_standby_configure_account.grid(row=7,column=0, sticky = "nsew")
``` ```
# Create the Operational Account Buttons Create the Operational Account buttons.
```python ```python
btn_get_operational_account = tk.Button(master=frm_form, btn_get_operational_account = tk.Button(master=frm_form,

View File

@@ -84,6 +84,8 @@ import xrpl
import json import json
from xrpl.clients import JsonRpcClient from xrpl.clients import JsonRpcClient
from xrpl.wallet import Wallet from xrpl.wallet import Wallet
from xrpl.models.requests import AccountNFTs
testnet_url = "https://s.altnet.rippletest.net:51234" 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. Pass the arguments account seed, NFT URI, transaction flags, the transfer fee, and optional taxon.
```python ```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. Get the account wallet and a client instance.
```python ```python
mint_wallet = Wallet(_seed, sequence = 16237283) mint_wallet=Wallet(seed, sequence=16237283)
client = JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
``` ```
Define the mint transaction. Note that the NFT URI must be converted to a hex string. Define the mint transaction. Note that the NFT URI must be converted to a hex string.
```python ```python
mint_tx = xrpl.models.transactions.NFTokenMint( mint_tx=xrpl.models.transactions.NFTokenMint(
account = mint_wallet.classic_address, account=mint_wallet.classic_address,
uri = xrpl.utils.str_to_hex(_uri), uri=xrpl.utils.str_to_hex(uri),
flags = int(_flags), flags=int(flags),
transfer_fee = int(_transfer_fee), transfer_fee=int(transfer_fee),
nftoken_taxon = int(_taxon) nftoken_taxon=int(taxon)
) )
``` ```
@@ -125,45 +127,40 @@ Sign and fill the transaction.
Submit the transaction and return results. Submit the transaction and return results.
```python ```python
reply=""
try: 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: except xrpl.transaction.XRPLReliableSubmissionException as e:
response = f"Submit failed: {e}" reply=f"Submit failed: {e}"
return response.result return reply
``` ```
## getTokens ## getTokens
```python ```python
def get_tokens(_account): def get_tokens(account):
``` """get_tokens"""
Import dependencies.
```python
from xrpl.clients import JsonRpcClient
from xrpl.models.requests import AccountNFTs
import json
``` ```
Instantiate a client. Instantiate a client.
```python ```python
client = JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
``` ```
Prepare the `AccountNFTs` request. Prepare the `AccountNFTs` request.
```python ```python
acct_nfts = AccountNFTs( acct_nfts=AccountNFTs(
account=_account account=account
) )
``` ```
Send the request and return the result. Send the request and return the result.
```python ```python
response = client.request(acct_nfts) response=client.request(acct_nfts)
return response.result return response.result
``` ```
@@ -172,40 +169,43 @@ Send the request and return the result.
Pass the owner's seed value and the NFT ID. Pass the owner's seed value and the NFT ID.
```python ```python
def burn_token(_seed, _nftoken_id): def burn_token(seed, nftoken_id):
"""burn_token"""
``` ```
Get the owner wallet and client instance. Get the owner wallet and client instance.
```python ```python
owner_wallet = Wallet(_seed, sequence = 16237283) owner_wallet=Wallet(seed, sequence=16237283)
client = JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
``` ```
Define the NFTokenBurn transaction. Define the NFTokenBurn transaction.
```python ```python
burn_tx = xrpl.models.transactions.NFTokenBurn( burn_tx=xrpl.models.transactions.NFTokenBurn(
account = owner_wallet.classic_address, account=owner_wallet.classic_address,
nftoken_id = _nftoken_id nftoken_id=nftoken_id
) )
``` ```
Sign and fill the transaction. Sign and fill the transaction.
```python ```python
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction( signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
burn_tx, owner_wallet, client) burn_tx, owner_wallet, client)
``` ```
Submit the transaction and return results. Submit the transaction and return results.
```python ```python
reply=""
try: 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: except xrpl.transaction.XRPLReliableSubmissionException as e:
response = f"Submit failed: {e}" reply=f"Submit failed: {e}"
return response.result return reply
``` ```
@@ -218,23 +218,27 @@ This module builds on `lesson2-create-trustline-send-currency.py`. Changes are n
import tkinter as tk import tkinter as tk
import xrpl import xrpl
import json 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`. Import methods from `mod3.py`.
```python ```python
from mod3 import mint_token from mod3 import (
from mod3 import get_tokens mint_token,
from mod3 import burn_token get_tokens,
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 ################################# ## Handlers #################################
@@ -254,10 +258,14 @@ def standby_mint_token():
) )
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4)) text_standby_results.insert("1.0", json.dumps(results, indent=4))
def standby_get_tokens(): def standby_get_tokens():
results = get_tokens(ent_standby_account.get()) results = get_tokens(ent_standby_account.get())
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4)) text_standby_results.insert("1.0", json.dumps(results, indent=4))
def standby_burn_token(): def standby_burn_token():
results = burn_token( results = burn_token(
ent_standby_seed.get(), ent_standby_seed.get(),
@@ -265,6 +273,8 @@ def standby_burn_token():
) )
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4)) text_standby_results.insert("1.0", json.dumps(results, indent=4))
def operational_mint_token(): def operational_mint_token():
results = mint_token( results = mint_token(
ent_operational_seed.get(), ent_operational_seed.get(),
@@ -275,10 +285,14 @@ def operational_mint_token():
) )
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4)) text_operational_results.insert("1.0", json.dumps(results, indent=4))
def operational_get_tokens(): def operational_get_tokens():
results = get_tokens(ent_operational_account.get()) results = get_tokens(ent_operational_account.get())
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4)) text_operational_results.insert("1.0", json.dumps(results, indent=4))
def operational_burn_token(): def operational_burn_token():
results = burn_token( results = burn_token(
ent_operational_seed.get(), ent_operational_seed.get(),
@@ -287,15 +301,18 @@ def operational_burn_token():
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4)) text_operational_results.insert("1.0", json.dumps(results, indent=4))
# Module 2 Handlers # Module 2 Handlers
def standby_create_trustline(): def standby_create_trust_line():
results = create_trustline(ent_standby_seed.get(), results = create_trust_line(ent_standby_seed.get(),
ent_standby_destination.get(), ent_standby_destination.get(),
ent_standby_currency.get(), ent_standby_currency.get(),
ent_standby_amount.get()) ent_standby_amount.get())
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4)) text_standby_results.insert("1.0", json.dumps(results, indent=4))
def standby_send_currency(): def standby_send_currency():
results = send_currency(ent_standby_seed.get(), results = send_currency(ent_standby_seed.get(),
ent_standby_destination.get(), ent_standby_destination.get(),
@@ -303,12 +320,16 @@ def standby_send_currency():
ent_standby_amount.get()) ent_standby_amount.get())
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4)) text_standby_results.insert("1.0", json.dumps(results, indent=4))
def standby_configure_account(): def standby_configure_account():
results = configure_account( results = configure_account(
ent_standby_seed.get(), ent_standby_seed.get(),
standbyRippling) standbyRippling)
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0", json.dumps(results, indent=4)) text_standby_results.insert("1.0", json.dumps(results, indent=4))
def operational_create_trust_line(): def operational_create_trust_line():
results = create_trust_line(ent_operational_seed.get(), results = create_trust_line(ent_operational_seed.get(),
ent_operational_destination.get(), ent_operational_destination.get(),
@@ -316,6 +337,8 @@ def operational_create_trust_line():
ent_operational_amount.get()) ent_operational_amount.get())
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4)) text_operational_results.insert("1.0", json.dumps(results, indent=4))
def operational_send_currency(): def operational_send_currency():
results = send_currency(ent_operational_seed.get(), results = send_currency(ent_operational_seed.get(),
ent_operational_destination.get(), ent_operational_destination.get(),
@@ -323,12 +346,16 @@ def operational_send_currency():
ent_operational_amount.get()) ent_operational_amount.get())
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4)) text_operational_results.insert("1.0", json.dumps(results, indent=4))
def operational_configure_account(): def operational_configure_account():
results = configure_account( results = configure_account(
ent_operational_seed.get(), ent_operational_seed.get(),
operationalRippling) operationalRippling)
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0", json.dumps(results, indent=4)) text_operational_results.insert("1.0", json.dumps(results, indent=4))
def get_balances(): def get_balances():
results = get_balance(ent_operational_account.get(), ent_standby_account.get()) results = get_balance(ent_operational_account.get(), ent_standby_account.get())
text_standby_results.delete("1.0", tk.END) 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_seed.delete(0, tk.END)
ent_standby_account.insert(0, new_wallet.classic_address) ent_standby_account.insert(0, new_wallet.classic_address)
ent_standby_seed.insert(0, new_wallet.seed) ent_standby_seed.insert(0, new_wallet.seed)
def get_standby_account_info(): def get_standby_account_info():
accountInfo = get_account_info(ent_standby_account.get()) accountInfo = get_account_info(ent_standby_account.get())
ent_standby_balance.delete(0, tk.END) ent_standby_balance.delete(0, tk.END)
ent_standby_balance.insert(0,accountInfo['Balance']) ent_standby_balance.insert(0,accountInfo['Balance'])
text_standby_results.delete("1.0", tk.END) text_standby_results.delete("1.0", tk.END)
text_standby_results.insert("1.0",json.dumps(accountInfo, indent=4)) text_standby_results.insert("1.0",json.dumps(accountInfo, indent=4))
def standby_send_xrp(): def standby_send_xrp():
response = send_xrp(ent_standby_seed.get(),ent_standby_amount.get(), response = send_xrp(ent_standby_seed.get(),ent_standby_amount.get(),
ent_standby_destination.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)) text_standby_results.insert("1.0",json.dumps(response.result, indent=4))
get_standby_account_info() get_standby_account_info()
get_operational_account_info() get_operational_account_info()
def get_operational_account(): def get_operational_account():
new_wallet = get_account(ent_operational_seed.get()) new_wallet = get_account(ent_operational_seed.get())
ent_operational_account.delete(0, tk.END) ent_operational_account.delete(0, tk.END)
ent_operational_account.insert(0, new_wallet.classic_address) ent_operational_account.insert(0, new_wallet.classic_address)
ent_operational_seed.delete(0, tk.END) ent_operational_seed.delete(0, tk.END)
ent_operational_seed.insert(0, new_wallet.seed) ent_operational_seed.insert(0, new_wallet.seed)
def get_operational_account_info(): def get_operational_account_info():
accountInfo = get_account_info(ent_operational_account.get()) accountInfo = get_account_info(ent_operational_account.get())
ent_operational_balance.delete(0, tk.END) ent_operational_balance.delete(0, tk.END)
ent_operational_balance.insert(0,accountInfo['Balance']) ent_operational_balance.insert(0,accountInfo['Balance'])
text_operational_results.delete("1.0", tk.END) text_operational_results.delete("1.0", tk.END)
text_operational_results.insert("1.0",json.dumps(accountInfo, indent=4)) text_operational_results.insert("1.0",json.dumps(accountInfo, indent=4))
def operational_send_xrp(): def operational_send_xrp():
response = send_xrp(ent_operational_seed.get(),ent_operational_amount.get(), ent_operational_destination.get()) 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.delete("1.0", tk.END)
text_operational_results.insert("1.0",json.dumps(response.result,indent=4)) text_operational_results.insert("1.0",json.dumps(response.result,indent=4))
get_standby_account_info() get_standby_account_info()
get_operational_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 = tk.Tk()
window.title("Quickstart Module 3") window.title("Quickstart Module 3")
@@ -388,22 +428,22 @@ frm_form = tk.Frame(relief=tk.SUNKEN, borderwidth=3)
frm_form.pack() frm_form.pack()
# Create the Label and Entry widgets for "Standby Account" # Create the Label and Entry widgets for "Standby Account"
lbl_standy_seed = tk.Label(master=frm_form, text="Standby Seed") lbl_operational_seed = tk.Label(master=frm_form, text="Operational Seed")
ent_standby_seed = tk.Entry(master=frm_form, width=50) ent_operational_seed = tk.Entry(master=frm_form, width=50)
lbl_standby_account = tk.Label(master=frm_form, text="Standby Account") lbl_operational_account = tk.Label(master=frm_form, text="Operational Account")
ent_standby_account = tk.Entry(master=frm_form, width=50) ent_operational_account = tk.Entry(master=frm_form, width=50)
lbl_standby_balance = tk.Label(master=frm_form, text="XRP Balance") lbl_operational_amount = tk.Label(master=frm_form, text="Amount")
ent_standby_balance = tk.Entry(master=frm_form, width=50) ent_operational_amount = tk.Entry(master=frm_form, width=50)
lbl_standy_amount = tk.Label(master=frm_form, text="Amount") lbl_operational_destination = tk.Label(master=frm_form, text="Destination")
ent_standby_amount = tk.Entry(master=frm_form, width=50) ent_operational_destination = tk.Entry(master=frm_form, width=50)
lbl_standby_destination = tk.Label(master=frm_form, text="Destination") lbl_operational_balance = tk.Label(master=frm_form, text="XRP Balance")
ent_standby_destination = tk.Entry(master=frm_form, width=50) ent_operational_balance = tk.Entry(master=frm_form, width=50)
lbl_standby_currency = tk.Label(master=frm_form, text="Currency") lbl_operational_currency = tk.Label(master=frm_form, text="Currency")
ent_standby_currency = tk.Entry(master=frm_form, width=50) 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) 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 ```python
lbl_standby_uri = tk.Label(master=frm_form, text="NFT URI") 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) ent_operational_seed = tk.Entry(master=frm_form, width=50)
lbl_operational_account = tk.Label(master=frm_form, text="Operational Account") lbl_operational_account = tk.Label(master=frm_form, text="Operational Account")
ent_operational_account = tk.Entry(master=frm_form, width=50) 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") lbl_operational_amount = tk.Label(master=frm_form, text="Amount")
ent_operational_amount = tk.Entry(master=frm_form, width=50) ent_operational_amount = tk.Entry(master=frm_form, width=50)
lbl_operational_destination = tk.Label(master=frm_form, text="Destination") lbl_operational_destination = tk.Label(master=frm_form, text="Destination")
ent_operational_destination = tk.Entry(master=frm_form, width=50) 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") lbl_operational_currency = tk.Label(master=frm_form, text="Currency")
ent_operational_currency = tk.Entry(master=frm_form, width=50) 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) cb_operational_allow_rippling = tk.Checkbutton(master=frm_form, text="Allow Rippling", variable=operationalRippling, onvalue=True, offvalue=False)

View File

@@ -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). Pass the arguments _seed_, _amount_, _NFT ID_, _expiration_ (in seconds, optional), and _destination_ (optional).
```python ```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. Get the owner wallet and create a client connection.
```python ```python
owner_wallet = Wallet(_seed, sequence = 16237283) owner_wallet = Wallet(seed, sequence=16237283)
client = JsonRpcClient(testnet_url) client = JsonRpcClient(testnet_url)
``` ```
@@ -159,58 +160,60 @@ If there is an expiration value, convert the current date and time to Ripple tim
```python ```python
expiration_date = datetime.now() expiration_date = datetime.now()
if (_expiration != ''): if expiration != '':
expiration_date = xrpl.utils.datetime_to_ripple_time(expiration_date) 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. Define the sell offer transaction.
```python ```python
sell_offer_tx = xrpl.models.transactions.NFTokenCreateOffer( sell_offer_tx=xrpl.models.transactions.NFTokenCreateOffer(
account = owner_wallet.classic_address, account=owner_wallet.classic_address,
nftoken_id = _nft_id, nftoken_id=nftoken_id,
amount = _amount, amount=amount,
``` ```
If the sale is designated for a specific destination account, include the `destination` argument. If the sale is designated for a specific destination account, include the `destination` argument.
```python ```python
destination=_destination if _destination != '' else None, destination=destination if destination != '' else None,
``` ```
If the expiration date is present, include the `expiration` argument. If the expiration date is present, include the `expiration` argument.
```python ```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. Set the `flags` value to _1_, indicating that this is a sell offer.
```python ```python
flags = 1 flags=1
) )
``` ```
Sign the transaction. Sign the transaction.
```python ```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) sell_offer_tx, owner_wallet, client)
``` ```
Submit the transaction. Submit the transaction.
```python ```python
reply=""
try: 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: except xrpl.transaction.XRPLReliableSubmissionException as e:
response = f"Submit failed: {e}" reply=f"Submit failed: {e}"
``` ```
Return the result. Return the result.
```python ```python
return response.result return reply
``` ```
## Accept Sell Offer ## Accept Sell Offer
@@ -218,40 +221,43 @@ Return the result.
Pass the buyer's seed value and the NFT sell offer index. Pass the buyer's seed value and the NFT sell offer index.
```python ```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. Get the wallet and a client instance.
```python ```python
buyer_wallet = Wallet(_seed, sequence = 16237283) buyer_wallet=Wallet(seed, sequence=16237283)
client = JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
``` ```
Define the accept offer transaction Define the accept offer transaction
```python ```python
accept_offer_tx = xrpl.models.transactions.NFTokenAcceptOffer( accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer(
account = buyer_wallet.classic_address, account=buyer_wallet.classic_address,
nftoken_sell_offer = _offer_index nftoken_sell_offer=offer_index
) )
``` ```
Sign and fill the transaction. Sign and fill the transaction.
```python ```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) accept_offer_tx, buyer_wallet, client)
``` ```
Submit the transaction and report the results. Submit the transaction and report the results.
```python ```python
reply=""
try: 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: except xrpl.transaction.XRPLReliableSubmissionException as e:
response = f"Submit failed: {e}" reply=f"Submit failed: {e}"
return response.result return reply
``` ```
## Create Buy Offer ## 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). Pass the buyer _seed_, _amount_, _NFT ID_, _owner_, _expiration_ (in seconds, optional), and _destination_ account (optional).
```python ```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. Get the buyer wallet and a client instance.
```python ```python
buyer_wallet = Wallet(_seed, sequence = 16237283) buyer_wallet=Wallet(seed, sequence=16237283)
client = JsonRpcClient(testnet_url) 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. If the _expiration_ value is present, get the current date and time, convert it to Ripple time, and add the _expiration_ value.
```python ```python
expiration_date = datetime.now() expiration_date=datetime.now()
if (_expiration != ''): if (expiration!=''):
expiration_date = xrpl.utils.datetime_to_ripple_time(expiration_date) expiration_date=xrpl.utils.datetime_to_ripple_time(expiration_date)
expiration_date = expiration_date + int(_expiration) expiration_date=expiration_date + int(expiration)
``` ```
Define the buy offer transaction. Define the buy offer transaction.
```python ```python
buy_offer_tx = xrpl.models.transactions.NFTokenCreateOffer( buy_offer_tx=xrpl.models.transactions.NFTokenCreateOffer(
account = buyer_wallet.classic_address, account=buyer_wallet.classic_address,
nftoken_id = _nft_id, nftoken_id=nft_id,
amount = _amount, amount=amount,
owner = _owner, owner=owner,
``` ```
IF the _expiration_ value is present, include the _expiration_ argument. IF the _expiration_ value is present, include the _expiration_ argument.
```python ```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. If the _destination_ value is present, include the _destination_ argument.
```python ```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. Set the _flags_ value to _0_, indicating that this is a "buy" offer.
```python ```python
flags = 0 flags=0
) )
``` ```
Sign and fill the transaction. Sign and fill the transaction.
```python ```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) buy_offer_tx, buyer_wallet, client)
``` ```
Submit the transaction and report the results. Submit the transaction and report the results.
```python ```python
reply=""
try: 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: except xrpl.transaction.XRPLReliableSubmissionException as e:
response = f"Submit failed: {e}" reply=f"Submit failed: {e}"
return response.result return reply
``` ```
## Accept Buy Offer ## 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_. Pass the buyer's _seed_ value and the NFT _offer___index_.
```python ```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. Get the buyer wallet and a client instance.
```python ```python
buyer_wallet = Wallet(_seed, sequence = 16237283) buyer_wallet=Wallet(seed, sequence=16237283)
client = JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
``` ```
Define the accept offer transaction. Define the accept offer transaction.
```python ```python
accept_offer_tx = xrpl.models.transactions.NFTokenAcceptOffer( accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer(
account = buyer_wallet.classic_address, account=buyer_wallet.classic_address,
nftoken_buy_offer = _offer_index nftoken_buy_offer=offer_index
) )
``` ```
Sign and fill the transaction. Sign and fill the transaction.
```python ```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) accept_offer_tx, buyer_wallet, client)
``` ```
Submit the transaction and report the results Submit the transaction and report the results
```python ```python
reply=""
try: 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: except xrpl.transaction.XRPLReliableSubmissionException as e:
response = f"Submit failed: {e}" reply=f"Submit failed: {e}"
return response.result return reply
``` ```
## Get Offers ## 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_. Pass the _NFT ID_.
```python ```python
def get_offers(_nft_id): def get_offers(nft_id):
"""get_offers"""
``` ```
Create a client instance. Create a client instance.
```python ```python
client = JsonRpcClient(testnet_url) client=JsonRpcClient(testnet_url)
``` ```
Define the request for buy offers. Define the request for buy offers.
```python ```python
offers = NFTBuyOffers( offers=NFTBuyOffers(
nft_id=_nft_id nft_id=nft_id
)
```
Send the request and capture the response.
```python
response = client.request(offers)
```
Create the _allOffers_ variable to accumulate the offer responses.
```python
allOffers = "Buy Offers:\n" + json.dumps(response.result, indent=4)
```
Define the request for sell offers.
```python
offers = NFTSellOffers(
nft_id=_nft_id
) )
``` ```
Send the request and capture the response. Send the request and capture the response.
```python ```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)
```
Define the request for sell offers.
```python
offers=NFTSellOffers(
nft_id=nft_id
)
```
Send the request and capture the response.
```python
response=client.request(offers)
``` ```
Add the response to the _allOffers_ variable and return the results. Add the response to the _allOffers_ variable and return the results.
```python ```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 return allOffers
``` ```
@@ -429,29 +442,31 @@ 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. Pass the seed and the NFT Offer ID to be canceled.
```python ```python
def cancel_offer(_seed, _nft_offer_ids): def cancel_offer(seed, nftoken_offer_ids):
"""cancel_offer"""
``` ```
Get the wallet and a client instance. Get the wallet and a client instance.
```python ```python
owner_wallet = Wallet(_seed, sequence = 16237283) owner_wallet=Wallet(seed, sequence=16237283)
client = JsonRpcClient(testnet_url) 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. 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 ```python
tokenOfferIDs = [_nft_offer_ids] tokenOfferIDs=[nftoken_offer_ids]
``` ```
Define the cancel offer transaction. Define the cancel offer transaction.
```python ```python
cancel_offer_tx = xrpl.models.transactions.NFTokenCancelOffer( nftSellOffers="No sell offers"
account = owner_wallet.classic_address, cancel_offer_tx=xrpl.models.transactions.NFTokenCancelOffer(
nftoken_offers = tokenOfferIDs account=owner_wallet.classic_address,
) nftoken_offers=tokenOfferIDs
)
``` ```
Sign the transaction. Sign the transaction.
@@ -464,11 +479,13 @@ Sign the transaction.
Submit the transaction and return the result. Submit the transaction and return the result.
```python ```python
reply=""
try: 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: except xrpl.transaction.XRPLReliableSubmissionException as e:
response = f"Submit failed: {e}" reply=f"Submit failed: {e}"
return response.result return reply
``` ```
## lesson4-transfer-tokens.py ## 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 tkinter as tk
import xrpl import xrpl
import json 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`. Import new methods from `mod4.py`.
```python ```python
from mod4 import create_sell_offer from mod4 import (
from mod4 import create_buy_offer create_sell_offer,
from mod4 import get_offers create_buy_offer,
from mod4 import cancel_offer get_offers,
from mod4 import accept_sell_offer cancel_offer,
from mod4 import accept_buy_offer accept_sell_offer,
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 #################################
#############################################
``` ```
@@ -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) ent_standby_seed = tk.Entry(master=frm_form, width=50)
lbl_standby_account = tk.Label(master=frm_form, text="Standby Account") lbl_standby_account = tk.Label(master=frm_form, text="Standby Account")
ent_standby_account = tk.Entry(master=frm_form, width=50) 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") lbl_standy_amount = tk.Label(master=frm_form, text="Amount")
ent_standby_amount = tk.Entry(master=frm_form, width=50) ent_standby_amount = tk.Entry(master=frm_form, width=50)
lbl_standby_destination = tk.Label(master=frm_form, text="Destination") lbl_standby_destination = tk.Label(master=frm_form, text="Destination")
ent_standby_destination = tk.Entry(master=frm_form, width=50) 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") lbl_standby_currency = tk.Label(master=frm_form, text="Currency")
ent_standby_currency = tk.Entry(master=frm_form, width=50) 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) 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) ent_operational_seed = tk.Entry(master=frm_form, width=50)
lbl_operational_account = tk.Label(master=frm_form, text="Operational Account") lbl_operational_account = tk.Label(master=frm_form, text="Operational Account")
ent_operational_account = tk.Entry(master=frm_form, width=50) 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") lbl_operational_amount = tk.Label(master=frm_form, text="Amount")
ent_operational_amount = tk.Entry(master=frm_form, width=50) ent_operational_amount = tk.Entry(master=frm_form, width=50)
lbl_operational_destination = tk.Label(master=frm_form, text="Destination") lbl_operational_destination = tk.Label(master=frm_form, text="Destination")
ent_operational_destination = tk.Entry(master=frm_form, width=50) 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") lbl_operational_currency = tk.Label(master=frm_form, text="Currency")
ent_operational_currency = tk.Entry(master=frm_form, width=50) 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) cb_operational_allow_rippling = tk.Checkbutton(master=frm_form, text="Allow Rippling", variable=operationalRippling, onvalue=True, offvalue=False)