Add gettx API

This commit is contained in:
joeuhren
2020-11-20 14:32:27 -07:00
parent 988bf5b719
commit e48e6b0186
2 changed files with 57 additions and 0 deletions
+50
View File
@@ -85,6 +85,56 @@ app.use('/ext/getaddress/:hash', function(req,res){
});
});
app.use('/ext/gettx/:txid', function(req, res) {
var txid = req.param('txid');
db.get_tx(txid, function(tx) {
if (tx) {
lib.get_blockcount(function(blockcount) {
res.send({ active: 'tx', tx: tx, confirmations: settings.confirmations, blockcount: blockcount});
});
}
else {
lib.get_rawtransaction(txid, function(rtx) {
if (rtx.txid) {
lib.prepare_vin(rtx, function(vin) {
lib.prepare_vout(rtx.vout, rtx.txid, vin, function(rvout, rvin) {
lib.calculate_total(rvout, function(total){
if (!rtx.confirmations > 0) {
var utx = {
txid: rtx.txid,
vin: rvin,
vout: rvout,
total: total.toFixed(8),
timestamp: rtx.time,
blockhash: '-',
blockindex: -1,
};
res.send({ active: 'tx', tx: utx, confirmations: settings.confirmations, blockcount:-1});
} else {
var utx = {
txid: rtx.txid,
vin: rvin,
vout: rvout,
total: total.toFixed(8),
timestamp: rtx.time,
blockhash: rtx.blockhash,
blockindex: rtx.blockheight,
};
lib.get_blockcount(function(blockcount) {
res.send({ active: 'tx', tx: utx, confirmations: settings.confirmations, blockcount: blockcount});
});
}
});
});
});
} else {
res.send({ error: 'tx not found.', hash: txid});
}
});
}
});
});
app.use('/ext/getbalance/:hash', function(req,res){
db.get_address(req.params.hash, false, function(address){
if (address) {
+7
View File
@@ -138,6 +138,13 @@ block content
div
em Returns information for given address
a(href='/ext/getaddress/' + hashes.address) #{address}/ext/getaddress/#{hashes.address}
li
li
p
div(style='font-weight:bold;') gettx (/ext/gettx/hash)
div
em Returns information for given tx hash
a(href='/ext/gettx/' + hashes.txhash) #{address}/ext/gettx/#{hashes.txhash}
li
p
div(style='font-weight:bold;') getbalance (/ext/getbalance/hash)