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,9 +1,17 @@
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({
server: 'wss://s1.ripple.com' // Public rippled server
});
api.on('error', (errorCode, errorMessage) => {
// Connect -------------------------------------------------------------------
async function main() {
console.log("Connecting to Mainnet...")
const client = new xrpl.Client('wss://s1.ripple.com')
await client.connect()
client.on('error', (errorCode, errorMessage) => {
console.log(errorCode + ': ' + errorMessage);
});
@@ -11,27 +19,38 @@ const my_address = 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn';
const counterparty_address = 'rUpy3eEg8rqjqfUoLeBnZkscbKbFsKXC3v';
const frozen_currency = 'USD';
api.connect().then(() => {
// Look up current state of trust line
const options = {counterparty: counterparty_address,
currency: frozen_currency};
console.log('looking up', frozen_currency, 'trust line from',
my_address, 'to', counterparty_address);
return api.getTrustlines(my_address, options);
const account_lines = {
command: 'account_lines',
account: my_address,
peer: counterparty_address,
};
}).then(data => {
console.log('looking up all trust lines from',
counterparty_address, 'to', my_address);
if (data.length !== 1) {
throw 'should only be 1 trust line per counterparty+currency pair';
const data = await client.request(account_lines)
// 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];
console.log('Trust line frozen from our side?',
trustline.specification.frozen === true);
console.log('Trust line frozen from counterparty\'s side?',
trustline.counterparty.frozen === true);
if(trustline === null) {
throw `There was no ${frozen_currency} trust line`
}
}).then(() => {
return api.disconnect();
}).catch(console.error);
console.log('Trust line frozen from our side?',
trustline.freeze === true);
console.log('Trust line frozen from counterparty\'s side?',
trustline.freeze_peer === true);
await client.disconnect()
}
main().catch(console.error)