mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 12:45:50 +00:00
* assign -> Object.assign * replace isundefined * remove forEach * remove some * remove reduce * remove keys * remove map * remove includes * remove filter * remove last * remove isstring * remove every * remove rearg * remove indexOf * remove values * remove startswith * remove first and pick * build smaller lodash * remove lodash.isequal package * add lodash-cli dev dependency * add lodash script * test fix * Revert "build smaller lodash" This reverts commit 979446e57f60b29cb5d377b54efe91cfbeae0707. * upgrade npm * change ===/!== undefined to ==/!= null
57 lines
1.3 KiB
JavaScript
57 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
const masterAccount = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh';
|
|
const masterSecret = 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb';
|
|
|
|
function ledgerAccept(api) {
|
|
const request = {command: 'ledger_accept'};
|
|
return api.connection.request(request);
|
|
}
|
|
|
|
function pay(api, 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 api.preparePayment(from, paymentSpecification, {})
|
|
.then(data => api.sign(data.txJSON, secret))
|
|
.then(signed => {
|
|
id = signed.id;
|
|
return api.submit(signed.signedTransaction);
|
|
})
|
|
.then(() => ledgerAccept(api))
|
|
.then(() => id);
|
|
}
|
|
|
|
|
|
function payTo(api, to, amount = '4003218', currency = 'XRP', counterparty) {
|
|
return pay(api, masterAccount, to, amount, masterSecret, currency,
|
|
counterparty);
|
|
}
|
|
|
|
|
|
module.exports = {
|
|
pay,
|
|
payTo,
|
|
ledgerAccept
|
|
};
|