This commit is contained in:
Wo Jake
2022-09-05 11:20:06 +00:00
committed by GitHub
parent 0fc587e777
commit 828f7e282f

View File

@@ -1,16 +1,13 @@
from xrpl.clients import JsonRpcClient from xrpl.clients import JsonRpcClient
from xrpl.models.transactions import TicketCreate, AccountSet from xrpl.models.transactions import TicketCreate, AccountSet
from xrpl.account import get_next_valid_seq_number
from xrpl.transaction import safe_sign_and_submit_transaction from xrpl.transaction import safe_sign_and_submit_transaction
from xrpl.core import keypairs
from xrpl.wallet import Wallet from xrpl.wallet import Wallet
from xrpl.models.requests.account_info import AccountInfo from xrpl.models.requests.account_objects import AccountObjects, AccountObjectType
myAddr = "rfaNymVS1fEREj4FpNroXVEcVVMph6k2Mt" myAddr = "rLugkhsRxNHroDVJ29anq9UoTcNQdDjXCR"
mySeed = "ss3GZzmyEBxvwB3LUvsqfa-------" mySeed = "sARIIQ06xLZulXC1MBeE---------"
# Derive and initialize wallet # Derive and initialize wallet
public, private = keypairs.derive_keypair(mySeed)
wallet_from_seed = Wallet(mySeed, 0) wallet_from_seed = Wallet(mySeed, 0)
# Connect to a testnet node # Connect to a testnet node
@@ -20,23 +17,20 @@ client = JsonRpcClient(JSON_RPC_URL)
# Construct a TicketCreate transaction, 1 ticket created for future use # Construct a TicketCreate transaction, 1 ticket created for future use
tx = TicketCreate( tx = TicketCreate(
account=myAddr, account=myAddr,
fee="10", ticket_count=1
ticket_count=1,
sequence=get_next_valid_seq_number(address=myAddr, client=client)
) )
# Sign transaction locally and submit # Sign transaction locally and submit
my_tx_payment_signed = safe_sign_and_submit_transaction(transaction=tx, wallet=wallet_from_seed, client=client) my_tx_payment_signed = safe_sign_and_submit_transaction(transaction=tx, wallet=wallet_from_seed, client=client)
# Get ticket Sequence # Get a Ticket Sequence
get_ticket = AccountInfo( get_ticket_sequence = AccountObjects(
account=myAddr, account=myAddr,
ledger_index="current", type=AccountObjectType.TICKET
strict=True
) )
response = client.request(get_ticket) response = client.request(get_ticket_sequence)
ticket_sequence = response.result["account_data"]["Sequence"]-1 ticket_sequence = response.result["account_objects"][0]["TicketSequence"]
# Construct Transaction using a Ticket # Construct Transaction using a Ticket
tx_1 = AccountSet( tx_1 = AccountSet(
@@ -48,8 +42,8 @@ tx_1 = AccountSet(
) )
# Send transaction (w/ Ticket) # Send transaction (w/ Ticket)
result = safe_sign_and_submit_transaction(transaction=tx_1, client=client, wallet=wallet_from_seed) tx_result = safe_sign_and_submit_transaction(transaction=tx_1, client=client, wallet=wallet_from_seed)
result = result.result["engine_result"] result = tx_result.result["engine_result"]
if result == "tesSUCCESS": if result == "tesSUCCESS":
print("Transaction successful!") print("Transaction successful!")