mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 12:45:50 +00:00
Removes all prepare methods (#1605)
* 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>
This commit is contained in:
@@ -1,57 +1,80 @@
|
||||
'use strict';
|
||||
const assert = require('chai').assert
|
||||
|
||||
const masterAccount = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh';
|
||||
const masterSecret = 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb';
|
||||
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);
|
||||
const request = { command: 'ledger_accept' }
|
||||
return client.connection.request(request)
|
||||
}
|
||||
|
||||
function pay(client, from, to, amount, secret, currency = 'XRP', counterparty) {
|
||||
const paymentSpecification = {
|
||||
source: {
|
||||
address: from,
|
||||
maxAmount: {
|
||||
value: amount,
|
||||
currency: currency
|
||||
}
|
||||
},
|
||||
destination: {
|
||||
address: to,
|
||||
amount: {
|
||||
value: amount,
|
||||
currency: currency
|
||||
}
|
||||
}
|
||||
};
|
||||
function pay(client, from, to, amount, secret, currency = 'XRP', issuer) {
|
||||
const paymentAmount =
|
||||
currency === 'XRP' ? amount : { value: amount, currency, issuer }
|
||||
|
||||
if (counterparty != null) {
|
||||
paymentSpecification.source.maxAmount.counterparty = counterparty;
|
||||
paymentSpecification.destination.amount.counterparty = counterparty;
|
||||
const payment = {
|
||||
TransactionType: 'Payment',
|
||||
Account: from,
|
||||
Destination: to,
|
||||
Amount: paymentAmount,
|
||||
}
|
||||
|
||||
let id = null;
|
||||
return client.preparePayment(from, paymentSpecification, {})
|
||||
.then(data => client.sign(data.txJSON, secret))
|
||||
.then(signed => {
|
||||
id = signed.id;
|
||||
return client.request({command: 'submit', tx_blob: signed.signedTransaction});
|
||||
})
|
||||
// TODO: add better error handling here
|
||||
.then(() => ledgerAccept(client))
|
||||
.then(() => id);
|
||||
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 = '4003218', currency = 'XRP', counterparty) {
|
||||
return pay(client, masterAccount, to, amount, masterSecret, currency,
|
||||
counterparty);
|
||||
function payTo(
|
||||
client,
|
||||
to,
|
||||
amount = '40000000',
|
||||
currency = 'XRP',
|
||||
counterparty,
|
||||
) {
|
||||
return pay(
|
||||
client,
|
||||
masterAccount,
|
||||
to,
|
||||
amount,
|
||||
masterSecret,
|
||||
currency,
|
||||
counterparty,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
pay,
|
||||
payTo,
|
||||
ledgerAccept
|
||||
};
|
||||
ledgerAccept,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user