-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtxPayment.js
More file actions
64 lines (53 loc) · 2.21 KB
/
txPayment.js
File metadata and controls
64 lines (53 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict';
var _ = require('lodash');
const path = require('path');
var utils = require('chainsql-lib').ChainsqlLibUtil;
var validate = utils.common.validate;
var toRippledAmount = utils.common.toRippledAmount;
var paymentFlags = utils.common.txFlags.Payment;
var ValidationError = utils.common.errors.ValidationError;
function isXRPToXRPPayment(payment) {
var sourceCurrency = _.get(payment, 'source.maxAmount.currency', _.get(payment, 'source.amount.currency'));
var destinationCurrency = _.get(payment, 'destination.amount.currency', _.get(payment, 'destination.minAmount.currency'));
return sourceCurrency === 'ZXC' && destinationCurrency === 'ZXC';
}
function isIOUWithoutCounterparty(amount) {
return amount && amount.currency !== 'ZXC' && amount.counterparty === undefined;
}
function applyAnyCounterpartyEncoding(payment) {
// Convert blank counterparty to sender or receiver's address
// (Ripple convention for 'any counterparty')
// https://ripple.com/build/transactions/
// #special-issuer-values-for-sendmax-and-amount
// https://ripple.com/build/ripple-rest/#counterparties-in-payments
_.forEach([payment.source, payment.destination], function(adjustment) {
_.forEach(['amount', 'minAmount', 'maxAmount'], function(key) {
if (isIOUWithoutCounterparty(adjustment[key])) {
adjustment[key].counterparty = adjustment.address;
}
});
});
}
function createMaximalAmount(amount) {
var maxXRPValue = '100000000000';
var maxIOUValue = '9999999999999999e80';
var maxValue = amount.currency === 'ZXC' ? maxXRPValue : maxIOUValue;
return _.assign({}, amount, {
value: maxValue
});
}
function prepareTxPayment(payment) {
var instructions = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
//validate.preparePayment({ address: address, payment: payment, instructions: instructions });
return utils.prepareTransaction(payment, this, instructions).then(function(ret){
/*console.log('preparetx:')
let obj = JSON.parse(ret.txJSON);
console.log(obj.Memos[0].Memo.MemoData);
obj.Memos[0].Memo.MemoData = "----test";
console.log(obj);
ret.txJSON = JSON.stringify(obj);
console.log(ret);*/
return ret;
});
}
module.exports = prepareTxPayment;