Skip to content

Commit

Permalink
Merge pull request #2 from remcoros/fix-value-type
Browse files Browse the repository at this point in the history
fix: minor issue fetching transaction data for larger amounts
  • Loading branch information
remcoros authored Sep 8, 2024
2 parents f9d8f5d + fc37c7e commit 1e72ec3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions manifest.yaml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion scripts/procedures/migrations.ts
Original file line number Diff line number Diff line change
@@ -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" );
13 changes: 8 additions & 5 deletions src/PushTX/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ await Parallel.ForEachAsync(vins.OfType<JsonObject>(), 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<JsonObject>()
Expand All @@ -153,7 +156,7 @@ await Parallel.ForEachAsync(vins.OfType<JsonObject>(), 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();
Expand All @@ -164,7 +167,7 @@ await Parallel.ForEachAsync(vins.OfType<JsonObject>(), 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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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)
Expand Down

0 comments on commit 1e72ec3

Please sign in to comment.