Files
xahau.js/test/integration/utils.js
Mayukha Vadari 73109295b4 Rename RippleAPI client to Client (#1520)
* rename RippleAPI -> XrplClient

* more renames

* move API stuff to client folder

* rename all api -> client

* fix tests

* make tests run

* fix integ tests

* fix urls

* fix merge issues

* XrplClient -> Client

* fix merge issues

* rename xrpl-client npm symlink to xrpl-local
2021-10-04 14:10:08 -04:00

57 lines
1.3 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.submit(signed.signedTransaction);
})
.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
};