updated sample app per teting and feedback

This commit is contained in:
Ryan G. Young
2021-03-19 16:56:58 -07:00
parent 66fd6f8b38
commit 7f32f1943e

View File

@@ -1,26 +1,72 @@
import xrpl import xrpl
from xrpl.models import Wallet
from xrpl.models.transactions.transaction import Transaction, TransactionType # Core modules to
# To generate keypairs and encode addresses
from xrpl.core import keypairs
from xrpl.core.addresscodec.main import classic_address_to_xaddress
# Network client
from xrpl.clients.json_rpc_client import JsonRpcClient
# To create test wallets
from xrpl.wallet import generate_faucet_wallet
# Request models
from xrpl.models.requests.account_info import AccountInfo
# Wallet models
from xrpl.wallet import Wallet
# Transaction models
from xrpl.models.transactions.transaction import Transaction, TransactionType, AccountSet, Payment
from xrpl.models.transactions import AccountSet
from xrpl.transaction import (
LastLedgerSequenceExpiredException,
)
from xrpl.transaction.main import (
safe_sign_and_submit_transaction,
safe_sign_transaction,
submit_transaction_blob,
transaction_json_to_binary_codec_form,
)
from xrpl.transaction.reliable_submission import send_reliable_submission
# Account models
from xrpl.account import get_next_valid_seq_number
# Define the URL of the server you want to use
JSON_RPC_URL = "http://s1.ripple.com:51234/"
# Define the accounts you're going to use
CLASSIC_ACCOUNT = ""
SENDER_ACCOUNT = "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe"
address = ""
DESTINATION_WALLET = generate_faucet_wallet(JSON_RPC_URL).classic_address
# You can create a wallet using the testnet faucet: #JSON handling
import json
# Define the network client
JSON_RPC_URL_TESTNET = "https://s.altnet.rippletest.net:51234/"
JSON_RPC_CLIENT_TESTNET = JsonRpcClient(JSON_RPC_URL_TESTNET)
JSON_RPC_URL_DEVNET = "https://s.devnet.rippletest.net:51234/"
JSON_RPC_CLIENT_DEVNET = JsonRpcClient(JSON_RPC_URL_DEVNET)
# Create wallets using the testnet faucet:
# https://xrpl.org/xrp-testnet-faucet.html # https://xrpl.org/xrp-testnet-faucet.html
# with the generate_faucet_wallet function TESTNET_WALLET = generate_faucet_wallet(JSON_RPC_CLIENT_TESTNET)
TESTNET_ACCOUNT = generate_faucet_wallet(JSON_RPC_CLIENT).classic_address TESTNET_CLASSIC_ACCOUNT = TESTNET_WALLET.classic_address
DEVNET_WALLET = generate_faucet_wallet(JSON_RPC_CLIENT_DEVNET)
DEVNET_CLASSIC_ACCOUNT = DEVNET_WALLET.classic_address
# Define the receiver accounts
TESTNET_DESTINATION_WALLET = generate_faucet_wallet(JSON_RPC_CLIENT_TESTNET)
TESTNET_DESTINATION_ACCOUNT = TESTNET_DESTINATION_WALLET.classic_address
# Define variables to use for transactions # Define variables to use for transactions
_ACCOUNT = "r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ" _ACCOUNT = "r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ"
_FEE = "0.00001" _FEE = "10"
_SEQUENCE = 19048 _SEQUENCE = 19048
SET_FLAG = 8
MEMO = "I built this with xrpl-py!"
# Secrets to use for signing transactions # Secrets to use for signing transactions
_SECRET = "randomsecretkey" _SECRET = "randomsecretkey"
@@ -31,11 +77,11 @@ _PASSPHRASE = "mytopsecretpassphrasethatwillneverbehacked"
# Create an XRP Ledger wallet # Create an XRP Ledger wallet
# And create an x-address for the address # And create an x-address for the address
def createWallet(): def create_wallet():
wallet = Wallet.generate_seed_and_wallet() TESTNET_WALLET = generate_faucet_wallet(JSON_RPC_CLIENT_TESTNET)
address = wallet.classic_address wallet2_address = wallet2.classic_address
xaddress = addresscodec.classic_address_to_xaddress( xaddress = addresscodec.classic_address_to_xaddress(
classic_address, tag, True wallet2_address, tag, True
) )
print("Classic address:", address) print("Classic address:", address)
print("X-address:", xaddress) print("X-address:", xaddress)
@@ -44,7 +90,7 @@ def createWallet():
# Optionally generate private and public keys # Optionally generate private and public keys
# to manage your XRP Ledger account # to manage your XRP Ledger account
def generateKeys(): def generate_keys():
seed = keypairs.generate_seed() seed = keypairs.generate_seed()
public, private = keypairs.derive_keypair(seed) public, private = keypairs.derive_keypair(seed)
CLASSIC_ACCOUNT = keypairs.derive_classic_address(public) CLASSIC_ACCOUNT = keypairs.derive_classic_address(public)
@@ -52,32 +98,40 @@ def generateKeys():
print("Here's the private key: ", private) print("Here's the private key: ", private)
# Look up information about your account # Look up information about your account
def getAcctInfo(): def get_acct_info():
client = JsonRpcClient(JSON_RPC_URL) client = JsonRpcClient(JSON_RPC_URL)
acct_info = AccountInfo( acct_info = AccountInfo(
account=address, account=wallet,
ledger_index="current", ledger_index="current",
queue=True, queue=True,
strict=True, strict=True,
) )
response = client.request(acct_info) response = JSON_RPC_CLIENT_TESTNET.request(acct_info)
print("response.status: ", response.status) print("response.status: ", response.status)
print("response.result: ", response.result) print("response.result: ", response.result)
print("response.id: ", response.id) print("response.id: ", response.id)
print("response.type: ", response.type) print("response.type: ", response.type)
print("response.result.account_data.Balance", response.result.account_data.Balance)
for key, value in response.result():
print(key, value)
for k, v in value.result():
print(k,v)
# Prepare the tx by formatting it into # Prepare the tx by formatting it into
# the shape expected by the XRP Ledger # the shape expected by the XRP Ledger
# and signing it # and signing it
def prepareSignSubmitTx(): def prepare_sign_submit_tx():
CLASSIC_ACCOUNT.next_sequence_num = get_next_valid_seq_number(CLASSIC_ACCOUNT, JSON_RPC_CLIENT) TESTNET_WALLET.next_sequence_num = get_next_valid_seq_number(TESTNET_CLASSIC_ACCOUNT, JSON_RPC_CLIENT_TESTNET)
tx = Transaction( account_set = AccountSet(
account=_ACCOUNT, account=TESTNET_CLASSIC_ACCOUNT,
fee=_FEE, fee=_FEE,
sequence=CLASSIC_ACCOUNT.next_seuqnece_num + 10, sequence=TESTNET_WALLET.next_sequence_num,
transaction_type=TransactionType. set_flag=SET_FLAG,
) )
value = tx.to_dict()["payment_trannsaction"] response = safe_sign_and_submit_transaction(account_set, TESTNET_WALLET, JSON_RPC_CLIENT_TESTNET)
value = tx.to_dict()[]
signed_tx = Sign( signed_tx = Sign(
transaction=value, transaction=value,
seed=_SEED, seed=_SEED,