mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-20 03:35:51 +00:00
clean up snippets
This commit is contained in:
@@ -3,6 +3,7 @@ import { Client, Payment, PaymentFlags, TrustSet } from 'xrpl'
|
||||
const client = new Client('wss://s.altnet.rippletest.net:51233')
|
||||
|
||||
// This snippet walks us through partial payment.
|
||||
// Reference: https://xrpl.org/partial-payments.html
|
||||
async function partialPayment(): Promise<void> {
|
||||
await client.connect()
|
||||
|
||||
@@ -21,14 +22,18 @@ async function partialPayment(): Promise<void> {
|
||||
value: '10000000000',
|
||||
},
|
||||
}
|
||||
console.log("Submitting a TrustSet transaction...")
|
||||
|
||||
await client.submitAndWait(trust_set_tx, {
|
||||
const trust_set_res = await client.submitAndWait(trust_set_tx, {
|
||||
wallet: wallet2,
|
||||
})
|
||||
|
||||
console.log("TrustSet transaction response:")
|
||||
console.log(trust_set_res)
|
||||
|
||||
console.log('Balances after trustline is created')
|
||||
console.log(await client.getBalances(wallet1.classicAddress))
|
||||
console.log(await client.getBalances(wallet2.classicAddress))
|
||||
console.log(`Balance of ${wallet1.classicAddress} is ${await client.getBalances(wallet1.classicAddress)}`)
|
||||
console.log(`Balance of ${wallet2.classicAddress} is ${await client.getBalances(wallet2.classicAddress)}`)
|
||||
|
||||
// Initially, the issuer(wallet1) sends an amount to the other account(wallet2)
|
||||
const issue_quantity = '3840'
|
||||
@@ -47,11 +52,11 @@ async function partialPayment(): Promise<void> {
|
||||
const initialPayment = await client.submitAndWait(payment, {
|
||||
wallet: wallet1,
|
||||
})
|
||||
console.log(initialPayment)
|
||||
console.log("Initial payment response:", initialPayment)
|
||||
|
||||
console.log('Balances after issuer(wallet1) sends IOU("FOO") to wallet2')
|
||||
console.log(await client.getBalances(wallet1.classicAddress))
|
||||
console.log(await client.getBalances(wallet2.classicAddress))
|
||||
console.log(`Balance of ${wallet1.classicAddress} is ${await client.getBalances(wallet1.classicAddress)}`)
|
||||
console.log(`Balance of ${wallet2.classicAddress} is ${await client.getBalances(wallet2.classicAddress)}`)
|
||||
|
||||
/*
|
||||
* Send money less than the amount specified on 2 conditions:
|
||||
@@ -75,16 +80,17 @@ async function partialPayment(): Promise<void> {
|
||||
}
|
||||
|
||||
// submit payment
|
||||
console.log("Submitting a Partial Payment transaction...")
|
||||
const submitResponse = await client.submitAndWait(partialPaymentTx, {
|
||||
wallet: wallet2,
|
||||
})
|
||||
console.log(submitResponse)
|
||||
console.log("Partial Payment response: ", submitResponse)
|
||||
|
||||
console.log(
|
||||
"Balances after Partial Payment, when wallet2 tried to send 4000 FOO's",
|
||||
)
|
||||
console.log(await client.getBalances(wallet1.classicAddress))
|
||||
console.log(await client.getBalances(wallet2.classicAddress))
|
||||
console.log(`Balance of ${wallet1.classicAddress} is ${await client.getBalances(wallet1.classicAddress)}`)
|
||||
console.log(`Balance of ${wallet2.classicAddress} is ${await client.getBalances(wallet2.classicAddress)}`)
|
||||
|
||||
await client.disconnect()
|
||||
}
|
||||
|
||||
@@ -35,7 +35,9 @@ send_reliable_submission(signed_trust_set_tx, client)
|
||||
|
||||
# Both balances should be zero since nothing has been sent yet
|
||||
print("Balances after trustline is claimed:")
|
||||
print("Balance of ${wallet1.classic_address} is:")
|
||||
print((client.request(AccountLines(account=wallet1.classic_address))).result["lines"])
|
||||
print("Balance of ${wallet2.classic_address} is:")
|
||||
print((client.request(AccountLines(account=wallet2.classic_address))).result["lines"])
|
||||
|
||||
# Create a Payment to send 3840 FOO from wallet1 (issuer) to destination (wallet2)
|
||||
@@ -53,11 +55,13 @@ payment_tx = Payment(
|
||||
# Sign and autofill, then send transaction to the ledger
|
||||
signed_payment_tx = autofill_and_sign(payment_tx, wallet1, client)
|
||||
payment_response = send_reliable_submission(signed_payment_tx, client)
|
||||
print(payment_response)
|
||||
print("Initial Payment response: ", payment_response)
|
||||
|
||||
# Issuer (wallet1) should have -3840 FOO and destination (wallet2) should have 3840 FOO
|
||||
print("Balances after wallet1 sends 3840 FOO to wallet2:")
|
||||
print("Balance of ${wallet1.classic_address} is:")
|
||||
print((client.request(AccountLines(account=wallet1.classic_address))).result["lines"])
|
||||
print("Balance of ${wallet2.classic_address} is:")
|
||||
print((client.request(AccountLines(account=wallet2.classic_address))).result["lines"])
|
||||
|
||||
# Send money less than the amount specified on 2 conditions:
|
||||
@@ -88,9 +92,11 @@ partial_payment_tx = Payment(
|
||||
# Sign and autofill, then send transaction to the ledger
|
||||
signed_partial_payment_tx = autofill_and_sign(partial_payment_tx, wallet2, client)
|
||||
partial_payment_response = send_reliable_submission(signed_partial_payment_tx, client)
|
||||
print(partial_payment_response)
|
||||
print("Partial Payment response: ", partial_payment_response)
|
||||
|
||||
# Tried sending 4000 of 3840 FOO -> wallet1 and wallet2 should have 0 FOO
|
||||
print("Balances after Partial Payment, when wallet2 tried to send 4000 FOOs")
|
||||
print("Balance of ${wallet1.classic_address} is:")
|
||||
print((client.request(AccountLines(account=wallet1.classic_address))).result["lines"])
|
||||
print("Balance of ${wallet2.classic_address} is:")
|
||||
print((client.request(AccountLines(account=wallet2.classic_address))).result["lines"])
|
||||
|
||||
Reference in New Issue
Block a user