From 50466ea8f963eec19df9be0e3969a96013ca0ead Mon Sep 17 00:00:00 2001 From: pbca26 Date: Fri, 20 Oct 2017 19:05:22 +0300 Subject: [PATCH] spv, zero conf tx fix --- routes/shepherd/electrum/listunspent.js | 4 ++-- routes/shepherd/electrum/transactions.js | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/routes/shepherd/electrum/listunspent.js b/routes/shepherd/electrum/listunspent.js index 7db5f50..27269f2 100644 --- a/routes/shepherd/electrum/listunspent.js +++ b/routes/shepherd/electrum/listunspent.js @@ -61,7 +61,7 @@ module.exports = (shepherd) => { amountSats: _utxoItem.value, interest: interest, interestSats: Math.floor(interest * 100000000), - confirmations: currentHeight - _utxoItem.height, + confirmations: Number(_utxoItem.height) === 0 ? 0 : currentHeight - _utxoItem.height, spendable: true, verified: false, }; @@ -87,7 +87,7 @@ module.exports = (shepherd) => { address, amount: Number(_utxoItem.value) * 0.00000001, amountSats: _utxoItem.value, - confirmations: currentHeight - _utxoItem.height, + confirmations: Number(_utxoItem.height) === 0 ? 0 : currentHeight - _utxoItem.height, spendable: true, verified: false, }; diff --git a/routes/shepherd/electrum/transactions.js b/routes/shepherd/electrum/transactions.js index d49d58f..80cf31b 100644 --- a/routes/shepherd/electrum/transactions.js +++ b/routes/shepherd/electrum/transactions.js @@ -107,8 +107,8 @@ module.exports = (shepherd) => { inputs: txInputs, outputs: decodedTx.outputs, height: transaction.height, - timestamp: blockInfo.timestamp, - confirmations: currentHeight - transaction.height, + timestamp: Number(transaction.height) === 0 ? Math.floor(Date.now() / 1000) : blockInfo.timestamp, + confirmations: Number(transaction.height) === 0 ? 0 : currentHeight - transaction.height, }; const formattedTx = shepherd.parseTransactionAddresses(_parsedTx, req.query.address, network); @@ -149,8 +149,8 @@ module.exports = (shepherd) => { inputs: 'cant parse', outputs: 'cant parse', height: transaction.height, - timestamp: blockInfo.timestamp, - confirmations: currentHeight - transaction.height, + timestamp: Number(transaction.height) === 0 ? Math.floor(Date.now() / 1000) : blockInfo.timestamp, + confirmations: Number(transaction.height) === 0 ? 0 : currentHeight - transaction.height, }; const formattedTx = shepherd.parseTransactionAddresses(_parsedTx, req.query.address, network); @@ -166,7 +166,7 @@ module.exports = (shepherd) => { outputs: 'cant parse', height: transaction.height, timestamp: 'cant get block info', - confirmations: currentHeight - transaction.height, + confirmations: Number(transaction.height) === 0 ? 0 : currentHeight - transaction.height, }; const formattedTx = shepherd.parseTransactionAddresses(_parsedTx, req.query.address, network); _rawtx.push(formattedTx);