Skip to content

Commit

Permalink
Cleanup #434 and add changelog details
Browse files Browse the repository at this point in the history
  • Loading branch information
janoside committed May 17, 2022
1 parent e77c38d commit 338d680
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG-API.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
This changelog specifically tracks changes to the Public API available at `/api` and is maintained separately from the app CHANGELOG such that it can properly adhere to semantic versioning.

##### v1.2.0
###### Unreleased

* /api/tx/:txid
* Added result.vin[i].scriptSig.address
* Added result.vin[i].scriptSig.type
* Added result.fee, including result.fee.amount and result.fee.unit



##### v1.1.0
###### 2021-12-07

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Homepage additions
* Show difficulty ATH comparison
* Show "Next Block" fullness
* Tweaks to API, see [/api/changelog](./api/changelog)
* Support for serving static assets via a configurable CDN
* Misc fixes for erroneous data display on non-mainnet nodes
* Switch from fontawesome to bootstrap-icons v1.8.0
Expand Down
28 changes: 17 additions & 11 deletions routes/apiRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,25 +133,31 @@ router.get("/tx/:txid", function(req, res, next) {
Promise.all(promises).then(function(results) {
let outJson = results[0].transactions[0];
let txInputs = results[0].txInputsByTransaction[txid] || {};
const satsPerBtc = 100000000;

let inputBtc = 0;
if(txInputs[0]){
for (var key in txInputs) {
var item = txInputs[key];
inputBtc += item["value"] * satsPerBtc;
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"];
outJson.vin[key].scriptSig.type = item.scriptPubKey.type;
outJson.vin[key].value = item.value;
}
}

let outputBtc = 0;
for (var key in outJson.vout) {
var item = outJson.vout[key];
outputBtc += item["value"] * satsPerBtc;
for (let key in outJson.vout) {
let item = outJson.vout[key];

outputBtc += item.value * global.coinConfig.baseCurrencyUnit.multiplier;
}
outJson.fee = {"amount": (inputBtc - outputBtc)/satsPerBtc, "unit": "BTC"};

outJson.fee = {
"amount": (inputBtc - outputBtc) / global.coinConfig.baseCurrencyUnit.multiplier,
"unit": "BTC"
};

res.json(outJson);

Expand Down

0 comments on commit 338d680

Please sign in to comment.