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

DecodeRawTransaction does not populate addresses #127

Open
p-v-n opened this issue Jan 8, 2023 · 0 comments
Open

DecodeRawTransaction does not populate addresses #127

p-v-n opened this issue Jan 8, 2023 · 0 comments

Comments

@p-v-n
Copy link

p-v-n commented Jan 8, 2023

When DecodeRawTransaction is called, the Addresses property of a Vout.ScriptPubKey property is not initialized and is always null.
Upon investigation, it looks like the root cause it that Bitcoin Core RPC is returning a single address, not a collection of addresses, therefore, the de-serialization does not initialize Addresses property.
It can be illustrated by using bitcoin-cli:

Command:

bitcoin-cli decoderawtransaction 01000000010b1cc4b8d8aec036e0c86ab030e1be9688c6d9602aee604dad49c6b2f41ce3e8000000008a47304402202b3eb2df6ba7961a7aaf31edc1b5153a08fc2d42ff7edce4270d73c220c94d8102201f31eca6778af707616d8809572b5c32c93ae8633a7c0254c415c7c06824d6f8014104418a55853e122a5f31df51d08048eb677c42b76fcf3d73f4ec3590f11291f365e2b37fa99c5227741f82a149f1b2ba91f01f88936c717fd6e21fd83c82c69b1effffffff0200000000000000001976a914379e4e5bcdeabc8ba94119927f1cee83d5f2180f88ac6d2a0f00000000001976a914267ee9b39a33c45a2cdf3c7bccc373de86c1fcd988ac00000000

Output:

{
  "txid": "2f2442f68e38b980a6c4cec21e71851b0d8a5847d85208331a27321a9967bbd6",
  "hash": "2f2442f68e38b980a6c4cec21e71851b0d8a5847d85208331a27321a9967bbd6",
  "version": 1,
  "size": 257,
  "vsize": 257,
  "weight": 1028,
  "locktime": 0,
  "vin": [
    {
      "txid": "e8e31cf4b2c649ad4d60ee2a60d9c68896bee130b06ac8e036c0aed8b8c41c0b",
      "vout": 0,
      "scriptSig": {
        "asm": "304402202b3eb2df6ba7961a7aaf31edc1b5153a08fc2d42ff7edce4270d73c220c94d8102201f31eca6778af707616d8809572b5c32c93ae8633a7c0254c415c7c06824d6f8[ALL] 04418a55853e122a5f31df51d08048eb677c42b76fcf3d73f4ec3590f11291f365e2b37fa99c5227741f82a149f1b2ba91f01f88936c717fd6e21fd83c82c69b1e",
        "hex": "47304402202b3eb2df6ba7961a7aaf31edc1b5153a08fc2d42ff7edce4270d73c220c94d8102201f31eca6778af707616d8809572b5c32c93ae8633a7c0254c415c7c06824d6f8014104418a55853e122a5f31df51d08048eb677c42b76fcf3d73f4ec3590f11291f365e2b37fa99c5227741f82a149f1b2ba91f01f88936c717fd6e21fd83c82c69b1e"
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 0.00000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 379e4e5bcdeabc8ba94119927f1cee83d5f2180f OP_EQUALVERIFY OP_CHECKSIG",
        "desc": "addr(1655orL9kVqVqCGMjGLogr11MFmeDBXw61)#w5ycn65c",
        "hex": "76a914379e4e5bcdeabc8ba94119927f1cee83d5f2180f88ac",
        "address": "1655orL9kVqVqCGMjGLogr11MFmeDBXw61",
        "type": "pubkeyhash"
      }
    },
    {
      "value": 0.00993901,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 267ee9b39a33c45a2cdf3c7bccc373de86c1fcd9 OP_EQUALVERIFY OP_CHECKSIG",
        "desc": "addr(14WYiMRrD8sobRcmLYdZCugD95KmyuYtBZ)#tmugevwe",
        "hex": "76a914267ee9b39a33c45a2cdf3c7bccc373de86c1fcd988ac",
        "address": "14WYiMRrD8sobRcmLYdZCugD95KmyuYtBZ",
        "type": "pubkeyhash"
      }
    }
  ]
}

One way of fixing this issue would be to change ScriptPubKey definition to this:

    public class ScriptPubKey
    {
        public string Asm { get; set; }
        public string Hex { get; set; }
        public int ReqSigs { get; set; }
        public string Type { get; set; }
        public string Address { get; set; }
    }

I don't know whether Bitcoin RPC used to return a list of addresses at some point, so List<string> Addresses was being properly populated, or whether this was always broken. If it's the latter, then it can be argued that the concern about backwards compatibility is small or even virtually non-existent.

As a side note not related to this issue, but related to general completeness of the library, "Desc" property, which is returned by BItcoin RPC, is currently missing from ScriptPubKey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant