mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-28 07:35:50 +00:00
Migrate set-individual-freeze to 2.0
This commit is contained in:
@@ -1,57 +1,60 @@
|
||||
const {RippleAPI} = require('ripple-lib');
|
||||
const { validate } = require('xrpl');
|
||||
const xrpl = require('xrpl')
|
||||
|
||||
const api = new RippleAPI({
|
||||
server: 'wss://s1.ripple.com' // Public rippled server
|
||||
});
|
||||
api.on('error', (errorCode, errorMessage) => {
|
||||
console.log(errorCode + ': ' + errorMessage);
|
||||
});
|
||||
async function main() {
|
||||
// Connect -------------------------------------------------------------------
|
||||
const client = new xrpl.Client('wss://s.altnet.rippletest.net:51233')
|
||||
await client.connect()
|
||||
|
||||
const issuing_address = 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn';
|
||||
const issuing_secret = 's████████████████████████████';
|
||||
// Best practice: get your secret from an encrypted
|
||||
// config file instead
|
||||
const address_to_freeze = 'rUpy3eEg8rqjqfUoLeBnZkscbKbFsKXC3v';
|
||||
const currency_to_freeze = 'USD';
|
||||
client.on('error', (errorCode, errorMessage) => {
|
||||
console.log(errorCode + ': ' + errorMessage);
|
||||
});
|
||||
|
||||
api.connect().then(() => {
|
||||
const { wallet, balance } = await client.fundWallet()
|
||||
const issuing_address = wallet.classicAddress
|
||||
|
||||
//const issuing_address = 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn';
|
||||
const address_to_freeze = 'rUpy3eEg8rqjqfUoLeBnZkscbKbFsKXC3v';
|
||||
const currency_to_freeze = 'USD';
|
||||
|
||||
// Look up current state of trust line
|
||||
const options = {counterparty: address_to_freeze,
|
||||
currency: currency_to_freeze};
|
||||
const account_lines = {
|
||||
command: 'account_lines',
|
||||
account: issuing_address,
|
||||
peer: address_to_freeze,
|
||||
};
|
||||
|
||||
console.log('looking up', currency_to_freeze, 'trust line from',
|
||||
issuing_address, 'to', address_to_freeze);
|
||||
return api.getTrustlines(issuing_address, options);
|
||||
|
||||
}).then(data => {
|
||||
const data = await client.request(account_lines)
|
||||
|
||||
// Prepare a trustline transaction to enable freeze
|
||||
let trustline = {};
|
||||
let trustset = {};
|
||||
if (data.length !== 1) {
|
||||
console.log('trustline not found, making a default one');
|
||||
trustline = {
|
||||
currency: currency_to_freeze,
|
||||
counterparty: address_to_freeze,
|
||||
limit: 0
|
||||
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 {
|
||||
trustline = data[0].specification;
|
||||
trustset = data[0].specification;
|
||||
console.log('trustline found. previous state:', trustline);
|
||||
}
|
||||
|
||||
trustline.frozen = true;
|
||||
trustset.Flags = xrpl.TrustSetFlags.tfSetFreeze;
|
||||
|
||||
console.log('preparing trustline transaction for line:', trustline);
|
||||
return api.prepareTrustline(issuing_address, trustline);
|
||||
console.log('submitting tx:', trustset);
|
||||
await client.submit(wallet, trustset)
|
||||
|
||||
}).then(prepared_tx => {
|
||||
client.disconnect()
|
||||
}
|
||||
|
||||
// Sign and submit the trustline transaction
|
||||
console.log('signing tx:', prepared_tx.txJSON);
|
||||
const signed1 = api.sign(prepared_tx.txJSON, issuing_secret);
|
||||
console.log('submitting tx:', signed1.id);
|
||||
|
||||
return api.submit(signed1.signedTransaction);
|
||||
}).then(() => {
|
||||
return api.disconnect();
|
||||
}).catch(console.error);
|
||||
main().catch(console.error)
|
||||
|
||||
Reference in New Issue
Block a user