Tx Parsing and updating input values
This commit is contained in:
parent
a5d74393d1
commit
8d733df278
@ -21,7 +21,7 @@ module.exports = function transactionAPI(router) {
|
||||
`getTxById: ${err}`);
|
||||
return res.status(400).send();
|
||||
}
|
||||
|
||||
console.log(transaction);
|
||||
const tx = transaction;
|
||||
return res.send({
|
||||
txid: tx.hash,
|
||||
@ -34,8 +34,8 @@ module.exports = function transactionAPI(router) {
|
||||
confirmations: (height - tx.height) + 1,
|
||||
valueOut: tx.outputs.reduce((sum, output) => sum + output.value, 0) / 1e8,
|
||||
vin: tx.inputs.map(input => ({
|
||||
addr: input.coin ? input.coin.address : '',
|
||||
value: input.coin ? input.coin.value / 1e8 : 0,
|
||||
addr: input.address,
|
||||
value: input.value / 1e8,
|
||||
})),
|
||||
vout: tx.outputs.map(output => ({
|
||||
scriptPubKey: {
|
||||
|
||||
@ -54,7 +54,6 @@ function getTransaction(params, options, limit, cb) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function getTxById(txid, cb) {
|
||||
getTransaction(
|
||||
{ hash: txid },
|
||||
@ -66,13 +65,31 @@ function getTxById(txid, cb) {
|
||||
`/rawblock/:blockHash: ${err}`);
|
||||
return cb(err);
|
||||
}
|
||||
console.log(transaction);
|
||||
return cb(null, transaction);
|
||||
});
|
||||
}
|
||||
|
||||
function updateInput(txid, inputid, value, address) {
|
||||
Transactions.findOneAndUpdate(
|
||||
{ _id: txid, 'inputs._id': inputid },
|
||||
{
|
||||
$set: {
|
||||
'inputs.$.value': value,
|
||||
'inputs.$.address': address,
|
||||
},
|
||||
},
|
||||
(err, tx) => {
|
||||
if (err) {
|
||||
logger.log('err',
|
||||
`updateInput: ${err}`);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getTransaction,
|
||||
getTransactions,
|
||||
getTxById,
|
||||
updateInput,
|
||||
};
|
||||
|
||||
@ -73,13 +73,6 @@ function parse(entry, block) {
|
||||
}
|
||||
});
|
||||
}
|
||||
// Fill in behind blocks and update tx inputs
|
||||
function updateInputs(txid, address) {
|
||||
// Use txid and output address to get value
|
||||
// Get addr / value from prev out
|
||||
// update input
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
parse,
|
||||
|
||||
@ -4,6 +4,7 @@ const OutputModel = require('../../models/output');
|
||||
const config = require('../../config');
|
||||
const util = require('../../lib/util');
|
||||
const logger = require('../logger');
|
||||
const db = require('../db');
|
||||
|
||||
function parse(entry, txs) {
|
||||
txs.forEach((tx) => {
|
||||
@ -46,10 +47,28 @@ function parse(entry, txs) {
|
||||
chain: config.bcoin.network,
|
||||
});
|
||||
|
||||
|
||||
t.save((err) => {
|
||||
if (err) {
|
||||
logger.log('error', err.message);
|
||||
}
|
||||
|
||||
t.inputs.forEach((input) => {
|
||||
const txid = input.prevout.hash;
|
||||
const idx = input.prevout.index;
|
||||
const addr = input.address;
|
||||
if (txid !== '0000000000000000000000000000000000000000000000000000000000000000') {
|
||||
db.txs.getTxById(txid, (err, tx) => {
|
||||
if (err) {
|
||||
logger.log('err',
|
||||
`Tx Parser inputs.ForEach: ${err}`);
|
||||
return;
|
||||
}
|
||||
|
||||
db.txs.updateInput(t._id, input._id, tx.outputs[idx].value, tx.outputs[idx].address);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user