mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-27 23:25:51 +00:00
xrpl.js 2.0: start migrating code (incomplete)
This commit is contained in:
2
assets/js/ripple-lib-1.10.0.min.js
vendored
2
assets/js/ripple-lib-1.10.0.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,3 +1,5 @@
|
||||
const xrpl = ripple; // TODO: remove when webpack build is updated
|
||||
|
||||
jQuery(function ($) {
|
||||
const FULL_HISTORY_SERVER = "wss://s2.ripple.com"
|
||||
const reTxId = /^[0-9A-Fa-f]{64}$/
|
||||
@@ -7,11 +9,13 @@ jQuery(function ($) {
|
||||
let currentMarker
|
||||
let nextMarker
|
||||
|
||||
const api = new ripple.RippleAPI({server: FULL_HISTORY_SERVER})
|
||||
const api = new xrpl.Client(FULL_HISTORY_SERVER)
|
||||
|
||||
api.on('connected', () => {
|
||||
const target = location.hash.slice(1);
|
||||
if (api.isValidAddress(target) ||
|
||||
// TODO: switch back to isValidAddress
|
||||
if (api.isValidClassicAddress(target) ||
|
||||
api.isValidXAddress(target) ||
|
||||
reTxId.exec(target) ||
|
||||
reLedgerSeq.exec(target)) {
|
||||
$('#target').val(target);
|
||||
@@ -45,7 +49,8 @@ jQuery(function ($) {
|
||||
$("#permalink").attr("href", locationWithoutHash + "#" + target);
|
||||
$("#explorerlink").attr("href", ""); // Reset
|
||||
|
||||
if (api.isValidAddress(target)) { // Account -------------------------------
|
||||
// TODO: switch back to isValidAddress()
|
||||
if (api.isValidClassicAddress(target)) { // Account -------------------------------
|
||||
let account = target;
|
||||
previousMarkers = []
|
||||
nextMarker = undefined
|
||||
@@ -57,20 +62,23 @@ jQuery(function ($) {
|
||||
$("#progress .progress-bar").css("width", "10%");
|
||||
|
||||
try {
|
||||
let result = await api.request("account_info", {account})
|
||||
$("#progress .progress-bar").css("width", "20%");
|
||||
console.log('account_info', result);
|
||||
format(result, $("#account_info"));
|
||||
let command = "account_info"
|
||||
let result = await api.request({command, account})
|
||||
$("#progress .progress-bar").css("width", "20%")
|
||||
console.log('account_info', result)
|
||||
format(result, $("#account_info"))
|
||||
|
||||
result = await api.request("account_lines", {account})
|
||||
$("#progress .progress-bar").css("width", "40%");
|
||||
console.log('account_lines', result);
|
||||
format(result, $("#account_lines"));
|
||||
command = "account_lines"
|
||||
result = await api.request({command, account})
|
||||
$("#progress .progress-bar").css("width", "40%")
|
||||
console.log('account_lines', result)
|
||||
format(result, $("#account_lines"))
|
||||
|
||||
result = await pagedAccountTx(account);
|
||||
$("#progress .progress-bar").css("width", "60%");
|
||||
|
||||
result = await api.request("account_objects", {account})
|
||||
command = "account_objects"
|
||||
result = await api.request({command, account})
|
||||
$("#progress .progress-bar").css("width", "80%");
|
||||
console.log('account_objects', result);
|
||||
format(result, $("#account_objects"));
|
||||
@@ -92,7 +100,8 @@ jQuery(function ($) {
|
||||
|
||||
$("#progress .progress-bar").css("width", "10%");
|
||||
try {
|
||||
let result = await api.request("ledger", {
|
||||
let result = await api.request({
|
||||
command: "ledger",
|
||||
ledger_index: target,
|
||||
transactions: true,
|
||||
expand: true
|
||||
@@ -114,7 +123,8 @@ jQuery(function ($) {
|
||||
|
||||
try {
|
||||
$("#progress .progress-bar").css("width", "10%");
|
||||
let result = await api.request("tx", {
|
||||
let result = await api.request({
|
||||
command: "tx",
|
||||
transaction: target,
|
||||
binary: false
|
||||
})
|
||||
@@ -229,6 +239,7 @@ jQuery(function ($) {
|
||||
|
||||
async function pagedAccountTx(account, page) {
|
||||
let opts = {
|
||||
"command": "account_tx",
|
||||
"account": account,
|
||||
"ledger_index_min": -1,
|
||||
"ledger_index_max": -1,
|
||||
@@ -251,7 +262,7 @@ jQuery(function ($) {
|
||||
currentMarker = opts["marker"]
|
||||
}
|
||||
|
||||
let result = await api.request("account_tx", opts)
|
||||
let result = await api.request(opts)
|
||||
console.log('account_tx', result)
|
||||
format(result, $("#account_tx").empty())
|
||||
updateTxMarkerNav(result)
|
||||
|
||||
176
assets/js/submit-and-verify2.js
Normal file
176
assets/js/submit-and-verify2.js
Normal file
@@ -0,0 +1,176 @@
|
||||
// Submit-and-verify XRPL transaction using ripple-lib (v1.x)
|
||||
// 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 RippleAPI instance connected to the network where you
|
||||
// submitted the transaction.
|
||||
// @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]
|
||||
}
|
||||
|
||||
// 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.info.complete_ledgers}`)
|
||||
if (si.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.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 {
|
||||
tx_result = await api.request({
|
||||
"command": "tx",
|
||||
"transaction": tx_id,
|
||||
"min_ledger": min_ledger,
|
||||
"max_ledger": max_ledger
|
||||
})
|
||||
|
||||
if (tx_result.validated) {
|
||||
resolve(tx_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) {
|
||||
const prelim_result = 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
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,23 @@
|
||||
const xrpl = ripple; // TODO: remove when webpack build is updated
|
||||
|
||||
async function wait_for_seq(network_url, address) {
|
||||
const api = new ripple.RippleAPI({server: network_url})
|
||||
const api = new xrpl.Client(network_url)
|
||||
await api.connect()
|
||||
let result;
|
||||
let response;
|
||||
while (true) {
|
||||
try {
|
||||
result = await api.request("account_info", {account: address, ledger_index: "validated"})
|
||||
response = await api.request({
|
||||
command: "account_info",
|
||||
account: address,
|
||||
ledger_index: "validated"
|
||||
})
|
||||
break
|
||||
} catch(e) {
|
||||
await new Promise(resolve => setTimeout(resolve, 1000))
|
||||
}
|
||||
}
|
||||
$("#sequence").html('<h3>Sequence Number</h3> '+result.account_data.Sequence)
|
||||
console.log(response)
|
||||
$("#sequence").html('<h3>Sequence Number</h3> '+response.result.account_data.Sequence)
|
||||
api.disconnect()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
const xrpl = ripple; // TODO: remove when webpack build is updated
|
||||
|
||||
const set_up_tx_sender = async function() {
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Notification helpers
|
||||
@@ -44,13 +46,13 @@ const set_up_tx_sender = async function() {
|
||||
const TESTNET_URL = "wss://s.altnet.rippletest.net:51233"
|
||||
|
||||
let connection_ready = false
|
||||
api = new xrpl.Client(TESTNET_URL)
|
||||
|
||||
let sending_address
|
||||
let sending_secret
|
||||
let sending_wallet
|
||||
let xrp_balance
|
||||
|
||||
function enable_buttons_if_ready() {
|
||||
if ( (typeof sending_address) === "undefined") {
|
||||
if ( (typeof sending_wallet) === "undefined") {
|
||||
console.debug("No sending address yet...")
|
||||
return false
|
||||
}
|
||||
@@ -66,37 +68,29 @@ const set_up_tx_sender = async function() {
|
||||
return true
|
||||
}
|
||||
|
||||
$("#init_button").click(async (evt) => {
|
||||
console.log("Connecting to Testnet WebSocket...")
|
||||
await api.connect()
|
||||
|
||||
faucet_response = function(data) {
|
||||
sending_address = data.account.address
|
||||
sending_secret = data.account.secret
|
||||
xrp_balance = Number(data.balance) // Faucet only delivers ~10,000 XRP,
|
||||
// so this won't go over JavaScript's
|
||||
// 64-bit double precision
|
||||
console.debug("Getting a sending address from the faucet...")
|
||||
try {
|
||||
sending_wallet = await api.generateFaucetWallet()
|
||||
} catch(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_address)
|
||||
|
||||
$(".sending-address-item").text(sending_wallet.classicAddress)
|
||||
$("#init_button").prop("disabled", "disabled")
|
||||
$("#init_button").addClass("disabled")
|
||||
$("#init_button").attr("title", "Done")
|
||||
$("#init_button").append(' <i class="fa fa-check-circle"></i>')
|
||||
enable_buttons_if_ready()
|
||||
}
|
||||
|
||||
$("#init_button").click((evt) => {
|
||||
console.debug("Getting a sending address from the faucet...")
|
||||
$.ajax({
|
||||
url: FAUCET_URL,
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
success: faucet_response,
|
||||
error: function() {
|
||||
errorNotif("There was an error with the XRP Ledger Testnet Faucet. Reload this page to try again.")
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
api = new ripple.RippleAPI({server: TESTNET_URL})
|
||||
api.on('connected', () => {
|
||||
connection_ready = true
|
||||
$("#connection-status-item").text("Connected")
|
||||
@@ -108,8 +102,6 @@ const set_up_tx_sender = async function() {
|
||||
$("#connection-status-item").text("Not connected")
|
||||
$("#connection-status-item").removeClass("active").addClass("disabled")
|
||||
})
|
||||
console.log("Connecting to Testnet WebSocket...")
|
||||
api.connect()
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Generic Transaction Submission
|
||||
@@ -120,37 +112,18 @@ const set_up_tx_sender = async function() {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
const INTERVAL = 1000 // milliseconds to wait for new ledger versions
|
||||
async function verify_transaction(hash, options) {
|
||||
try {
|
||||
data = await api.getTransaction(hash, options)
|
||||
return data
|
||||
} catch(error) {
|
||||
/* If transaction not in latest validated ledger,
|
||||
try again until max ledger hit */
|
||||
if (error instanceof api.errors.PendingLedgerVersionError) {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => verify_transaction(hash, options)
|
||||
.then(resolve, reject), INTERVAL)
|
||||
})
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function update_xrp_balance() {
|
||||
balances = await api.getBalances(sending_address, {currency: "XRP"})
|
||||
balances = await api.getBalances(sending_wallet.classicAddress, {currency: "XRP"})
|
||||
$("#balance-item").text(balances[0].value)
|
||||
}
|
||||
|
||||
async function submit_and_verify(tx_object, use_secret, silent) {
|
||||
if (use_secret === undefined) {
|
||||
use_secret = sending_secret
|
||||
async function submit_and_notify(tx_object, use_wallet, silent) {
|
||||
if (use_wallet === undefined) {
|
||||
use_wallet = sending_wallet
|
||||
}
|
||||
try {
|
||||
// Auto-fill fields like Fee and Sequence
|
||||
prepared = await api.prepareTransaction(tx_object)
|
||||
prepared = await api.autofill(tx_object)
|
||||
console.debug("Prepared:", prepared)
|
||||
} catch(error) {
|
||||
console.log(error)
|
||||
@@ -162,40 +135,38 @@ const set_up_tx_sender = async function() {
|
||||
|
||||
// Determine first and last ledger the tx could be validated in *BEFORE*
|
||||
// signing it.
|
||||
const options = {
|
||||
minLedgerVersion: (await api.getLedger()).ledgerVersion,
|
||||
maxLedgerVersion: prepared.instructions.maxLedgerVersion
|
||||
}
|
||||
min_ledger = (await api.request({"command": "ledger", "ledger_index": "validated"})).result.ledger.ledger_index, // TODO: change to a simpler way when xrpl.js supports it
|
||||
max_ledger = prepared.LastLedgerSequence
|
||||
|
||||
let sign_response
|
||||
|
||||
let signed
|
||||
try {
|
||||
// Sign, submit
|
||||
sign_response = api.sign(prepared.txJSON, use_secret)
|
||||
await api.submit(sign_response.signedTransaction)
|
||||
signed = use_wallet.sign(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)
|
||||
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.computeBinaryTransactionSigningHash(signed)
|
||||
|
||||
try {
|
||||
const data = await verify_transaction(sign_response.id, options)
|
||||
const final_result = data.outcome.result
|
||||
// Future feature: output should link to a TestNet tx lookup/explainer
|
||||
if (final_result === "tesSUCCESS") {
|
||||
if (!silent) {
|
||||
successNotif(tx_object.TransactionType+" tx succeeded (hash: "+sign_response.id+")")
|
||||
logTx(tx_object.TransactionType, sign_response.id, final_result)
|
||||
}
|
||||
} else {
|
||||
if (!silent) {
|
||||
errorNotif(tx_object.TransactionType+" tx failed w/ code "+final_result+
|
||||
" (hash: "+sign_response.id+")")
|
||||
logTx(tx_object.TransactionType, sign_response.id, final_result)
|
||||
// use lookup_tx_final() from submit-and-verify2.js
|
||||
let final_result_data = await lookup_tx_final(api, tx_id, max_ledger, min_ledger)
|
||||
let final_result = final_result_data.meta.TransactionResult
|
||||
if (!silent) {
|
||||
if (final_result === "tesSUCCESS") {
|
||||
successNotif(`${tx_object.TransactionType} tx succeeded (hash: ${hash})`)
|
||||
} else {
|
||||
errorNotif(`${tx_object.TransactionType} tx failed w/ code ${final_result}
|
||||
(hash: ${hash})`)
|
||||
}
|
||||
logTx(tx_object.TransactionType, hash, final_result)
|
||||
}
|
||||
update_xrp_balance()
|
||||
return data
|
||||
@@ -214,7 +185,7 @@ const set_up_tx_sender = async function() {
|
||||
// an issuer for a fake currency to ripple through.)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
let pp_issuer_address
|
||||
let pp_issuer_wallet
|
||||
let pp_sending_currency = "BAR"
|
||||
async function set_up_for_partial_payments() {
|
||||
while (!connection_ready) {
|
||||
@@ -224,15 +195,8 @@ const set_up_tx_sender = async function() {
|
||||
console.debug("Starting partial payment setup...")
|
||||
$("#pp_progress .progress-bar").addClass("progress-bar-animated")
|
||||
// 1. Get a funded address to use as issuer
|
||||
let pp_issuer_secret
|
||||
try {
|
||||
const faucet_response = await ($.ajax({
|
||||
url: FAUCET_URL,
|
||||
type: 'POST',
|
||||
dataType: 'json'
|
||||
}))
|
||||
pp_issuer_address = faucet_response.account.address
|
||||
pp_issuer_secret = faucet_response.account.secret
|
||||
pp_issuer_wallet = await api.getFaucetWallet()
|
||||
} catch(error) {
|
||||
console.log("Error getting issuer address for partial payments:", error)
|
||||
return
|
||||
@@ -244,18 +208,21 @@ const set_up_tx_sender = async function() {
|
||||
while (true) {
|
||||
try {
|
||||
await new Promise(resolve => setTimeout(resolve, 1000))
|
||||
await api.request("account_info", {account: pp_issuer_address,
|
||||
ledger_index: "validated"})
|
||||
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_verify({
|
||||
let resp = await submit_and_notify({
|
||||
TransactionType: "AccountSet",
|
||||
Account: pp_issuer_address,
|
||||
Account: pp_issuer_wallet.classicAddress,
|
||||
SetFlag: 8
|
||||
}, pp_issuer_secret, true)
|
||||
}, pp_issuer_wallet, true)
|
||||
if (resp === undefined) {
|
||||
console.log("Couldn't set Default Ripple for partial payment issuer")
|
||||
return
|
||||
@@ -263,15 +230,15 @@ const set_up_tx_sender = async function() {
|
||||
$("#pp_progress .progress-bar").width("40%")
|
||||
|
||||
// 3. Make a trust line from sending address to issuer
|
||||
resp = await submit_and_verify({
|
||||
resp = await submit_and_notify({
|
||||
TransactionType: "TrustSet",
|
||||
Account: sending_address,
|
||||
Account: sending_wallet.classicAddress,
|
||||
LimitAmount: {
|
||||
currency: pp_sending_currency,
|
||||
value: "1000000000", // arbitrarily, 1 billion fake currency
|
||||
issuer: pp_issuer_address
|
||||
issuer: pp_issuer_wallet.classicAddress
|
||||
}
|
||||
}, sending_secret, true)
|
||||
}, sending_wallet, true)
|
||||
if (resp === undefined) {
|
||||
console.log("Error making trust line to partial payment issuer")
|
||||
return
|
||||
@@ -279,16 +246,16 @@ const set_up_tx_sender = async function() {
|
||||
$("#pp_progress .progress-bar").width("60%")
|
||||
|
||||
// 4. Issue fake currency to main sending address
|
||||
resp = await submit_and_verify({
|
||||
resp = await submit_and_notify({
|
||||
TransactionType: "Payment",
|
||||
Account: pp_issuer_address,
|
||||
Destination: sending_address,
|
||||
Account: pp_issuer_wallet.classicAddress,
|
||||
Destination: sending_wallet.classicAddress,
|
||||
Amount: {
|
||||
currency: pp_sending_currency,
|
||||
value: "1000000000",
|
||||
issuer: pp_issuer_address
|
||||
issuer: pp_issuer_wallet.classicAddress
|
||||
}
|
||||
}, pp_issuer_secret, true)
|
||||
}, pp_issuer_wallet, true)
|
||||
if (resp === undefined) {
|
||||
console.log("Error sending fake currency from partial payment issuer")
|
||||
return
|
||||
@@ -298,16 +265,16 @@ const set_up_tx_sender = async function() {
|
||||
// 5. Place offer to buy issued currency for XRP
|
||||
// When sending the partial payment, the sender consumes their own offer (!)
|
||||
// so they end up paying themselves issued currency then delivering XRP.
|
||||
resp = await submit_and_verify({
|
||||
resp = await submit_and_notify({
|
||||
TransactionType: "OfferCreate",
|
||||
Account: sending_address,
|
||||
Account: sending_wallet.classicAddress,
|
||||
TakerGets: "1000000000000000", // 1 billion XRP
|
||||
TakerPays: {
|
||||
currency: pp_sending_currency,
|
||||
value: "1000000000",
|
||||
issuer: pp_issuer_address
|
||||
issuer: pp_issuer_wallet.classicAddress
|
||||
}
|
||||
}, sending_secret, true)
|
||||
}, sending_wallet, true)
|
||||
if (resp === undefined) {
|
||||
console.log("Error placing order to enable partial payments")
|
||||
return
|
||||
@@ -328,7 +295,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.isValidAddress(d_a)) {
|
||||
if (api.isValidClassicAddress(d_a) || api.isValidXAddress(d_a)) { // TODO: switch back to isValidAddress
|
||||
$("#destination_address").addClass("is-valid").removeClass("is-invalid")
|
||||
if (d_a[0] == "X") {
|
||||
$("#x-address-warning").show()
|
||||
@@ -354,9 +321,9 @@ const set_up_tx_sender = async function() {
|
||||
const xrp_drops_input = $("#send_xrp_payment_amount").val()
|
||||
$("#send_xrp_payment .loader").show()
|
||||
$("#send_xrp_payment button").prop("disabled","disabled")
|
||||
await submit_and_verify({
|
||||
await submit_and_notify({
|
||||
TransactionType: "Payment",
|
||||
Account: sending_address,
|
||||
Account: sending_wallet.classicAddress,
|
||||
Destination: destination_address,
|
||||
Amount: xrp_drops_input
|
||||
})
|
||||
@@ -372,27 +339,19 @@ const set_up_tx_sender = async function() {
|
||||
$("#send_partial_payment .loader").show()
|
||||
$("#send_partial_payment button").prop("disabled","disabled")
|
||||
|
||||
// const path_find_result = await api.request("ripple_path_find", {
|
||||
// source_account: sending_address,
|
||||
// destination_account: destination_address,
|
||||
// destination_amount: "-1", // as much XRP as possible
|
||||
// source_currencies: [{currency: pp_sending_currency, issuer: pp_issuer_address}]
|
||||
// })
|
||||
// console.log("Path find result:", path_find_result)
|
||||
// use_path = path_find_result.alternatives[0].paths_computed
|
||||
|
||||
await submit_and_verify({
|
||||
await submit_and_notify({
|
||||
TransactionType: "Payment",
|
||||
Account: sending_address,
|
||||
Account: sending_wallet.classicAddress,
|
||||
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_address
|
||||
issuer: pp_issuer_wallet.classicAddress
|
||||
},
|
||||
Flags: api.txFlags.Payment.PartialPayment | api.txFlags.Universal.FullyCanonicalSig
|
||||
})
|
||||
// TODO: follow txFlags wherever they get moved to
|
||||
$("#send_partial_payment .loader").hide()
|
||||
$("#send_partial_payment button").prop("disabled",false)
|
||||
}
|
||||
@@ -410,13 +369,13 @@ const set_up_tx_sender = async function() {
|
||||
errorNotif("Error: Escrow duration must be a positive number of seconds")
|
||||
return
|
||||
}
|
||||
const finish_after = api.iso8601ToRippleTime(Date()) + duration_seconds
|
||||
const finish_after = xrpl.ISOTimeToRippleTime(Date()) + duration_seconds
|
||||
|
||||
$("#create_escrow .loader").show()
|
||||
$("#create_escrow button").prop("disabled","disabled")
|
||||
const escrowcreate_tx_data = await submit_and_verify({
|
||||
const escrowcreate_tx_data = await submit_and_notify({
|
||||
TransactionType: "EscrowCreate",
|
||||
Account: sending_address,
|
||||
Account: sending_wallet.classicAddress,
|
||||
Destination: destination_address,
|
||||
Amount: "1000000",
|
||||
FinishAfter: finish_after
|
||||
@@ -431,14 +390,17 @@ const set_up_tx_sender = async function() {
|
||||
let pct_done
|
||||
let latestCloseTimeRipple
|
||||
while (true) {
|
||||
seconds_left = (finish_after - api.iso8601ToRippleTime(Date()))
|
||||
seconds_left = (finish_after - xrpl.ISOTimeToRippleTime(Date()))
|
||||
pct_done = Math.min(99, Math.max(0, (1-(seconds_left / duration_seconds)) * 100))
|
||||
$("#escrow_progress .progress-bar").width(pct_done+"%")
|
||||
if (seconds_left <= 0) {
|
||||
// System time has advanced past FinishAfter. But is there a new
|
||||
// enough validated ledger?
|
||||
latestCloseTimeRipple = api.iso8601ToRippleTime((await api.getLedger()).closeTime)
|
||||
if (latestCloseTimeRipple > finish_after) {
|
||||
latest_close_time = (await api.request({
|
||||
command: "ledger",
|
||||
"ledger_index": "validated"}
|
||||
)).result.ledger.close_time
|
||||
if (latest_close_time > finish_after) {
|
||||
$("#escrow_progress .progress-bar").width("100%").removeClass("progress-bar-animated")
|
||||
break
|
||||
}
|
||||
@@ -451,10 +413,10 @@ const set_up_tx_sender = async function() {
|
||||
// Now submit the EscrowFinish
|
||||
// Future feature: submit from a different sender, just to prove that
|
||||
// escrows can be finished by a third party
|
||||
await submit_and_verify({
|
||||
Account: sending_address,
|
||||
await submit_and_notify({
|
||||
Account: sending_wallet.classicAddress,
|
||||
TransactionType: "EscrowFinish",
|
||||
Owner: sending_address,
|
||||
Owner: sending_wallet.classicAddress,
|
||||
OfferSequence: escrowcreate_tx_data.sequence
|
||||
})
|
||||
}
|
||||
@@ -467,12 +429,12 @@ const set_up_tx_sender = async function() {
|
||||
async function on_click_create_payment_channel(event) {
|
||||
const destination_address = $("#destination_address").val()
|
||||
const xrp_drops_input = $("#create_payment_channel_amount").val()
|
||||
const pubkey = api.deriveKeypair(sending_secret).publicKey
|
||||
const pubkey = sending_wallet.publicKey
|
||||
$("#create_payment_channel .loader").show()
|
||||
$("#create_payment_channel button").prop("disabled","disabled")
|
||||
await submit_and_verify({
|
||||
await submit_and_notify({
|
||||
TransactionType: "PaymentChannelCreate",
|
||||
Account: sending_address,
|
||||
Account: sending_wallet.classicAddress,
|
||||
Destination: destination_address,
|
||||
Amount: xrp_drops_input,
|
||||
SettleDelay: 30,
|
||||
@@ -495,14 +457,14 @@ const set_up_tx_sender = async function() {
|
||||
$("#send_issued_currency .loader").show()
|
||||
$("#send_issued_currency button").prop("disabled","disabled")
|
||||
// Future feature: cross-currency sending with paths?
|
||||
await submit_and_verify({
|
||||
await submit_and_notify({
|
||||
TransactionType: "Payment",
|
||||
Account: sending_address,
|
||||
Account: sending_wallet.classicAddress,
|
||||
Destination: destination_address,
|
||||
Amount: {
|
||||
"currency": issue_code,
|
||||
"value": issue_amount,
|
||||
"issuer": sending_address
|
||||
"issuer": sending_wallet.classicAddress
|
||||
}
|
||||
})
|
||||
$("#send_issued_currency .loader").hide()
|
||||
@@ -517,9 +479,9 @@ const set_up_tx_sender = async function() {
|
||||
const trust_currency_code = $("#trust_for_currency_code").text()
|
||||
$("#trust_for .loader").show()
|
||||
$("#trust_for button").prop("disabled","disabled")
|
||||
await submit_and_verify({
|
||||
await submit_and_notify({
|
||||
TransactionType: "TrustSet",
|
||||
Account: sending_address,
|
||||
Account: sending_wallet.classicAddress,
|
||||
LimitAmount: {
|
||||
currency: trust_currency_code,
|
||||
value: trust_limit,
|
||||
|
||||
2
assets/js/xrpl-2.0b0.min.js
vendored
Normal file
2
assets/js/xrpl-2.0b0.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user