mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-12-05 08:48:11 +00:00
code updates for xrpl.js 2.0 beta 5
This commit is contained in:
@@ -520,12 +520,12 @@ async function generic_full_send(event, tx_json, wallet) {
|
||||
`<p>${tl("Prepared transaction:")}</p>
|
||||
<pre><code>${pretty_print(prepared)}</code></pre>`)
|
||||
|
||||
const signed = wallet.signTransaction(prepared)
|
||||
const {tx_blob, hash} = wallet.sign(prepared)
|
||||
block.find(".output-area").append(
|
||||
`<p>${tl("Transaction hash:")} <code id="tx_id">${xrpl.computeSignedTransactionHash(signed)}</code></p>`)
|
||||
`<p>${tl("Transaction hash:")} <code id="tx_id">${hash}</code></p>`)
|
||||
// TODO: update computeSignedTransactionHash if that changes
|
||||
|
||||
await do_submit(block, {"tx_blob": signed}, wait_step_name)
|
||||
await do_submit(block, {"tx_blob": tx_blob}, wait_step_name)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,183 +0,0 @@
|
||||
// Submit-and-verify XRPL transaction using xrpl.js (v2.0)
|
||||
// Demonstrates how to submit a transaction and wait for validation.
|
||||
// This is not true "robust" transaction submission because it does not protect
|
||||
// against power outages or other sudden interruptions.
|
||||
|
||||
// Look up a transaction's result.
|
||||
// Arguments:
|
||||
// @param api object Client instance connected to the network where you
|
||||
// submitted the transaction. MUST ALREADY BE SUBSCRIBED TO THE
|
||||
// `ledger` event stream.
|
||||
// @param tx_id string The identifying hash of the transaction.
|
||||
// @param max_ledger int optional The highest ledger index where the
|
||||
// transaction can be validated.
|
||||
// @param min_ledger int optional The lowest ledger index where the
|
||||
// transaction can be validated.
|
||||
// Returns: Promise<object> -> result of the tx command with the transaction's
|
||||
// validated transaction results.
|
||||
// On failure, the reason is an object with two fields:
|
||||
// - failure_final: if true, this transaction did not achieve consensus and
|
||||
// it can never be validated in the future (assuming the
|
||||
// min_ledger and max_ledger values provided were accurate).
|
||||
// - msg: A human-readable message explaining what happened.
|
||||
function lookup_tx_final(api, tx_id, max_ledger, min_ledger) {
|
||||
if (typeof min_ledger == "undefined") {
|
||||
min_ledger = -1
|
||||
}
|
||||
if (typeof max_ledger == "undefined") {
|
||||
max_ledger = -1
|
||||
}
|
||||
if (min_ledger > max_ledger) {
|
||||
// Assume the args were just passed backwards & swap them
|
||||
[min_ledger, max_ledger] = [max_ledger, min_ledger]
|
||||
}
|
||||
|
||||
// Make sure we're subscribed to the ledger stream to trigger updates
|
||||
api.request({"command": "subscribe", "streams": ["ledger"]})
|
||||
|
||||
// Helper to determine if we (should) know the transaction's final result yet.
|
||||
// If the server has validated all ledgers the tx could possibly appear in,
|
||||
// then we should know its final result.
|
||||
async function server_has_ledger_range(min_ledger, max_ledger) {
|
||||
const si = await api.request({command: "server_info"})
|
||||
// console.log(`Server has ledger range: ${si.result.info.complete_ledgers}`)
|
||||
if (si.result.info.complete_ledgers == "empty") {
|
||||
console.warn("Connected server is not synced.")
|
||||
return false
|
||||
}
|
||||
// In case of a discontiguous set, use only the last set, since we need
|
||||
// continuous history from submission to expiration to know that a
|
||||
// transaction failed to achieve consensus.
|
||||
const ledger_ranges = si.result.info.complete_ledgers.split(',')
|
||||
// Note: last_range can be in the form 'x-y' or just 'y'
|
||||
const last_range = ledger_ranges[ledger_ranges.length -1].split('-')
|
||||
const lr_min = parseInt(last_range[0])
|
||||
const lr_max = parseInt(last_range[last_range.length - 1])
|
||||
if (lr_min <= min_ledger && lr_max >= max_ledger) {
|
||||
// Server has ledger range needed.
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
ledger_listener = async (ledger) => {
|
||||
try {
|
||||
const tx_response = await api.request({
|
||||
"command": "tx",
|
||||
"transaction": tx_id,
|
||||
"min_ledger": min_ledger,
|
||||
"max_ledger": max_ledger
|
||||
})
|
||||
|
||||
if (tx_response.result.validated) {
|
||||
resolve(tx_response.result.meta.TransactionResult)
|
||||
} else if (ledger.ledger_index >= max_ledger) {
|
||||
api.off("ledgerClosed", ledger_listener)
|
||||
// Transaction found, not validated, but we should have a final result
|
||||
// by now.
|
||||
// Work around https://github.com/ripple/rippled/issues/3727
|
||||
if (await server_has_ledger_range(min_ledger, max_ledger)) {
|
||||
// Transaction should have been validated by now.
|
||||
reject({
|
||||
failure_final: true,
|
||||
msg: `Transaction not found in ledgers ${min_ledger}-${max_ledger}. This result is final if this range is correct.`
|
||||
})
|
||||
} else {
|
||||
reject({
|
||||
failure_final: false,
|
||||
msg: "Can't get final result (1). Check a full history server."
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// Transaction may still be validated later. Keep waiting.
|
||||
}
|
||||
} catch(e) {
|
||||
console.warn(e)
|
||||
if (e.data.error == "txnNotFound") {
|
||||
if (e.data.searched_all) {
|
||||
api.off("ledgerClosed", ledger_listener)
|
||||
reject({
|
||||
failure_final: true,
|
||||
msg: `Transaction not found in ledgers ${min_ledger}-${max_ledger}. This result is final if this range is correct.`
|
||||
})
|
||||
} else {
|
||||
if (max_ledger > ledger.ledger_index) {
|
||||
api.off("ledgerClosed", ledger_listener)
|
||||
// Transaction may yet be confirmed. This would not be a bad time
|
||||
// to resubmit the transaction just in case.
|
||||
} else {
|
||||
// Work around https://github.com/ripple/rippled/issues/3750
|
||||
if (await server_has_ledger_range(min_ledger, max_ledger)) {
|
||||
reject({
|
||||
failure_final: true,
|
||||
msg: `Transaction not found in ledgers ${min_ledger}-${max_ledger}. This result is final if this range is correct.`
|
||||
})
|
||||
} else {
|
||||
reject({
|
||||
failure_final: false,
|
||||
msg: "Can't get final result. Check a full history server."
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Unknown error; pass it back up
|
||||
reject({
|
||||
failure_final: false,
|
||||
msg: `Unknown Error: ${e}`
|
||||
})
|
||||
}
|
||||
}
|
||||
} // end ledger event handler
|
||||
api.on('ledgerClosed', ledger_listener)
|
||||
}) // end promise def
|
||||
}
|
||||
|
||||
|
||||
// Submit a transaction blob and get its final result as a string.
|
||||
// This can be one of these possibilities:
|
||||
// tesSUCCESS. The transaction executed successfully.
|
||||
// tec*. The transaction was validated with a failure code. It destroyed the XRP
|
||||
// transaction cost and may have done some cleanup such as removing
|
||||
// expired objects from the ledger, but nothing else.
|
||||
// See https://xrpl.org/tec-codes.html for the full list.
|
||||
// tefMAX_LEDGER. The transaction expired without ever being included
|
||||
// in a validated ledger.
|
||||
// unknown. Either the server you are querying does not have the
|
||||
// necessary ledger history to find the transaction's final result, or
|
||||
// something else went wrong when trying to look up the results. The
|
||||
// warning written to the console can tell you more about what happened.
|
||||
async function submit_and_verify(api, tx_blob) {
|
||||
// Make sure we subscribe to the ledger stream. This is idempotent so we don't
|
||||
// have to worry about oversubscribing.
|
||||
api.request({"command": "subscribe", "streams": ["ledger"]})
|
||||
const prelim = await api.request({"command": "submit", "tx_blob": tx_blob})
|
||||
console.log("Preliminary result code:", prelim.result.engine_result)
|
||||
const min_ledger = prelim.result.validated_ledger_index
|
||||
if (prelim.result.tx_json.LastLedgerSequence === undefined) {
|
||||
console.warn("Transaction has no LastLedgerSequence field. "+
|
||||
"It may be impossible to determine final failure.")
|
||||
}
|
||||
const max_ledger = prelim.result.tx_json.LastLedgerSequence
|
||||
const tx_id = prelim.result.tx_json.hash
|
||||
|
||||
let final_result
|
||||
try {
|
||||
final_result = await lookup_tx_final(api, tx_id, max_ledger, min_ledger)
|
||||
} catch(reason) {
|
||||
if (reason.failure_final) final_result = "tefMAX_LEDGER"
|
||||
else final_result = "unknown"
|
||||
console.warn(reason)
|
||||
}
|
||||
|
||||
return final_result;
|
||||
}
|
||||
|
||||
// Exports for node.js; no-op for browsers
|
||||
if (typeof module !== "undefined") {
|
||||
module.exports = {
|
||||
submit_and_verify: submit_and_verify,
|
||||
lookup_tx_final: lookup_tx_final
|
||||
}
|
||||
}
|
||||
@@ -128,10 +128,10 @@ $(document).ready(() => {
|
||||
|
||||
let flags = 0
|
||||
if ($("#cold-require-dest").prop("checked")) {
|
||||
flags |= xrpl.AccountSetTransactionFlags.tfRequireDestTag
|
||||
flags |= xrpl.AccountSetTfFlags.tfRequireDestTag
|
||||
}
|
||||
if ($("#cold-disallow-xrp").prop("checked")) {
|
||||
flags |= xrpl.AccountSetTransactionFlags.tfDisallowXRP
|
||||
flags |= xrpl.AccountSetTfFlags.tfDisallowXRP
|
||||
}
|
||||
|
||||
const tick_size = parseInt($("#cold-tick-size").val(), 10)
|
||||
@@ -153,10 +153,10 @@ $(document).ready(() => {
|
||||
try {
|
||||
const cold_settings_tx = {
|
||||
"TransactionType": "AccountSet",
|
||||
"Account": cold_wallet.classicAddress,
|
||||
"Account": cold_wallet.address,
|
||||
"TransferRate": transfer_rate,
|
||||
"TickSize": tick_size,
|
||||
"SetFlag": xrpl.AccountSetFlags.asfDefaultRipple,
|
||||
"SetFlag": xrpl.AccountSetAsfFlags.asfDefaultRipple,
|
||||
"Domain": domain,
|
||||
"Flags": flags
|
||||
}
|
||||
@@ -179,10 +179,10 @@ $(document).ready(() => {
|
||||
|
||||
let flags = 0
|
||||
if ($("#hot-require-dest").prop("checked")) {
|
||||
flags |= xrpl.AccountSetTransactionFlags.tfRequireDestTag
|
||||
flags |= xrpl.AccountSetTfFlags.tfRequireDestTag
|
||||
}
|
||||
if ($("#hot-disallow-xrp").prop("checked")) {
|
||||
flags |= xrpl.AccountSetTransactionFlags.tfDisallowXRP
|
||||
flags |= xrpl.AccountSetTfFlags.tfDisallowXRP
|
||||
}
|
||||
|
||||
const domain = $("#hot-domain-hex").text().trim()
|
||||
@@ -191,9 +191,9 @@ $(document).ready(() => {
|
||||
try {
|
||||
const hot_settings_tx = {
|
||||
"TransactionType": "AccountSet",
|
||||
"Account": hot_wallet.classicAddress,
|
||||
"Account": hot_wallet.address,
|
||||
// Require Auth so we can't accidentally issue from the hot address
|
||||
"SetFlag": xrpl.AccountSetFlags.asfRequireAuth,
|
||||
"SetFlag": xrpl.AccountSetAsfFlags.asfRequireAuth,
|
||||
"Domain": domain,
|
||||
"Flags": flags
|
||||
}
|
||||
@@ -211,7 +211,7 @@ $(document).ready(() => {
|
||||
$("#create-trust-line-button").click( async (event) => {
|
||||
const block = $(event.target).closest(".interactive-block")
|
||||
block.find(".output-area").empty()
|
||||
const cold_address = get_wallet_2(event, "cold").classicAddress
|
||||
const cold_address = get_wallet_2(event, "cold").address
|
||||
const hot_wallet = get_wallet_2(event, "hot")
|
||||
|
||||
let currency_code
|
||||
@@ -234,7 +234,7 @@ $(document).ready(() => {
|
||||
try {
|
||||
const trust_set_tx = {
|
||||
"TransactionType": "TrustSet",
|
||||
"Account": hot_wallet.classicAddress,
|
||||
"Account": hot_wallet.address,
|
||||
"LimitAmount": {
|
||||
"currency": currency_code,
|
||||
"issuer": cold_address,
|
||||
@@ -254,7 +254,7 @@ $(document).ready(() => {
|
||||
$("#send-token-button").click( async (event) => {
|
||||
const block = $(event.target).closest(".interactive-block")
|
||||
block.find(".output-area").empty()
|
||||
const hot_address = get_wallet_2(event, "hot").classicAddress
|
||||
const hot_address = get_wallet_2(event, "hot").address
|
||||
const cold_wallet = get_wallet_2(event, "cold")
|
||||
|
||||
const currency_code = $("#send-currency-code").text().trim()
|
||||
@@ -274,11 +274,11 @@ $(document).ready(() => {
|
||||
try {
|
||||
const send_token_tx = {
|
||||
"TransactionType": "Payment",
|
||||
"Account": cold_wallet.classicAddress,
|
||||
"Account": cold_wallet.address,
|
||||
"Amount": {
|
||||
"currency": currency_code,
|
||||
"value": issue_quantity,
|
||||
"issuer": cold_wallet.classicAddress
|
||||
"issuer": cold_wallet.address
|
||||
},
|
||||
"Destination": hot_address
|
||||
}
|
||||
@@ -299,8 +299,8 @@ $(document).ready(() => {
|
||||
$("#confirm-balances-button").click( async (event) => {
|
||||
const block = $(event.target).closest(".interactive-block")
|
||||
block.find(".output-area").empty()
|
||||
const hot_address = get_wallet_2(event, "hot").classicAddress
|
||||
const cold_address = get_wallet_2(event, "cold").classicAddress
|
||||
const hot_address = get_wallet_2(event, "hot").address
|
||||
const cold_address = get_wallet_2(event, "cold").address
|
||||
|
||||
block.find(".loader").show()
|
||||
try {
|
||||
|
||||
@@ -66,7 +66,7 @@ $(document).ready(() => {
|
||||
let seed = block.data("testSendSecret")
|
||||
if (!seed) {
|
||||
console.debug("First-time setup for test sender...")
|
||||
test_sender_wallet = await api.generateFaucetWallet()
|
||||
test_sender_wallet = (await api.fundWallet()).wallet
|
||||
block.data("testSendSecret", test_sender_wallet.seed)
|
||||
|
||||
// First time: Wait for our test sender to be fully funded, so we don't
|
||||
@@ -75,7 +75,7 @@ $(document).ready(() => {
|
||||
try {
|
||||
await api.request({
|
||||
"command": "account_info",
|
||||
"account": test_sender_wallet.classicAddress,
|
||||
"account": test_sender_wallet.address,
|
||||
"ledger_index": "validated"
|
||||
})
|
||||
break
|
||||
@@ -101,7 +101,7 @@ $(document).ready(() => {
|
||||
const test_sender = await get_test_sender(block)
|
||||
const tx_json = {
|
||||
"TransactionType": "Payment",
|
||||
"Account": test_sender.classicAddress,
|
||||
"Account": test_sender.address,
|
||||
"Amount": "3152021",
|
||||
"Destination": address
|
||||
}
|
||||
@@ -111,15 +111,14 @@ $(document).ready(() => {
|
||||
}
|
||||
|
||||
const prepared = await api.autofill(tx_json)
|
||||
const tx_blob = test_sender.signTransaction(prepared)
|
||||
const {tx_blob, hash} = test_sender.sign(prepared)
|
||||
console.debug("Submitting test payment", prepared)
|
||||
const prelim = await api.request({"command": "submit", tx_blob})
|
||||
const tx_hash = xrpl.computeSignedTransactionHash(tx_blob)
|
||||
|
||||
block.find(".loader").hide()
|
||||
block.find(".output-area").append(`<p>${tx_json.TransactionType}
|
||||
${prepared.Sequence} ${(dt?"WITH":"WITHOUT")} Dest. Tag:
|
||||
<a href="https://testnet.xrpl.org/transactions/${tx_hash}"
|
||||
<a href="https://testnet.xrpl.org/transactions/${hash}"
|
||||
target="_blank">${prelim.result.engine_result}</a></p>`)
|
||||
} catch(err) {
|
||||
block.find(".loader").hide()
|
||||
|
||||
@@ -44,13 +44,12 @@ $("#sign-button").click( function(event) {
|
||||
const wallet = get_wallet(event)
|
||||
if (!wallet) {return}
|
||||
|
||||
signed = wallet.signTransaction(preparedTxJSON)
|
||||
hash = xrpl.computeSignedTransactionHash(signed) // TODO: update if computeSignedTransactionHash changes
|
||||
{tx_blob, hash} = wallet.sign(preparedTxJSON)
|
||||
|
||||
block.find(".output-area").html(
|
||||
`<div><strong>Signed Transaction blob:</strong>
|
||||
<code id='signed-tx-blob' style='overflow-wrap: anywhere; word-wrap: anywhere'
|
||||
>${signed}</code></div>
|
||||
>${tx_blob}</code></div>
|
||||
<div><strong>Identifying hash:</strong> <span id='signed-tx-hash'
|
||||
>${hash}</span></div>`
|
||||
)
|
||||
|
||||
@@ -49,9 +49,9 @@ $("#prepare-and-sign").click( async function(event) {
|
||||
}
|
||||
|
||||
const vli = await api.getLedgerIndex()
|
||||
let prepared = await api.autofill({
|
||||
const prepared = await api.autofill({
|
||||
"TransactionType": "TicketCreate",
|
||||
"Account": wallet.classicAddress,
|
||||
"Account": wallet.address,
|
||||
"TicketCount": 10,
|
||||
"Sequence": current_sequence,
|
||||
"LastLedgerSequence": vli+LLS_OFFSET
|
||||
@@ -61,10 +61,9 @@ $("#prepare-and-sign").click( async function(event) {
|
||||
`<p>Prepared transaction:</p>
|
||||
<pre><code>${pretty_print(prepared)}</code></pre>`)
|
||||
|
||||
let tx_blob = wallet.signTransaction(prepared)
|
||||
let tx_id = xrpl.computeSignedTransactionHash(tx_blob)
|
||||
const {tx_blob, hash} = wallet.sign(prepared)
|
||||
block.find(".output-area").append(
|
||||
`<p>Transaction hash: <code id="tx_id">${tx_id}</code></p>`)
|
||||
`<p>Transaction hash: <code id="tx_id">${hash}</code></p>`)
|
||||
block.find(".output-area").append(
|
||||
`<p>Signed blob:</p><pre class="tx-blob"><code id="tx_blob">${tx_blob}</code></pre>`)
|
||||
|
||||
@@ -84,16 +83,15 @@ async function intermission_submit(event, tx_json) {
|
||||
const wallet = get_wallet(event)
|
||||
if (!wallet) {return}
|
||||
const prepared = await api.autofill(tx_json)
|
||||
const tx_blob = wallet.signTransaction(prepared)
|
||||
const {tx_blob, hash} = wallet.sign(prepared)
|
||||
const prelim = await api.request({
|
||||
"command": "submit",
|
||||
"tx_blob": tx_blob
|
||||
})
|
||||
const tx_id = xrpl.computeSignedTransactionHash(tx_blob)
|
||||
|
||||
block.find(".output-area").append(`<p>${prepared.TransactionType}
|
||||
${prepared.Sequence}:
|
||||
<a href="https://devnet.xrpl.org/transactions/${tx_id}"
|
||||
<a href="https://devnet.xrpl.org/transactions/${hash}"
|
||||
target="_blank">${prelim.result.engine_result}</a></p>`)
|
||||
}
|
||||
|
||||
@@ -187,7 +185,7 @@ $("#prepare-ticketed-tx").click(async function(event) {
|
||||
|
||||
const prepared_t = await api.autofill({
|
||||
"TransactionType": "AccountSet",
|
||||
"Account": wallet.classicAddress,
|
||||
"Account": wallet.address,
|
||||
"TicketSequence": use_ticket,
|
||||
"Sequence": 0,
|
||||
"LastLedgerSequence": vli+LLS_OFFSET
|
||||
@@ -197,14 +195,13 @@ $("#prepare-ticketed-tx").click(async function(event) {
|
||||
`<p>Prepared transaction:</p>
|
||||
<pre><code>${pretty_print(prepared_t)}</code></pre>`)
|
||||
|
||||
const tx_blob_t = wallet.signTransaction(prepared_t)
|
||||
const tx_id_t = xrpl.computeSignedTransactionHash(tx_blob_t)
|
||||
const {tx_blob, hash} = wallet.sign(prepared_t)
|
||||
block.find(".output-area").append(
|
||||
`<p>Transaction hash: <code id="tx_id_t">${tx_id_t}</code></p>`)
|
||||
`<p>Transaction hash: <code id="tx_id_t">${hash}</code></p>`)
|
||||
|
||||
block.find(".output-area").append(
|
||||
`<pre style="visibility: none">
|
||||
<code id="tx_blob_t">${tx_blob_t}</code></pre>`)
|
||||
<code id="tx_blob_t">${tx_blob}</code></pre>`)
|
||||
|
||||
// Update breadcrumbs & activate next step
|
||||
complete_step("Prepare Ticketed Tx")
|
||||
|
||||
@@ -47,7 +47,7 @@ const set_up_tx_sender = async function() {
|
||||
api = new xrpl.Client(TESTNET_URL)
|
||||
|
||||
let sending_wallet
|
||||
let xrp_balance
|
||||
let xrp_balance = "TBD"
|
||||
|
||||
function enable_buttons_if_ready() {
|
||||
if ( (typeof sending_wallet) === "undefined") {
|
||||
@@ -72,17 +72,18 @@ const set_up_tx_sender = async function() {
|
||||
|
||||
console.debug("Getting a sending address from the faucet...")
|
||||
try {
|
||||
sending_wallet = await api.generateFaucetWallet()
|
||||
const fund_response = await api.fundWallet()
|
||||
sending_wallet = fund_response.wallet
|
||||
xrp_balance = xrpl.dropsToXrp(fund_response.balance)
|
||||
} catch(error) {
|
||||
console.error(error)
|
||||
errorNotif("There was an error with the XRP Ledger Testnet Faucet. Reload this page to try again.")
|
||||
return
|
||||
}
|
||||
|
||||
xrp_balance = "TBD" // TODO old faucet command gave balance, new doesn't
|
||||
$("#balance-item").text(xrp_balance)
|
||||
|
||||
$(".sending-address-item").text(sending_wallet.classicAddress)
|
||||
$(".sending-address-item").text(sending_wallet.address)
|
||||
$("#init_button").prop("disabled", "disabled")
|
||||
$("#init_button").addClass("disabled")
|
||||
$("#init_button").attr("title", "Done")
|
||||
@@ -112,10 +113,11 @@ const set_up_tx_sender = async function() {
|
||||
}
|
||||
|
||||
async function update_xrp_balance() {
|
||||
balances = await api.getBalances(sending_wallet.classicAddress, {currency: "XRP"})
|
||||
balances = await api.getBalances(sending_wallet.address, {currency: "XRP"})
|
||||
$("#balance-item").text(balances[0].value)
|
||||
}
|
||||
|
||||
|
||||
async function submit_and_notify(tx_object, use_wallet, silent) {
|
||||
if (use_wallet === undefined) {
|
||||
use_wallet = sending_wallet
|
||||
@@ -132,31 +134,9 @@ const set_up_tx_sender = async function() {
|
||||
return
|
||||
}
|
||||
|
||||
// Determine first and last ledger the tx could be validated in *BEFORE*
|
||||
// signing it.
|
||||
min_ledger = await api.getLedgerIndex()
|
||||
max_ledger = prepared.LastLedgerSequence
|
||||
|
||||
|
||||
let signed
|
||||
try {
|
||||
// Sign, submit
|
||||
signed = use_wallet.signTransaction(prepared)
|
||||
await api.request({"command": "submit", "tx_blob": signed})
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
if (!silent) {
|
||||
errorNotif(`Error signing & submitting ${tx_object.TransactionType} tx: ${error}`)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Wait for tx to be in a validated ledger or to expire
|
||||
const hash = xrpl.computeSignedTransactionHash(signed)
|
||||
|
||||
try {
|
||||
// use lookup_tx_final() from submit-and-verify2.js
|
||||
let final_result_data = await lookup_tx_final(api, hash, max_ledger, min_ledger)
|
||||
const {tx_blob, hash} = use_wallet.sign(prepared)
|
||||
const final_result_data = await api.submitSignedReliable(tx_blob)
|
||||
console.log("final_result_data is", final_result_data)
|
||||
let final_result = final_result_data.result.meta.TransactionResult
|
||||
if (!silent) {
|
||||
@@ -169,12 +149,13 @@ const set_up_tx_sender = async function() {
|
||||
logTx(tx_object.TransactionType, hash, final_result)
|
||||
}
|
||||
update_xrp_balance()
|
||||
return data
|
||||
} catch(error) {
|
||||
return final_result_data
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
if (!silent) {
|
||||
errorNotif("Error submitting "+tx_object.TransactionType+" tx: "+error)
|
||||
errorNotif(`Error signing & submitting ${tx_object.TransactionType} tx: ${error}`)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
@@ -196,32 +177,19 @@ const set_up_tx_sender = async function() {
|
||||
$("#pp_progress .progress-bar").addClass("progress-bar-animated")
|
||||
// 1. Get a funded address to use as issuer
|
||||
try {
|
||||
pp_issuer_wallet = await api.generateFaucetWallet()
|
||||
const fund_response = await api.fundWallet()
|
||||
pp_issuer_wallet = fund_response.wallet
|
||||
} catch(error) {
|
||||
console.log("Error getting issuer address for partial payments:", error)
|
||||
return
|
||||
}
|
||||
$("#pp_progress .progress-bar").width("20%")
|
||||
|
||||
// Wait for the address's funding to be validated so we don't get the wrong
|
||||
// starting sequence number.
|
||||
while (true) {
|
||||
try {
|
||||
await new Promise(resolve => setTimeout(resolve, 1000))
|
||||
await api.request({
|
||||
command: "account_info",
|
||||
account: pp_issuer_wallet.classicAddress,
|
||||
ledger_index: "validated"
|
||||
})
|
||||
break
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
// 2. Set Default Ripple on issuer
|
||||
let resp = await submit_and_notify({
|
||||
TransactionType: "AccountSet",
|
||||
Account: pp_issuer_wallet.classicAddress,
|
||||
SetFlag: 8
|
||||
Account: pp_issuer_wallet.address,
|
||||
SetFlag: xrpl.AccountSetAsfFlags.asfDefaultRipple
|
||||
}, pp_issuer_wallet, true)
|
||||
if (resp === undefined) {
|
||||
console.log("Couldn't set Default Ripple for partial payment issuer")
|
||||
@@ -232,11 +200,11 @@ const set_up_tx_sender = async function() {
|
||||
// 3. Make a trust line from sending address to issuer
|
||||
resp = await submit_and_notify({
|
||||
TransactionType: "TrustSet",
|
||||
Account: sending_wallet.classicAddress,
|
||||
Account: sending_wallet.address,
|
||||
LimitAmount: {
|
||||
currency: pp_sending_currency,
|
||||
value: "1000000000", // arbitrarily, 1 billion fake currency
|
||||
issuer: pp_issuer_wallet.classicAddress
|
||||
issuer: pp_issuer_wallet.address
|
||||
}
|
||||
}, sending_wallet, true)
|
||||
if (resp === undefined) {
|
||||
@@ -248,12 +216,12 @@ const set_up_tx_sender = async function() {
|
||||
// 4. Issue fake currency to main sending address
|
||||
resp = await submit_and_notify({
|
||||
TransactionType: "Payment",
|
||||
Account: pp_issuer_wallet.classicAddress,
|
||||
Destination: sending_wallet.classicAddress,
|
||||
Account: pp_issuer_wallet.address,
|
||||
Destination: sending_wallet.address,
|
||||
Amount: {
|
||||
currency: pp_sending_currency,
|
||||
value: "1000000000",
|
||||
issuer: pp_issuer_wallet.classicAddress
|
||||
issuer: pp_issuer_wallet.address
|
||||
}
|
||||
}, pp_issuer_wallet, true)
|
||||
if (resp === undefined) {
|
||||
@@ -267,12 +235,12 @@ const set_up_tx_sender = async function() {
|
||||
// so they end up paying themselves issued currency then delivering XRP.
|
||||
resp = await submit_and_notify({
|
||||
TransactionType: "OfferCreate",
|
||||
Account: sending_wallet.classicAddress,
|
||||
Account: sending_wallet.address,
|
||||
TakerGets: "1000000000000000", // 1 billion XRP
|
||||
TakerPays: {
|
||||
currency: pp_sending_currency,
|
||||
value: "1000000000",
|
||||
issuer: pp_issuer_wallet.classicAddress
|
||||
issuer: pp_issuer_wallet.address
|
||||
}
|
||||
}, sending_wallet, true)
|
||||
if (resp === undefined) {
|
||||
@@ -295,7 +263,7 @@ const set_up_tx_sender = async function() {
|
||||
// Destination Address box -----------------------------------------------
|
||||
async function on_dest_address_update(event) {
|
||||
const d_a = $("#destination_address").val()
|
||||
if (api.isValidClassicAddress(d_a) || api.isValidXAddress(d_a)) { // TODO: switch back to isValidAddress
|
||||
if (xrpl.isValidAddress(d_a)) {
|
||||
$("#destination_address").addClass("is-valid").removeClass("is-invalid")
|
||||
if (d_a[0] == "X") {
|
||||
$("#x-address-warning").show()
|
||||
@@ -323,7 +291,7 @@ const set_up_tx_sender = async function() {
|
||||
$("#send_xrp_payment button").prop("disabled","disabled")
|
||||
await submit_and_notify({
|
||||
TransactionType: "Payment",
|
||||
Account: sending_wallet.classicAddress,
|
||||
Account: sending_wallet.address,
|
||||
Destination: destination_address,
|
||||
Amount: xrp_drops_input
|
||||
})
|
||||
@@ -341,17 +309,16 @@ const set_up_tx_sender = async function() {
|
||||
|
||||
await submit_and_notify({
|
||||
TransactionType: "Payment",
|
||||
Account: sending_wallet.classicAddress,
|
||||
Account: sending_wallet.address,
|
||||
Destination: destination_address,
|
||||
Amount: "1000000000000000", // 1 billion XRP
|
||||
SendMax: {
|
||||
value: (Math.random()*.01).toPrecision(15), // random very small amount
|
||||
currency: pp_sending_currency,
|
||||
issuer: pp_issuer_wallet.classicAddress
|
||||
issuer: pp_issuer_wallet.address
|
||||
},
|
||||
Flags: api.txFlags.Payment.PartialPayment | api.txFlags.Universal.FullyCanonicalSig
|
||||
Flags: xrpl.PaymentFlags.tfPartialPayment
|
||||
})
|
||||
// TODO: follow txFlags wherever they get moved to
|
||||
$("#send_partial_payment .loader").hide()
|
||||
$("#send_partial_payment button").prop("disabled",false)
|
||||
}
|
||||
@@ -375,13 +342,13 @@ const set_up_tx_sender = async function() {
|
||||
$("#create_escrow button").prop("disabled","disabled")
|
||||
const escrowcreate_tx_data = await submit_and_notify({
|
||||
TransactionType: "EscrowCreate",
|
||||
Account: sending_wallet.classicAddress,
|
||||
Account: sending_wallet.address,
|
||||
Destination: destination_address,
|
||||
Amount: "1000000",
|
||||
FinishAfter: finish_after
|
||||
})
|
||||
|
||||
if (release_auto) {
|
||||
if (escrowcreate_tx_data && release_auto) {
|
||||
// Wait until there's a ledger with a close time > FinishAfter
|
||||
// to submit the EscrowFinish
|
||||
$("#escrow_progress .progress-bar").width("0%").addClass("progress-bar-animated")
|
||||
@@ -414,10 +381,10 @@ const set_up_tx_sender = async function() {
|
||||
// Future feature: submit from a different sender, just to prove that
|
||||
// escrows can be finished by a third party
|
||||
await submit_and_notify({
|
||||
Account: sending_wallet.classicAddress,
|
||||
Account: sending_wallet.address,
|
||||
TransactionType: "EscrowFinish",
|
||||
Owner: sending_wallet.classicAddress,
|
||||
OfferSequence: escrowcreate_tx_data.sequence
|
||||
Owner: sending_wallet.address,
|
||||
OfferSequence: escrowcreate_tx_data.result.Sequence
|
||||
})
|
||||
}
|
||||
$("#create_escrow .loader").hide()
|
||||
@@ -434,7 +401,7 @@ const set_up_tx_sender = async function() {
|
||||
$("#create_payment_channel button").prop("disabled","disabled")
|
||||
await submit_and_notify({
|
||||
TransactionType: "PaymentChannelCreate",
|
||||
Account: sending_wallet.classicAddress,
|
||||
Account: sending_wallet.address,
|
||||
Destination: destination_address,
|
||||
Amount: xrp_drops_input,
|
||||
SettleDelay: 30,
|
||||
@@ -459,12 +426,12 @@ const set_up_tx_sender = async function() {
|
||||
// Future feature: cross-currency sending with paths?
|
||||
await submit_and_notify({
|
||||
TransactionType: "Payment",
|
||||
Account: sending_wallet.classicAddress,
|
||||
Account: sending_wallet.address,
|
||||
Destination: destination_address,
|
||||
Amount: {
|
||||
"currency": issue_code,
|
||||
"value": issue_amount,
|
||||
"issuer": sending_wallet.classicAddress
|
||||
"issuer": sending_wallet.address
|
||||
}
|
||||
})
|
||||
$("#send_issued_currency .loader").hide()
|
||||
@@ -481,7 +448,7 @@ const set_up_tx_sender = async function() {
|
||||
$("#trust_for button").prop("disabled","disabled")
|
||||
await submit_and_notify({
|
||||
TransactionType: "TrustSet",
|
||||
Account: sending_wallet.classicAddress,
|
||||
Account: sending_wallet.address,
|
||||
LimitAmount: {
|
||||
currency: trust_currency_code,
|
||||
value: trust_limit,
|
||||
|
||||
Reference in New Issue
Block a user