mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-20 11:45:50 +00:00
Fix set-individual-freeze when trustline exists
This commit is contained in:
@@ -10,10 +10,10 @@ async function main() {
|
||||
console.log(errorCode + ': ' + errorMessage);
|
||||
});
|
||||
|
||||
// Generates a test account
|
||||
const { wallet, balance } = await client.fundWallet()
|
||||
const issuing_address = wallet.classicAddress
|
||||
|
||||
//const issuing_address = 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn';
|
||||
const issuing_address = wallet.classicAddress
|
||||
const address_to_freeze = 'rUpy3eEg8rqjqfUoLeBnZkscbKbFsKXC3v';
|
||||
const currency_to_freeze = 'USD';
|
||||
|
||||
@@ -24,39 +24,56 @@ async function main() {
|
||||
peer: address_to_freeze,
|
||||
};
|
||||
|
||||
console.log('looking up', currency_to_freeze, 'trust line from',
|
||||
console.log('Looking up', currency_to_freeze, 'trust line from',
|
||||
issuing_address, 'to', address_to_freeze);
|
||||
|
||||
const data = await client.request(account_lines)
|
||||
const trustlines = data.result.lines
|
||||
|
||||
let trustset = {};
|
||||
if (data.length !== 1) {
|
||||
console.log('trustline not found, making a default one');
|
||||
|
||||
// Prepare a TrustSet transaction to create a trust line
|
||||
trustset = {
|
||||
TransactionType: 'TrustSet',
|
||||
Account: issuing_address,
|
||||
LimitAmount: {
|
||||
value: '0',
|
||||
currency: currency_to_freeze,
|
||||
issuer: address_to_freeze,
|
||||
}
|
||||
};
|
||||
|
||||
// For JS users, this lets you check if your transaction is well-formed
|
||||
validate(trustset)
|
||||
|
||||
} else {
|
||||
trustset = data[0].specification;
|
||||
console.log('trustline found. previous state:', trustline);
|
||||
// There can only be one trust line per currency code per account,
|
||||
// so we stop after the first match
|
||||
let trustline = null;
|
||||
for (let i = 0; i < trustlines.length; i++) {
|
||||
if(trustlines[i].currency === currency_to_freeze) {
|
||||
trustline = trustlines[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
trustset.Flags = xrpl.TrustSetFlags.tfSetFreeze;
|
||||
let limit = null;
|
||||
if(trustline === null) {
|
||||
console.log('Trustline not found, making a default one');
|
||||
|
||||
console.log('submitting tx:', trustset);
|
||||
await client.submitReliable(wallet, trustset)
|
||||
limit = {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
console.log('Submitting TrustSet tx:', trust_set);
|
||||
const result = await client.submitReliable(wallet, trust_set)
|
||||
|
||||
console.log('Submitted tx!')
|
||||
client.disconnect()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user