mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-18 02:35:49 +00:00
Make set-individual-freeze more readable + comment
This commit is contained in:
@@ -10,14 +10,15 @@ async function main() {
|
||||
console.log(errorCode + ': ' + errorMessage)
|
||||
})
|
||||
|
||||
// Generates a test account
|
||||
// Get credentials from the Testnet Faucet ------------------------------------
|
||||
console.log("Requesting an address from the Testnet faucet...")
|
||||
const { wallet, balance } = await client.fundWallet()
|
||||
|
||||
const issuing_address = wallet.classicAddress
|
||||
// Look up current state of a trust line --------------------------------------
|
||||
const issuing_address = wallet.address
|
||||
const address_to_freeze = 'rUpy3eEg8rqjqfUoLeBnZkscbKbFsKXC3v'
|
||||
const currency_to_freeze = 'USD'
|
||||
|
||||
// Look up current state of trust line
|
||||
const account_lines = {
|
||||
command: 'account_lines',
|
||||
account: issuing_address,
|
||||
@@ -30,8 +31,7 @@ async function main() {
|
||||
const data = await client.request(account_lines)
|
||||
const trustlines = data.result.lines
|
||||
|
||||
// There can only be one trust line per currency code per account,
|
||||
// so we stop after the first match
|
||||
// Find the trust line for our currency_to_freeze ------------------------------
|
||||
let trustline = null
|
||||
for (let i = 0; i < trustlines.length; i++) {
|
||||
if(trustlines[i].currency === currency_to_freeze) {
|
||||
@@ -40,41 +40,47 @@ async function main() {
|
||||
}
|
||||
}
|
||||
|
||||
let limit = null
|
||||
// Prepare a TrustSet transaction to create or modify the target trust line ----
|
||||
let trust_set = null
|
||||
|
||||
if(trustline === null) {
|
||||
console.log('Trustline not found, making a default one')
|
||||
|
||||
limit = {
|
||||
value: '0',
|
||||
currency: currency_to_freeze,
|
||||
issuer: address_to_freeze,
|
||||
|
||||
trust_set = {
|
||||
TransactionType: 'TrustSet',
|
||||
Account: issuing_address,
|
||||
LimitAmount: {
|
||||
value: '0',
|
||||
currency: currency_to_freeze,
|
||||
issuer: address_to_freeze,
|
||||
},
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log('Found existing trustline: ', trustline)
|
||||
|
||||
limit = {
|
||||
value: trustline.limit,
|
||||
currency: trustline.currency,
|
||||
issuer: trustline.account
|
||||
trust_set = {
|
||||
TransactionType: 'TrustSet',
|
||||
Account: issuing_address,
|
||||
LimitAmount: {
|
||||
value: trustline.limit,
|
||||
currency: trustline.currency,
|
||||
issuer: trustline.account
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const trust_set = {
|
||||
TransactionType: 'TrustSet',
|
||||
Account: issuing_address,
|
||||
LimitAmount: limit,
|
||||
// Signal to freeze the individual trust line
|
||||
Flags: xrpl.TrustSetFlags.tfSetFreeze
|
||||
}
|
||||
|
||||
// For JS users, validate lets you check if your transaction is well-formed
|
||||
validate(trust_set)
|
||||
// Set a flag to freeze the trust line --------------------------------------------
|
||||
trust_set.Flags = xrpl.TrustSetFlags.tfSetFreeze
|
||||
|
||||
// Submit a TrustSet transaction to set an individual freeze ----------------------
|
||||
console.log('Submitting TrustSet tx:', trust_set)
|
||||
const result = await client.submitReliable(wallet, trust_set)
|
||||
|
||||
console.log('Submitted tx!')
|
||||
console.log("Finished submitting. Now disconnecting.")
|
||||
await client.disconnect()
|
||||
|
||||
//End main()
|
||||
}
|
||||
|
||||
main().catch(console.error)
|
||||
|
||||
@@ -4,14 +4,14 @@ async function main() {
|
||||
// Connect -------------------------------------------------------------------
|
||||
const client = new xrpl.Client('wss://s.altnet.rippletest.net:51233')
|
||||
await client.connect()
|
||||
console.log("Connected to TestNet")
|
||||
console.log("Connected to Testnet")
|
||||
|
||||
client.on('error', (errorCode, errorMessage) => {
|
||||
console.log(errorCode + ': ' + errorMessage)
|
||||
})
|
||||
|
||||
// Get credentials from the Testnet Faucet ------------------------------------
|
||||
console.log("Requesting addresses from the Testnet faucet...")
|
||||
console.log("Requesting an address from the Testnet faucet...")
|
||||
const { wallet, balance } = await client.fundWallet()
|
||||
|
||||
// Submit an AccountSet transaction to enable No Freeze ----------------------
|
||||
|
||||
Reference in New Issue
Block a user