Merge pull request #1213 from JST5000/update-freeze

Update freeze code samples to match xrpl.js release syntax
This commit is contained in:
Rome Reginelli
2021-10-22 15:43:21 -07:00
committed by GitHub
7 changed files with 99 additions and 81 deletions

View File

@@ -1,36 +1,34 @@
// 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')
}
// gotta use var here because const/let are block-scoped to the if statement.
var xrpl = require('xrpl')
var { AccountRootFlags } = require('xrpl/dist/npm/models/ledger')
}
// 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)
})
const my_address = 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn';
// Request account info for my_address to check account settings ------------
const response = await client.request(
{command: 'account_info', account: my_address })
const settings = response.result
const lsfGlobalFreeze = 0x00400000
// Connect -------------------------------------------------------------------
async function main() {
console.log("Connecting to Mainnet...")
const client = new xrpl.Client('wss://s1.ripple.com')
await client.connect()
console.log('Got settings for address', my_address);
console.log('Global Freeze enabled?',
((settings.account_data.Flags & lsfGlobalFreeze) === lsfGlobalFreeze))
await client.disconnect()
// End main()
}
main().catch(console.error)
const my_address = 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn';
// Request account info for my_address to check account settings ------------
const response = await client.request(
{command: 'account_info', account: my_address })
const settings = response.result
const lsfGlobalFreeze = xrpl.LedgerEntry.AccountRootFlags.lsfGlobalFreeze
console.log('Got settings for address', my_address);
console.log('Global Freeze enabled?',
((settings.account_data.Flags & lsfGlobalFreeze)
=== lsfGlobalFreeze))
await client.disconnect()
// End main()
}
main().catch(console.error)

View File

@@ -11,10 +11,6 @@ async function main() {
const client = new xrpl.Client('wss://s1.ripple.com')
await client.connect()
client.on('error', (errorCode, errorMessage) => {
console.log(errorCode + ': ' + errorMessage)
})
const my_address = 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn'
const counterparty_address = 'rUpy3eEg8rqjqfUoLeBnZkscbKbFsKXC3v'
const frozen_currency = 'USD'

View File

@@ -1,33 +1,33 @@
// 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')
}
// gotta use var here because const/let are block-scoped to the if statement.
var xrpl = require('xrpl')
}
// 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)
})
// Connect -------------------------------------------------------------------
async function main() {
console.log("Connecting to Mainnet...")
const client = new xrpl.Client('wss://s1.ripple.com')
await client.connect()
const my_address = 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn';
const my_address = 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn';
// Request account info for my_address to check account settings ------------
const response = await client.request(
{command: 'account_info', account: my_address })
const settings = response.result
// Request account info for my_address to check account settings ------------
const response = await client.request(
{command: 'account_info', account: my_address })
const settings = response.result
const lsfNoFreeze = xrpl.LedgerEntry.AccountRootFlags.lsfNoFreeze
console.log('Got settings for address', my_address);
console.log('No Freeze enabled?', (settings.noFreeze === true))
console.log('Got settings for address', my_address);
console.log('No Freeze enabled?',
(settings.account_data.Flags & lsfNoFreeze)
=== lsfNoFreeze)
await client.disconnect()
await client.disconnect()
// End main()
}
// End main()
}
main().catch(console.error)
main().catch(console.error)

View File

@@ -1,13 +1,15 @@
const xrpl = require('xrpl')
// 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')
}
async function main() {
// Connect -------------------------------------------------------------------
const client = new xrpl.Client('wss://s.altnet.rippletest.net:51233')
await client.connect()
client.on('error', (errorCode, errorMessage) => {
console.log(errorCode + ': ' + errorMessage)
})
// Get credentials from the Testnet Faucet ------------------------------------
console.log("Requesting an address from the Testnet faucet...")
const { wallet, balance } = await client.fundWallet()
@@ -20,9 +22,12 @@ async function main() {
SetFlag: xrpl.AccountSetAsfFlags.asfGlobalFreeze
}
// Best practice for JS users - validate checks if a transaction is well-formed
xrpl.validate(accountSetTx)
// Sign and submit the AccountSet transaction to enable a global freeze -------
console.log('Signing and submitting the transaction:', accountSetTx)
await client.submitAndWait(wallet, accountSetTx)
await client.submitAndWait(accountSetTx, { wallet: wallet })
console.log("Finished submitting!")
// Checking the status of the global freeze -----------------------------------
@@ -49,9 +54,12 @@ async function main() {
ClearFlag: xrpl.AccountSetAsfFlags.asfGlobalFreeze
}
// Best practice for JS users - validate checks if a transaction is well-formed
xrpl.validate(accountSetTx2)
// Sign and submit the AccountSet transaction to enable a global freeze -------
console.log('Signing and submitting the transaction:', accountSetTx2)
const result = await client.submitAndWait(wallet, accountSetTx2)
const result = await client.submitAndWait(accountSetTx2, { wallet: wallet })
console.log("Finished submitting!")
// Checking the status of the global freeze -----------------------------------

View File

@@ -1,13 +1,15 @@
const xrpl = require('xrpl')
// 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')
}
async function main() {
// Connect -------------------------------------------------------------------
const client = new xrpl.Client('wss://s.altnet.rippletest.net:51233')
await client.connect()
client.on('error', (errorCode, errorMessage) => {
console.log(errorCode + ': ' + errorMessage)
})
// Get credentials from the Testnet Faucet -----------------------------------
console.log("Requesting an address from the Testnet faucet...")
const { wallet, balance } = await client.fundWallet()
@@ -20,9 +22,12 @@ async function main() {
SetFlag: xrpl.AccountSetAsfFlags.asfGlobalFreeze
}
// Best practice for JS users - validate checks if a transaction is well-formed
xrpl.validate(accountSetTx)
// Sign and submit the AccountSet transaction to enable a global freeze ------
console.log('Signing and submitting the transaction:', accountSetTx)
await client.submitAndWait(wallet, accountSetTx)
await client.submitAndWait(accountSetTx, { wallet })
console.log(`Finished submitting! ${wallet.address} should be frozen now.`)
// Investigate ---------------------------------------------------------------
@@ -38,9 +43,12 @@ async function main() {
ClearFlag: xrpl.AccountSetAsfFlags.asfGlobalFreeze
}
// Best practice for JS users - validate checks if a transaction is well-formed
xrpl.validate(accountSetTx2)
// Sign and submit the AccountSet transaction to end a global freeze ---------
console.log('Signing and submitting the transaction:', accountSetTx2)
const result = await client.submitAndWait(wallet, accountSetTx2)
const result = await client.submitAndWait(accountSetTx2, { wallet: wallet })
console.log("Finished submitting!")
// Global freeze disabled

View File

@@ -1,14 +1,15 @@
const xrpl = require('xrpl')
// 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')
}
async function main() {
// Connect -------------------------------------------------------------------
const client = new xrpl.Client('wss://s.altnet.rippletest.net:51233')
await client.connect()
client.on('error', (errorCode, errorMessage) => {
console.log(errorCode + ': ' + errorMessage)
})
// Get credentials from the Testnet Faucet ------------------------------------
console.log("Requesting an address from the Testnet faucet...")
const { wallet, balance } = await client.fundWallet()
@@ -72,9 +73,12 @@ async function main() {
// Set a flag to freeze the trust line --------------------------------------------
trust_set.Flags = xrpl.TrustSetFlags.tfSetFreeze
// Best practice for JS users - validate checks if a transaction is well-formed
xrpl.validate(trust_set)
// Submit a TrustSet transaction to set an individual freeze ----------------------
console.log('Submitting TrustSet tx:', trust_set)
const result = await client.submitAndWait(wallet, trust_set)
const result = await client.submitAndWait(trust_set, { wallet: wallet })
console.log("Submitted TrustSet!")
// Investigate --------------------------------------------------------------------
@@ -88,7 +92,7 @@ async function main() {
// Submit a TrustSet transaction to clear an individual freeze --------------------
console.log('Submitting TrustSet tx:', trust_set)
const result2 = await client.submitAndWait(wallet, trust_set)
const result2 = await client.submitAndWait(trust_set, { wallet: wallet })
console.log("Submitted TrustSet!")
console.log("Finished submitting. Now disconnecting.")

View File

@@ -1,4 +1,9 @@
const xrpl = require('xrpl')
// 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')
}
async function main() {
// Connect -------------------------------------------------------------------
@@ -6,10 +11,6 @@ async function main() {
await client.connect()
console.log("Connected to Testnet")
client.on('error', (errorCode, errorMessage) => {
console.log(errorCode + ': ' + errorMessage)
})
// Get credentials from the Testnet Faucet ------------------------------------
console.log("Requesting an address from the Testnet faucet...")
const { wallet, balance } = await client.fundWallet()
@@ -22,8 +23,11 @@ async function main() {
SetFlag: xrpl.AccountSetAsfFlags.asfNoFreeze
}
// Best practice for JS users - validate checks if a transaction is well-formed
xrpl.validate(accountSetTx)
console.log('Sign and submit the transaction:', accountSetTx)
await client.submitAndWait(wallet, accountSetTx)
await client.submitAndWait(accountSetTx, { wallet: wallet })
// Done submitting
console.log("Finished submitting. Now disconnecting.")