From fc37c7e1862ce0c69e15fc9afdb678841f2e3c4f Mon Sep 17 00:00:00 2001 From: Remco Ros Date: Sun, 8 Sep 2024 11:30:59 +0000 Subject: [PATCH] fix: minor issue fetching transaction data for larger amounts --- manifest.yaml | 4 ++-- scripts/procedures/migrations.ts | 2 +- src/PushTX/Program.cs | 13 ++++++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/manifest.yaml b/manifest.yaml index 6392ec4..3ee3a90 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -1,8 +1,8 @@ id: pushtx title: "NFC Push TX" -version: 1.0.0 +version: 1.0.1 release-notes: | - * Initial release of NFC Push TX + * Fix minor issue fetching transaction data for larger amounts license: MIT wrapper-repo: "https://github.com/remcoros/pushtx-startos" upstream-repo: "https://github.com/remcoros/pushtx-startos" diff --git a/scripts/procedures/migrations.ts b/scripts/procedures/migrations.ts index 7ea8974..99d0d0c 100644 --- a/scripts/procedures/migrations.ts +++ b/scripts/procedures/migrations.ts @@ -1,4 +1,4 @@ import { compat, types as T } from "../deps.ts"; export const migration: T.ExpectedExports.migration = compat.migrations - .fromMapping({}, "1.0.0" ); + .fromMapping({}, "1.0.1" ); diff --git a/src/PushTX/Program.cs b/src/PushTX/Program.cs index 6d0cd00..d42d853 100644 --- a/src/PushTX/Program.cs +++ b/src/PushTX/Program.cs @@ -145,6 +145,9 @@ await Parallel.ForEachAsync(vins.OfType(), async (vin, token) => } }); + // factor to multiply values with (BTC > SATS) + const decimal sats = 100_000_000m; + // map BTC Core result to mempool.space api result // map inputs var mempoolVin = rpcResult["vin"]!.AsArray().OfType() @@ -153,7 +156,7 @@ await Parallel.ForEachAsync(vins.OfType(), async (vin, token) => var prevout = new MempoolTxDataVout( (string)vin["prevout"]!["scriptPubKey"]!["hex"]!, (string)vin["prevout"]!["scriptPubKey"]!["address"]!, - (int)((decimal)vin["prevout"]!["value"]! * 1e8m)); + (decimal)vin["prevout"]!["value"]! * sats); return new MempoolTxDataVin((string)vin["txid"]!, (int)vin["vout"]!, prevout); }) .ToArray(); @@ -164,7 +167,7 @@ await Parallel.ForEachAsync(vins.OfType(), async (vin, token) => new MempoolTxDataVout( (string)vout["scriptPubKey"]!["hex"]!, (string)vout["scriptPubKey"]!["address"]!, - (int)((decimal)vout["value"]! * 1e8m))) + (decimal)vout["value"]! * sats)) .ToArray(); // if we have a blockhash, transaction is confirmed and we can query for the block info to get height @@ -363,7 +366,7 @@ public class MempoolTxData(string txid, MempoolTxDataVin[] vin, MempoolTxDataVou public string Txid { get; set; } = txid; [JsonPropertyName("fee")] - public int Fee => Vin.Sum(x => x.Prevout.Value) - Vout.Sum(x => x.Value); + public decimal Fee => Vin.Sum(x => x.Prevout.Value) - Vout.Sum(x => x.Value); [JsonPropertyName("status")] public MempoolConfirmedStatus Status { get; set; } = status; @@ -387,7 +390,7 @@ public class MempoolTxDataVin(string txid, int vout, MempoolTxDataVout prevout) public MempoolTxDataVout Prevout { get; set; } = prevout; } -public class MempoolTxDataVout(string scriptPubkey, string scriptPubkeyAddress, int value) +public class MempoolTxDataVout(string scriptPubkey, string scriptPubkeyAddress, decimal value) { [JsonPropertyName("scriptpubkey")] public string ScriptPubkey { get; set; } = scriptPubkey; @@ -396,7 +399,7 @@ public class MempoolTxDataVout(string scriptPubkey, string scriptPubkeyAddress, public string ScriptPubkeyAddress { get; set; } = scriptPubkeyAddress; [JsonPropertyName("value")] - public int Value { get; set; } = value; + public decimal Value { get; set; } = value; } public class MempoolConfirmedStatus(bool confirmed, int blockHeight)