Fix set-individual-freeze when trustline exists

This commit is contained in:
Jackson Mills
2021-10-15 16:42:53 -07:00
parent 30fbc2e42a
commit ae72b1e024

View File

@@ -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');
// 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
}
}
// Prepare a TrustSet transaction to create a trust line
trustset = {
TransactionType: 'TrustSet',
Account: issuing_address,
LimitAmount: {
let limit = null;
if(trustline === null) {
console.log('Trustline not found, making a default one');
limit = {
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);
console.log('Found existing trustline: ', 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);
await client.submitReliable(wallet, trustset)
// 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()
}