mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 04:35:49 +00:00
* deprecate and alias prepareTransaction * delete prepareTransaction and replace methods in check-cancel * WIP update check-cash * remove all prepares * remove prepares from client * fix ts issues * remove tests * fix tests * additional cleanup * fix integration tests * remove console statement * re-add helper function * fix imports * fix more issues with integration tests Co-authored-by: Omar Khan <khancodegt@gmail.com>
81 lines
1.7 KiB
JavaScript
81 lines
1.7 KiB
JavaScript
const assert = require('chai').assert
|
|
|
|
const models = require('xrpl-local/models/transactions')
|
|
const utils = require('xrpl-local/utils')
|
|
|
|
const masterAccount = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'
|
|
const masterSecret = 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb'
|
|
|
|
function ledgerAccept(client) {
|
|
const request = { command: 'ledger_accept' }
|
|
return client.connection.request(request)
|
|
}
|
|
|
|
function pay(client, from, to, amount, secret, currency = 'XRP', issuer) {
|
|
const paymentAmount =
|
|
currency === 'XRP' ? amount : { value: amount, currency, issuer }
|
|
|
|
const payment = {
|
|
TransactionType: 'Payment',
|
|
Account: from,
|
|
Destination: to,
|
|
Amount: paymentAmount,
|
|
}
|
|
|
|
let id = null
|
|
return (
|
|
client
|
|
.autofill(payment, 1)
|
|
.then((tx) => {
|
|
models.verifyPayment(payment)
|
|
return client.sign(JSON.stringify(tx), secret)
|
|
})
|
|
.then((signed) => {
|
|
id = signed.id
|
|
return client.request({
|
|
command: 'submit',
|
|
tx_blob: signed.signedTransaction,
|
|
})
|
|
})
|
|
// TODO: add better error handling here
|
|
// TODO: fix path issues
|
|
.then((response) => {
|
|
if (
|
|
response.result.engine_result !== 'tesSUCCESS' &&
|
|
response.result.engine_result !== 'tecPATH_PARTIAL'
|
|
) {
|
|
console.log(response)
|
|
assert.fail(
|
|
`Response not successful, ${response.result.engine_result}`,
|
|
)
|
|
}
|
|
ledgerAccept(client)
|
|
})
|
|
.then(() => id)
|
|
)
|
|
}
|
|
|
|
function payTo(
|
|
client,
|
|
to,
|
|
amount = '40000000',
|
|
currency = 'XRP',
|
|
counterparty,
|
|
) {
|
|
return pay(
|
|
client,
|
|
masterAccount,
|
|
to,
|
|
amount,
|
|
masterSecret,
|
|
currency,
|
|
counterparty,
|
|
)
|
|
}
|
|
|
|
module.exports = {
|
|
pay,
|
|
payTo,
|
|
ledgerAccept,
|
|
}
|