forked from slickage/baron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate.js
55 lines (50 loc) · 1.73 KB
/
validate.js
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
var invoice = function(invoice) {
var curTime = new Date().getTime();
var invalidLineItems = false;
if(invoice.line_items && invoice.line_items.length > 0) {
invoice.line_items.forEach(function(item) {
invalidLineItems = !item.amount || !item.quantity || !item.description;
});
}
if (!invoice.currency || !invoice.min_confirmations ||
invalidLineItems || Number(invoice.expiration) < curTime) {
return false;
}
else {
return true;
}
};
var invoiceExpired = function(invoice) {
var curTime = new Date().getTime();
if (invoice && invoice.expiration) {
return Number(invoice.expiration) < curTime;
}
else {
return false;
}
};
var block = function(block) {
return block.confirmations ? Number(block.confirmations) !== -1 : true;
};
var paymentChanged = function(payment, transaction, newStatus) {
var oldAmount = payment.amount_paid;
var newAmount = transaction.amount;
var oldTxId = payment.tx_id;
var newTxId = transaction.txid;
var oldBlockHash = payment.block_hash;
var newBlockHash = transaction.blockhash ? transaction.blockhash : null;
var oldPaidTime = payment.paid_timestamp;
var newPaidTime = transaction.time * 1000;
var oldStatus = payment.status;
var oldDoubleSpentHist = payment.double_spent_history ? payment.double_spent_history : [];
var newDoubleSpentHist = transaction.walletconflicts ? transaction.walletconflicts : [];
return oldAmount !== newAmount || oldTxId !== newTxId ||
oldBlockHash !== newBlockHash || oldPaidTime !== newPaidTime ||
oldStatus !== newStatus || oldDoubleSpentHist.length !== newDoubleSpentHist.length;
};
module.exports = {
invoice: invoice,
invoiceExpired: invoiceExpired,
block: block,
paymentChanged: paymentChanged
};