Files
xahau.js/test/integration/utils.js
Mayukha Vadari 0b08de5956 Removes methods that were just rippled wrappers (#1550)
* remove getAccountInfo

* remove getAccountObjects

* remove getBalanceSheet (gateway_balances)

* remove getLedger

* remove getOrders (account_orders)

* remove getPaymentChannel (ledger_entry)

* remove getTransaction(s) (tx/account_tx)

* remove getSettings (account_info)

* remove getServerInfo (server_info)

* fix integ tests

* remove submit (also deprecated)

* fix integ tests

* add TODO
2021-10-04 14:10:09 -04:00

58 lines
1.4 KiB
JavaScript

'use strict';
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', counterparty) {
const paymentSpecification = {
source: {
address: from,
maxAmount: {
value: amount,
currency: currency
}
},
destination: {
address: to,
amount: {
value: amount,
currency: currency
}
}
};
if (counterparty != null) {
paymentSpecification.source.maxAmount.counterparty = counterparty;
paymentSpecification.destination.amount.counterparty = counterparty;
}
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);
}
function payTo(client, to, amount = '4003218', currency = 'XRP', counterparty) {
return pay(client, masterAccount, to, amount, masterSecret, currency,
counterparty);
}
module.exports = {
pay,
payTo,
ledgerAccept
};