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}`);
|
`getTxById: ${err}`);
|
||||||
return res.status(400).send();
|
return res.status(400).send();
|
||||||
}
|
}
|
||||||
|
console.log(transaction);
|
||||||
const tx = transaction;
|
const tx = transaction;
|
||||||
return res.send({
|
return res.send({
|
||||||
txid: tx.hash,
|
txid: tx.hash,
|
||||||
@ -34,8 +34,8 @@ module.exports = function transactionAPI(router) {
|
|||||||
confirmations: (height - tx.height) + 1,
|
confirmations: (height - tx.height) + 1,
|
||||||
valueOut: tx.outputs.reduce((sum, output) => sum + output.value, 0) / 1e8,
|
valueOut: tx.outputs.reduce((sum, output) => sum + output.value, 0) / 1e8,
|
||||||
vin: tx.inputs.map(input => ({
|
vin: tx.inputs.map(input => ({
|
||||||
addr: input.coin ? input.coin.address : '',
|
addr: input.address,
|
||||||
value: input.coin ? input.coin.value / 1e8 : 0,
|
value: input.value / 1e8,
|
||||||
})),
|
})),
|
||||||
vout: tx.outputs.map(output => ({
|
vout: tx.outputs.map(output => ({
|
||||||
scriptPubKey: {
|
scriptPubKey: {
|
||||||
|
|||||||
@ -54,7 +54,6 @@ function getTransaction(params, options, limit, cb) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getTxById(txid, cb) {
|
function getTxById(txid, cb) {
|
||||||
getTransaction(
|
getTransaction(
|
||||||
{ hash: txid },
|
{ hash: txid },
|
||||||
@ -66,13 +65,31 @@ function getTxById(txid, cb) {
|
|||||||
`/rawblock/:blockHash: ${err}`);
|
`/rawblock/:blockHash: ${err}`);
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
console.log(transaction);
|
|
||||||
return cb(null, 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 = {
|
module.exports = {
|
||||||
getTransaction,
|
getTransaction,
|
||||||
getTransactions,
|
getTransactions,
|
||||||
getTxById,
|
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 = {
|
module.exports = {
|
||||||
parse,
|
parse,
|
||||||
|
|||||||
@ -4,6 +4,7 @@ const OutputModel = require('../../models/output');
|
|||||||
const config = require('../../config');
|
const config = require('../../config');
|
||||||
const util = require('../../lib/util');
|
const util = require('../../lib/util');
|
||||||
const logger = require('../logger');
|
const logger = require('../logger');
|
||||||
|
const db = require('../db');
|
||||||
|
|
||||||
function parse(entry, txs) {
|
function parse(entry, txs) {
|
||||||
txs.forEach((tx) => {
|
txs.forEach((tx) => {
|
||||||
@ -46,10 +47,28 @@ function parse(entry, txs) {
|
|||||||
chain: config.bcoin.network,
|
chain: config.bcoin.network,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
t.save((err) => {
|
t.save((err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
logger.log('error', err.message);
|
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