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