mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-20 19:55:54 +00:00
Adding cancel escrow transaction
This commit is contained in:
@@ -1,40 +1,37 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
const RippleAPI = require('ripple-lib').RippleAPI
|
if (typeof module !== "undefined") {
|
||||||
|
// Use var here because const/let are block-scoped to the if statement.
|
||||||
const myAddr = 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn'
|
var xrpl = require('xrpl')
|
||||||
const mySecret = 's████████████████████████████'
|
|
||||||
|
|
||||||
const myEscrowCancellation = {
|
|
||||||
owner: myAddr,
|
|
||||||
escrowSequence: 366
|
|
||||||
}
|
|
||||||
const myInstructions = {
|
|
||||||
maxLedgerVersionOffset: 5
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const api = new RippleAPI({server: 'wss://s2.ripple.com'})
|
const secret = "sEdTPPEeMH6SAgpo6rSj8YW7a9vFfUj";
|
||||||
|
|
||||||
function submitTransaction(lastClosedLedgerVersion, prepared, secret) {
|
const main = async () => {
|
||||||
const signedData = api.sign(prepared.txJSON, secret)
|
try {
|
||||||
console.log('Transaction ID: ', signedData.id)
|
// Connect -------------------------------------------------------------------
|
||||||
return api.submit(signedData.signedTransaction).then(data => {
|
const client = new xrpl.Client('wss://s.altnet.rippletest.net:51233');
|
||||||
console.log('Tentative Result: ', data.resultCode)
|
await client.connect();
|
||||||
console.log('Tentative Message: ', data.resultMessage)
|
const wallet = await xrpl.Wallet.fromSeed(secret);
|
||||||
})
|
|
||||||
|
const escrowCancelTransaction = {
|
||||||
|
"Account": wallet.address,
|
||||||
|
"TransactionType": "EscrowCancel",
|
||||||
|
"Owner": wallet.address,
|
||||||
|
"OfferSequence": 34821001, // Sequence number
|
||||||
|
};
|
||||||
|
|
||||||
|
xrpl.validate(escrowCancelTransaction);
|
||||||
|
|
||||||
|
// Sign and submit the transaction --------------------------------------------
|
||||||
|
console.log('Signing and submitting the transaction:', escrowCancelTransaction);
|
||||||
|
const response = await client.submitAndWait(escrowCancelTransaction, { wallet });
|
||||||
|
console.log(`Finished submitting! ${JSON.stringify(response.result)}`);
|
||||||
|
|
||||||
|
await client.disconnect();
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
api.connect().then(() => {
|
main()
|
||||||
console.log('Connected')
|
|
||||||
return api.prepareEscrowCancellation(myAddr, myEscrowCancellation, myInstructions)
|
|
||||||
}).then(prepared => {
|
|
||||||
console.log('EscrowCancellation Prepared')
|
|
||||||
return api.getLedger().then(ledger => {
|
|
||||||
console.log('Current Ledger', ledger.ledgerVersion)
|
|
||||||
return submitTransaction(ledger.ledgerVersion, prepared, mySecret)
|
|
||||||
})
|
|
||||||
}).then(() => {
|
|
||||||
api.disconnect().then(() => {
|
|
||||||
console.log('api disconnected')
|
|
||||||
process.exit()
|
|
||||||
})
|
|
||||||
}).catch(console.error)
|
|
||||||
|
|||||||
@@ -1,32 +1,31 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
if (typeof module !== "undefined") {
|
if (typeof module !== "undefined") {
|
||||||
// Use var here because const/let are block-scoped to the if statement.
|
// Use var here because const/let are block-scoped to the if statement.
|
||||||
var xrpl = require('xrpl')
|
var xrpl = require('xrpl');
|
||||||
}
|
};
|
||||||
|
|
||||||
const cc = require('five-bells-condition')
|
const cc = require('five-bells-condition');
|
||||||
const crypto = require('crypto')
|
const crypto = require('crypto');
|
||||||
|
|
||||||
|
const secret = "sEdTPPEeMH6SAgpo6rSj8YW7a9vFfUj";
|
||||||
|
|
||||||
const main = async () => {
|
const main = async () => {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// Construct condition and fulfillment ---------------------------------------
|
// Construct condition and fulfillment ---------------------------------------
|
||||||
const preimageData = crypto.randomBytes(32)
|
const preimageData = crypto.randomBytes(32);
|
||||||
const myFulfillment = new cc.PreimageSha256()
|
const myFulfillment = new cc.PreimageSha256();
|
||||||
myFulfillment.setPreimage(preimageData)
|
myFulfillment.setPreimage(preimageData);
|
||||||
const conditionHex = myFulfillment.getConditionBinary().toString('hex').toUpperCase()
|
const conditionHex = myFulfillment.getConditionBinary().toString('hex').toUpperCase();
|
||||||
|
const wallet = await xrpl.Wallet.fromSeed(secret);
|
||||||
|
console.log("Wallet: ",wallet.address);
|
||||||
|
|
||||||
console.log('Condition:', conditionHex)
|
console.log('Condition:', conditionHex);
|
||||||
console.log('Fulfillment:', myFulfillment.serializeBinary().toString('hex').toUpperCase())
|
console.log('Fulfillment:', myFulfillment.serializeBinary().toString('hex').toUpperCase());
|
||||||
|
|
||||||
// Connect -------------------------------------------------------------------
|
// Connect -------------------------------------------------------------------
|
||||||
const client = new xrpl.Client('wss://s.altnet.rippletest.net:51233')
|
const client = new xrpl.Client('wss://s.altnet.rippletest.net:51233');
|
||||||
await client.connect()
|
await client.connect();
|
||||||
|
|
||||||
// Get credentials from the Testnet Faucet -----------------------------------
|
|
||||||
console.log("Requesting an address from the Testnet faucet...")
|
|
||||||
const { wallet, balance } = await client.fundWallet();
|
|
||||||
console.log("Wallet: ",wallet.address);
|
|
||||||
|
|
||||||
const firstRippleEpoch = 946684800;
|
const firstRippleEpoch = 946684800;
|
||||||
const escrowCreateTransaction = {
|
const escrowCreateTransaction = {
|
||||||
|
|||||||
Reference in New Issue
Block a user