mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-12-01 17:15:51 +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({
|
async function main() {
|
||||||
server: 'wss://s1.ripple.com' // Public rippled server
|
// Connect -------------------------------------------------------------------
|
||||||
});
|
const client = new xrpl.Client('wss://s.altnet.rippletest.net:51233')
|
||||||
api.on('error', (errorCode, errorMessage) => {
|
await client.connect()
|
||||||
console.log(errorCode + ': ' + errorMessage);
|
|
||||||
});
|
|
||||||
|
|
||||||
const issuing_address = 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn';
|
client.on('error', (errorCode, errorMessage) => {
|
||||||
const issuing_secret = 's████████████████████████████';
|
console.log(errorCode + ': ' + errorMessage);
|
||||||
// Best practice: get your secret from an encrypted
|
});
|
||||||
// config file instead
|
|
||||||
const address_to_freeze = 'rUpy3eEg8rqjqfUoLeBnZkscbKbFsKXC3v';
|
|
||||||
const currency_to_freeze = 'USD';
|
|
||||||
|
|
||||||
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
|
// Look up current state of trust line
|
||||||
const options = {counterparty: address_to_freeze,
|
const account_lines = {
|
||||||
currency: currency_to_freeze};
|
command: 'account_lines',
|
||||||
|
account: issuing_address,
|
||||||
|
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);
|
||||||
return api.getTrustlines(issuing_address, options);
|
|
||||||
|
|
||||||
}).then(data => {
|
const data = await client.request(account_lines)
|
||||||
|
|
||||||
// Prepare a trustline transaction to enable freeze
|
// Prepare a trustline transaction to enable freeze
|
||||||
let trustline = {};
|
let trustset = {};
|
||||||
if (data.length !== 1) {
|
if (data.length !== 1) {
|
||||||
console.log('trustline not found, making a default one');
|
console.log('trustline not found, making a default one');
|
||||||
trustline = {
|
trustset = {
|
||||||
currency: currency_to_freeze,
|
TransactionType: 'TrustSet',
|
||||||
counterparty: address_to_freeze,
|
Account: issuing_address,
|
||||||
limit: 0
|
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 {
|
} else {
|
||||||
trustline = data[0].specification;
|
trustset = data[0].specification;
|
||||||
console.log('trustline found. previous state:', trustline);
|
console.log('trustline found. previous state:', trustline);
|
||||||
}
|
}
|
||||||
|
|
||||||
trustline.frozen = true;
|
trustset.Flags = xrpl.TrustSetFlags.tfSetFreeze;
|
||||||
|
|
||||||
console.log('preparing trustline transaction for line:', trustline);
|
console.log('submitting tx:', trustset);
|
||||||
return api.prepareTrustline(issuing_address, trustline);
|
await client.submit(wallet, trustset)
|
||||||
|
|
||||||
}).then(prepared_tx => {
|
client.disconnect()
|
||||||
|
}
|
||||||
|
|
||||||
// Sign and submit the trustline transaction
|
main().catch(console.error)
|
||||||
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);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user