mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-21 04:05:49 +00:00
Updates based on feedback
This commit is contained in:
@@ -15,37 +15,40 @@ function addSeconds(numOfSeconds, date = new Date()) {
|
||||
// *******************************************************
|
||||
|
||||
async function createTimeBasedEscrow() {
|
||||
|
||||
//-------------------------------------------- Prepare Finish and Cancel Dates
|
||||
|
||||
let escrow_finish_date = new Date()
|
||||
let escrow_cancel_date = new Date()
|
||||
escrow_finish_date = addSeconds(parseInt(escrowFinishTimeField.value))
|
||||
escrow_cancel_date = addSeconds(parseInt(escrowCancelTimeField.value))
|
||||
|
||||
//------------------------------------------------------Connect to the Ledger
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `Connected to ${net}.\nCreating time-based escrow.\n`
|
||||
let results = `===Connected to ${net}.===\n\n===Creating time-based escrow.===\n`
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const sendAmount = amountField.value
|
||||
resultField.value = results
|
||||
const escrowTx = await client.autofill({
|
||||
"TransactionType": "EscrowCreate",
|
||||
"Account": wallet.address,
|
||||
"Amount": xrpl.xrpToDrops(sendAmount),
|
||||
"Destination": destinationField.value,
|
||||
"FinishAfter": escrow_finish_date,
|
||||
"CancelAfter": escrow_cancel_date
|
||||
})
|
||||
const signed = wallet.sign(escrowTx)
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += "\nSuccess! Save this sequence number: " + tx.result.tx_json.Sequence
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
resultField.value = results
|
||||
client.disconnect()
|
||||
try {
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const sendAmount = amountField.value
|
||||
const escrowTx = await client.autofill({
|
||||
"TransactionType": "EscrowCreate",
|
||||
"Account": wallet.address,
|
||||
"Amount": xrpl.xrpToDrops(sendAmount),
|
||||
"Destination": destinationField.value,
|
||||
"FinishAfter": escrow_finish_date,
|
||||
"CancelAfter": escrow_cancel_date
|
||||
})
|
||||
const signed = wallet.sign(escrowTx)
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += "\n===Success! === *** Save this sequence number: " + tx.result.tx_json.Sequence
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
resultField.value = results
|
||||
}
|
||||
catch (error) {
|
||||
results += "\n===Error: " + error.message
|
||||
resultField.value = results
|
||||
}
|
||||
finally {
|
||||
client.disconnect()
|
||||
}
|
||||
} // End of createTimeEscrow()
|
||||
|
||||
// *******************************************************
|
||||
@@ -56,24 +59,30 @@ async function finishTimeBasedEscrow() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `Connected to ${net}. Finishing escrow....`
|
||||
let results = `===Connected to ${net}. Finishing escrow.===\n`
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
results += "\nwallet.address: = " + wallet.address
|
||||
resultField.value = results
|
||||
const prepared = await client.autofill({
|
||||
"TransactionType": "EscrowFinish",
|
||||
"Account": accountAddressField.value,
|
||||
"Owner": escrowOwnerField.value,
|
||||
"OfferSequence": parseInt(escrowSequenceNumberField.value)
|
||||
})
|
||||
const signed = wallet.sign(prepared)
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += "\nBalance changes: " +
|
||||
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||
resultField.value = results
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
client.disconnect()
|
||||
try {
|
||||
const prepared = await client.autofill({
|
||||
"TransactionType": "EscrowFinish",
|
||||
"Account": accountAddressField.value,
|
||||
"Owner": escrowOwnerField.value,
|
||||
"OfferSequence": parseInt(escrowSequenceNumberField.value)
|
||||
})
|
||||
const signed = wallet.sign(prepared)
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += "\n===Balance changes===" +
|
||||
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||
resultField.value = results
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
}
|
||||
catch (error) {
|
||||
results += "\n===Error: " + error.message + "==="
|
||||
resultField.value = results
|
||||
}
|
||||
finally {
|
||||
client.disconnect()
|
||||
}
|
||||
} // End of finishTimeBasedEscrow()
|
||||
|
||||
// *******************************************************
|
||||
@@ -83,21 +92,28 @@ async function finishTimeBasedEscrow() {
|
||||
async function getEscrows() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `\nConnected to ${net}.\nGetting account escrows...\n`
|
||||
await client.connect()
|
||||
let results = `\n===Connected to ${net}.\nGetting account escrows.===\n`
|
||||
resultField.value = results
|
||||
const escrow_objects = await client.request({
|
||||
"id": 5,
|
||||
"command": "account_objects",
|
||||
"account": accountAddressField.value,
|
||||
"ledger_index": "validated",
|
||||
"type": "escrow"
|
||||
})
|
||||
results += JSON.stringify(escrow_objects.result, null, 2)
|
||||
resultField.value = results
|
||||
client.disconnect()
|
||||
} // End of getEscrows()
|
||||
|
||||
try {
|
||||
const escrow_objects = await client.request({
|
||||
"id": 5,
|
||||
"command": "account_objects",
|
||||
"account": accountAddressField.value,
|
||||
"ledger_index": "validated",
|
||||
"type": "escrow"
|
||||
})
|
||||
results += JSON.stringify(escrow_objects.result, null, 2)
|
||||
resultField.value = results
|
||||
}
|
||||
catch (error) {
|
||||
results += "\nError: " + error.message
|
||||
resultField.value = results
|
||||
}
|
||||
finally {
|
||||
client.disconnect()
|
||||
}
|
||||
}
|
||||
|
||||
// *******************************************************
|
||||
// ************** Get Transaction Info *******************
|
||||
@@ -106,18 +122,25 @@ async function getEscrows() {
|
||||
async function getTransaction() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `\nConnected to ${net}.\nGetting transaction information...\n`
|
||||
await client.connect()
|
||||
let results = `\n===Connected to ${net}.===\n===Getting transaction information.===\n`
|
||||
resultField.value = results
|
||||
const tx_info = await client.request({
|
||||
"id": 1,
|
||||
"command": "tx",
|
||||
"transaction": transactionField.value,
|
||||
})
|
||||
results += JSON.stringify(tx_info.result, null, 2)
|
||||
resultField.value = results
|
||||
client.disconnect()
|
||||
|
||||
try {
|
||||
const tx_info = await client.request({
|
||||
"id": 1,
|
||||
"command": "tx",
|
||||
"transaction": transactionField.value,
|
||||
})
|
||||
results += JSON.stringify(tx_info.result, null, 2)
|
||||
resultField.value = results
|
||||
}
|
||||
catch (error) {
|
||||
results += "\nError: " + error.message
|
||||
resultField.value = results
|
||||
}
|
||||
finally {
|
||||
client.disconnect()
|
||||
}
|
||||
} // End of getTransaction()
|
||||
|
||||
// *******************************************************
|
||||
@@ -128,20 +151,27 @@ async function cancelEscrow() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `\nConnected to ${net}. Cancelling escrow....`
|
||||
let results = `\n===Connected to ${net}. Cancelling escrow.===`
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const prepared = await client.autofill({
|
||||
"TransactionType": "EscrowCancel",
|
||||
"Account": wallet.address,
|
||||
"Owner": escrowOwnerField.value,
|
||||
"OfferSequence": parseInt(escrowSequenceNumberField.value)
|
||||
})
|
||||
const signed = wallet.sign(prepared)
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += "\nBalance changes: " +
|
||||
try {
|
||||
const prepared = await client.autofill({
|
||||
"TransactionType": "EscrowCancel",
|
||||
"Account": accountAddressField.value,
|
||||
"Owner": escrowOwnerField.value,
|
||||
"OfferSequence": parseInt(escrowSequenceNumberField.value)
|
||||
})
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const signed = wallet.sign(prepared)
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += "\n===Balance changes: " +
|
||||
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||
resultField.value = results
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
client.disconnect()
|
||||
resultField.value = results
|
||||
}
|
||||
catch (error) {
|
||||
results += "\n===Error: " + error.message
|
||||
resultField.value = results
|
||||
}
|
||||
finally {
|
||||
client.disconnect()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user