Migrate check-individual-freeze.js

This commit is contained in:
Jackson Mills
2021-10-15 15:40:50 -07:00
parent 67c7390055
commit 30fbc2e42a

View File

@@ -1,37 +1,56 @@
const {RippleAPI} = require('ripple-lib'); // Dependencies for Node.js.
// In browsers, use <script> tags as in the example demo.html.
if (typeof module !== "undefined") {
// gotta use var here because const/let are block-scoped to the if statement.
var xrpl = require('xrpl')
}
const api = new RippleAPI({ // Connect -------------------------------------------------------------------
server: 'wss://s1.ripple.com' // Public rippled server async function main() {
}); console.log("Connecting to Mainnet...")
api.on('error', (errorCode, errorMessage) => { const client = new xrpl.Client('wss://s1.ripple.com')
console.log(errorCode + ': ' + errorMessage); await client.connect()
});
const my_address = 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn'; client.on('error', (errorCode, errorMessage) => {
const counterparty_address = 'rUpy3eEg8rqjqfUoLeBnZkscbKbFsKXC3v'; console.log(errorCode + ': ' + errorMessage);
const frozen_currency = 'USD'; });
api.connect().then(() => { const my_address = 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn';
const counterparty_address = 'rUpy3eEg8rqjqfUoLeBnZkscbKbFsKXC3v';
const frozen_currency = 'USD';
// Look up current state of trust line // Look up current state of trust line
const options = {counterparty: counterparty_address, const account_lines = {
currency: frozen_currency}; command: 'account_lines',
console.log('looking up', frozen_currency, 'trust line from', account: my_address,
my_address, 'to', counterparty_address); peer: counterparty_address,
return api.getTrustlines(my_address, options); };
}).then(data => { console.log('looking up all trust lines from',
counterparty_address, 'to', my_address);
if (data.length !== 1) { const data = await client.request(account_lines)
throw 'should only be 1 trust line per counterparty+currency pair';
// There is only one trust line per currency code per account,
// so we stop after the first match
let trustline = null;
for (let i = 0; i < data.result.lines.length; i++) {
if(data.result.lines[i].currency === frozen_currency) {
trustline = data.result.lines[i]
break
}
} }
const trustline = data[0]; if(trustline === null) {
console.log('Trust line frozen from our side?', throw `There was no ${frozen_currency} trust line`
trustline.specification.frozen === true); }
console.log('Trust line frozen from counterparty\'s side?',
trustline.counterparty.frozen === true);
}).then(() => { console.log('Trust line frozen from our side?',
return api.disconnect(); trustline.freeze === true);
}).catch(console.error); console.log('Trust line frozen from counterparty\'s side?',
trustline.freeze_peer === true);
await client.disconnect()
}
main().catch(console.error)