Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tx api: add mempool data for unconfirmed tx #479

Merged
merged 1 commit into from
Dec 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions routes/apiRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,26 +144,21 @@ router.get("/block/header/:hashOrHeight", asyncHandler(async (req, res, next) =>

/// TRANSACTIONS

router.get("/tx/:txid", function(req, res, next) {
router.get("/tx/:txid", asyncHandler(async (req, res, next) => {
let txid = utils.asHash(req.params.txid);

let promises = [];

let txInputLimit = (res.locals.crawlerBot) ? 3 : -1;

promises.push(coreApi.getRawTransactionsWithInputs([txid], txInputLimit));

Promise.all(promises).then(function(results) {
let outJson = results[0].transactions[0];
let txInputs = results[0].txInputsByTransaction[txid] || {};
try {
var results = await coreApi.getRawTransactionsWithInputs([txid], txInputLimit);
let outJson = results.transactions[0];
let txInputs = results.txInputsByTransaction[txid] || {};

let inputBtc = 0;
if (txInputs[0]) {
for (let key in txInputs) {
let item = txInputs[key];

inputBtc += item["value"] * global.coinConfig.baseCurrencyUnit.multiplier;

outJson.vin[key].scriptSig.address = item.scriptPubKey.address;
outJson.vin[key].scriptSig.type = item.scriptPubKey.type;
outJson.vin[key].value = item.value;
Expand All @@ -172,8 +167,7 @@ router.get("/tx/:txid", function(req, res, next) {

let outputBtc = 0;
for (let key in outJson.vout) {
let item = outJson.vout[key];

let item = outJson.vout[key];
outputBtc += item.value * global.coinConfig.baseCurrencyUnit.multiplier;
}

Expand All @@ -182,24 +176,25 @@ router.get("/tx/:txid", function(req, res, next) {
"unit": "BTC"
};

if (outJson.confirmations == null) {
outJson.mempool = await coreApi.getMempoolTxDetails(txid, false);
}

if (global.specialTransactions && global.specialTransactions[txid]) {
let funInfo = global.specialTransactions[txid];

outJson.fun = funInfo;
}

res.json(outJson);

next();

}).catch(function(err) {

} catch(err) {
utils.logError("10328fwgdaqw", err);

res.json({success:false, error:err});
};

next();

next();
});
});
}));

router.get("/tx/volume/24h", function(req, res, next) {
try {
Expand Down