mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-21 04:05:49 +00:00
revise sample app and tutorial
This commit is contained in:
@@ -1,25 +1,12 @@
|
||||
import xrpl
|
||||
|
||||
# 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.models.transactions.transaction import Transaction, TransactionType, Memo
|
||||
from xrpl.models.transactions import AccountSet, Payment
|
||||
from xrpl.transaction import (
|
||||
LastLedgerSequenceExpiredException,
|
||||
)
|
||||
@@ -30,14 +17,7 @@ from xrpl.transaction.main import (
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
#JSON handling
|
||||
import json
|
||||
|
||||
# Define the network client
|
||||
@@ -63,30 +43,37 @@ TESTNET_DESTINATION_ACCOUNT = TESTNET_DESTINATION_WALLET.classic_address
|
||||
|
||||
# Define variables to use for transactions
|
||||
_ACCOUNT = "r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ"
|
||||
_AMOUNT = "20"
|
||||
_FEE = "10"
|
||||
_MEMO = "I sent this with xrpl-py!"
|
||||
_SEQUENCE = 19048
|
||||
SET_FLAG = 8
|
||||
MEMO = "I built this with xrpl-py!"
|
||||
|
||||
# Secrets to use for signing transactions
|
||||
_SECRET = "randomsecretkey"
|
||||
_SEED = "randomsecretseedforakey"
|
||||
_SECRET = ""
|
||||
_SEED = ""
|
||||
_SEED_HEX = "EACEB081770D8ADE216C85445DD6FB002C6B5A2930F2DECE006DA18150CB18F6"
|
||||
_PASSPHRASE = "mytopsecretpassphrasethatwillneverbehacked"
|
||||
|
||||
|
||||
# Create an XRP Ledger wallet
|
||||
# And create an x-address for the address
|
||||
def create_wallet():
|
||||
# Create an XRP Ledger wallet from the
|
||||
# testnet faucet and derive an
|
||||
# x-address for the address
|
||||
def create_wallet_from_faucet():
|
||||
TESTNET_WALLET = generate_faucet_wallet(JSON_RPC_CLIENT_TESTNET)
|
||||
wallet2_address = wallet2.classic_address
|
||||
wallet_classic_address = TESTNET_WALLET.classic_address
|
||||
xaddress = addresscodec.classic_address_to_xaddress(
|
||||
wallet2_address, tag, True
|
||||
)
|
||||
print("Classic address:", address)
|
||||
print("X-address:", xaddress)
|
||||
|
||||
print("\nClassic address:\n\n", wallet_classic_address)
|
||||
print("X-address:\n\n", xaddress)
|
||||
|
||||
# Create an XRP Ledger wallet from
|
||||
# a generated seed
|
||||
def create_wallet_from_seed():
|
||||
seed = keypairs.generate_seed()
|
||||
wallet_from_seed = xrpl.wallet.Wallet(seed)
|
||||
print(wallet_from_seed)
|
||||
|
||||
# Optionally generate private and public keys
|
||||
# to manage your XRP Ledger account
|
||||
@@ -94,12 +81,12 @@ def generate_keys():
|
||||
seed = keypairs.generate_seed()
|
||||
public, private = keypairs.derive_keypair(seed)
|
||||
CLASSIC_ACCOUNT = keypairs.derive_classic_address(public)
|
||||
print("Here's the public key: ", public + "Store this in a secure place.")
|
||||
print("Here's the private key: ", private)
|
||||
print(f"Here's the public key:\n", public)
|
||||
print(f"Here's the private key:\n", private + "\nStore this in a secure place.")
|
||||
|
||||
# Look up information about your account
|
||||
def get_acct_info():
|
||||
client = JsonRpcClient(JSON_RPC_URL)
|
||||
client = JsonRpcClient(JSON_RPC_URL_TESTNET)
|
||||
acct_info = AccountInfo(
|
||||
account=wallet,
|
||||
ledger_index="current",
|
||||
@@ -112,12 +99,30 @@ def get_acct_info():
|
||||
print("response.id: ", response.id)
|
||||
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)
|
||||
|
||||
|
||||
# FUTURE Prepare tx
|
||||
def prepare_tx_future():
|
||||
my_tx_future = Transaction.from_xrpl(
|
||||
{
|
||||
"TransactionType": "Payment",
|
||||
"Amount": "50",
|
||||
"Destination": "rNZz9HS8mmKqb3jGk28PjNMkkRXRzGdTda",
|
||||
"Account": "rKQxjvLW67ZkMQdu9wmy73vhrbPcir21SV"
|
||||
}
|
||||
)
|
||||
TESTNET_WALLET.next_sequence_num = get_next_valid_seq_number(TESTNET_CLASSIC_ACCOUNT, JSON_RPC_CLIENT_TESTNET)
|
||||
|
||||
# CURRENT Prepare tx
|
||||
def prepare_tx_current():
|
||||
my_tx_current = Payment(
|
||||
account=TESTNET_CLASSIC_ACCOUNT,
|
||||
amount=_AMOUNT,
|
||||
destination=TESTNET_DESTINATION_ACCOUNT,
|
||||
memos=_MEMO,
|
||||
transaction_type=TransactionType.PAYMENT,
|
||||
)
|
||||
TESTNET_WALLET.next_sequence_num = get_next_valid_seq_number(TESTNET_CLASSIC_ACCOUNT, JSON_RPC_CLIENT_TESTNET)
|
||||
|
||||
# Prepare the tx by formatting it into
|
||||
# the shape expected by the XRP Ledger
|
||||
@@ -139,9 +144,6 @@ def prepare_sign_submit_tx():
|
||||
)
|
||||
print("Signed transaction: ", signed_tx)
|
||||
payment_transaction = Payment.from_dict(value)
|
||||
response = send_reliable_submission(
|
||||
payment_transaction, CLASSIC_ACCOUNT, JSON_RPC_URL
|
||||
)
|
||||
print("response.result.validated: ", response["validated"])
|
||||
print("response.result.meta: ", response.result["meta"]["TransactionResult"], "tesSUCCESS")
|
||||
if response.result["meta"]["TransactionResult"] != "tesSUCCESS":
|
||||
|
||||
Reference in New Issue
Block a user