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

No SpentTxId for P2SH addresses #444

Closed
ndrego opened this issue Jan 2, 2016 · 1 comment
Closed

No SpentTxId for P2SH addresses #444

ndrego opened this issue Jan 2, 2016 · 1 comment

Comments

@ndrego
Copy link

ndrego commented Jan 2, 2016

Using bitcore == 2.0.0, insight-api == 0.3.1 and bitcore-node == 1.0.1, I am unable to get the spending txid for a P2SH address. In all of the following calls, the address to keep track of is 3MeZDtTzXmrGxxRgcs51CJdbeUesPHnNkd.

$ curl http://localhost:3001/insight-api/tx/5d72866a181e37c6fe1b2624f48955f75d6c08974004d43a3bbd1e62eddfef91 | jq
{
  "txid": "5d72866a181e37c6fe1b2624f48955f75d6c08974004d43a3bbd1e62eddfef91",
  "version": 1,
  "locktime": 0,
  "vin": [
    {
      "txid": "19f733b4fe010220ae82c137845aa759d97cacb8e1aa6cf1e575ddb34661e861",
      "vout": 0,
      "scriptSig": {
        "asm": "3044022034815bb602501467c69a052fc8f2c08107259a0ef0af4cf391b6bc0ef26cdc40022044bcc0793ba8535af88c30396ebeb827406ef4de20deaae3aa64474babb98fbe01 02f463a13a3c70d5c3c322faaf59a4f07b982f27cede45c2fd8bb8e456b4976bac",
        "hex": "473044022034815bb602501467c69a052fc8f2c08107259a0ef0af4cf391b6bc0ef26cdc40022044bcc0793ba8535af88c30396ebeb827406ef4de20deaae3aa64474babb98fbe012102f463a13a3c70d5c3c322faaf59a4f07b982f27cede45c2fd8bb8e456b4976bac"
      },
      "sequence": 4294967295,
      "n": 0,
      "addr": "1NmPCkWvNRrSKEwH4A8cnTrd6naFUJM1yt",
      "valueSat": 12502,
      "value": 0.00012502,
      "doubleSpentTxID": null
    },
    {
      "txid": "4b071b7ae4116c1be4cfc2c05ca5d5adcafb44da4191587eb124a2a10979241c",
      "vout": 1,
      "scriptSig": {
        "asm": "3045022100d5baa898275b71e29862bcfe11fbe4773fcf4bcac4b7cd42c9a158408ef2094b02202163e360e02de794e118da2df773cbe570670ecea7cce0ac8eaf0a76b23a431501 02f463a13a3c70d5c3c322faaf59a4f07b982f27cede45c2fd8bb8e456b4976bac",
        "hex": "483045022100d5baa898275b71e29862bcfe11fbe4773fcf4bcac4b7cd42c9a158408ef2094b02202163e360e02de794e118da2df773cbe570670ecea7cce0ac8eaf0a76b23a4315012102f463a13a3c70d5c3c322faaf59a4f07b982f27cede45c2fd8bb8e456b4976bac"
      },
      "sequence": 4294967295,
      "n": 1,
      "addr": "1NmPCkWvNRrSKEwH4A8cnTrd6naFUJM1yt",
      "valueSat": 39998,
      "value": 0.00039998,
      "doubleSpentTxID": null
    },
    {
      "txid": "8b6bdb768c3fe5fde9fd7cbdd61a765b4c47e75073f86432b5ea36fe381a86c9",
      "vout": 1,
      "scriptSig": {
        "asm": "3045022100923ff8a988e28ad0e54cbd417bdfeb8d250a82bfabc424f0414f3423855458d60220744b4a92279ca030dd22af44fd4d14fa4da0213a5ba158607366c2e266910c3d01 024d5be20d806be94f102e11e37970b006ba1e1d8d898ccb09adf7ce9e200c4780",
        "hex": "483045022100923ff8a988e28ad0e54cbd417bdfeb8d250a82bfabc424f0414f3423855458d60220744b4a92279ca030dd22af44fd4d14fa4da0213a5ba158607366c2e266910c3d0121024d5be20d806be94f102e11e37970b006ba1e1d8d898ccb09adf7ce9e200c4780"
      },
      "sequence": 4294967295,
      "n": 2,
      "addr": "1KFGUyLTBVxGU4nkDC2E37fVHBFgsBpBWL",
      "valueSat": 69498,
      "value": 0.00069498,
      "doubleSpentTxID": null
    }
  ],
  "vout": [
    {
      "value": "0.00000998",
      "n": 0,
      "scriptPubKey": {
        "hex": "76a914314d768ce14fc1f5dffdac1e4a0ed13705d4a4a688ac",
        "asm": "OP_DUP OP_HASH160 314d768ce14fc1f5dffdac1e4a0ed13705d4a4a6 OP_EQUALVERIFY OP_CHECKSIG",
        "addresses": [
          "15VgudW7RawMLhKuSvovD7jbkk66wtCaBs"
        ],
        "type": "pubkeyhash"
      },
      "spentTxId": "ea756854b1254b87fe6aaed036ce67d5f0749ac86e2c7fd6a917d60fb4734369",
      "spentIndex": 2
    },
    {
      "value": "0.00111000",
      "n": 1,
      "scriptPubKey": {
        "hex": "a914daeb651917aff08efa258abe1960890402affd2c87",
        "asm": "OP_HASH160 daeb651917aff08efa258abe1960890402affd2c OP_EQUAL",
        "addresses": [
          "3MeZDtTzXmrGxxRgcs51CJdbeUesPHnNkd"
        ],
        "type": "scripthash"
      }
    }
  ],
  "blockhash": "000000000000000003da9160e08f2e507a8949e52af90302287dc34c56642b4b",
  "confirmations": 2977,
  "time": 1450148002,
  "blocktime": 1450148002,
  "valueOut": 0.00111998,
  "size": 519,
  "valueIn": 0.00121998,
  "fees": 0.0001
}

Similarly, if I look up transactions for the address in question, I only see the funding transaction:

$ curl http://localhost:3001/insight-api/addrs/3MeZDtTzXmrGxxRgcs51CJdbeUesPHnNkd/txs | jq
{
  "totalItems": 1,
  "from": 0,
  "to": 1,
  "items": [
    {
      "txid": "5d72866a181e37c6fe1b2624f48955f75d6c08974004d43a3bbd1e62eddfef91",
      "version": 1,
      "locktime": 0,
      "vin": [
        {
          "txid": "19f733b4fe010220ae82c137845aa759d97cacb8e1aa6cf1e575ddb34661e861",
          "vout": 0,
          "scriptSig": {
            "asm": "3044022034815bb602501467c69a052fc8f2c08107259a0ef0af4cf391b6bc0ef26cdc40022044bcc0793ba8535af88c30396ebeb827406ef4de20deaae3aa64474babb98fbe01 02f463a13a3c70d5c3c322faaf59a4f07b982f27cede45c2fd8bb8e456b4976bac",
            "hex": "473044022034815bb602501467c69a052fc8f2c08107259a0ef0af4cf391b6bc0ef26cdc40022044bcc0793ba8535af88c30396ebeb827406ef4de20deaae3aa64474babb98fbe012102f463a13a3c70d5c3c322faaf59a4f07b982f27cede45c2fd8bb8e456b4976bac"
          },
          "sequence": 4294967295,
          "n": 0,
          "addr": "1NmPCkWvNRrSKEwH4A8cnTrd6naFUJM1yt",
          "valueSat": 12502,
          "value": 0.00012502,
          "doubleSpentTxID": null
        },
        {
          "txid": "4b071b7ae4116c1be4cfc2c05ca5d5adcafb44da4191587eb124a2a10979241c",
          "vout": 1,
          "scriptSig": {
            "asm": "3045022100d5baa898275b71e29862bcfe11fbe4773fcf4bcac4b7cd42c9a158408ef2094b02202163e360e02de794e118da2df773cbe570670ecea7cce0ac8eaf0a76b23a431501 02f463a13a3c70d5c3c322faaf59a4f07b982f27cede45c2fd8bb8e456b4976bac",
            "hex": "483045022100d5baa898275b71e29862bcfe11fbe4773fcf4bcac4b7cd42c9a158408ef2094b02202163e360e02de794e118da2df773cbe570670ecea7cce0ac8eaf0a76b23a4315012102f463a13a3c70d5c3c322faaf59a4f07b982f27cede45c2fd8bb8e456b4976bac"
          },
          "sequence": 4294967295,
          "n": 1,
          "addr": "1NmPCkWvNRrSKEwH4A8cnTrd6naFUJM1yt",
          "valueSat": 39998,
          "value": 0.00039998,
          "doubleSpentTxID": null
        },
        {
          "txid": "8b6bdb768c3fe5fde9fd7cbdd61a765b4c47e75073f86432b5ea36fe381a86c9",
          "vout": 1,
          "scriptSig": {
            "asm": "3045022100923ff8a988e28ad0e54cbd417bdfeb8d250a82bfabc424f0414f3423855458d60220744b4a92279ca030dd22af44fd4d14fa4da0213a5ba158607366c2e266910c3d01 024d5be20d806be94f102e11e37970b006ba1e1d8d898ccb09adf7ce9e200c4780",
            "hex": "483045022100923ff8a988e28ad0e54cbd417bdfeb8d250a82bfabc424f0414f3423855458d60220744b4a92279ca030dd22af44fd4d14fa4da0213a5ba158607366c2e266910c3d0121024d5be20d806be94f102e11e37970b006ba1e1d8d898ccb09adf7ce9e200c4780"
          },
          "sequence": 4294967295,
          "n": 2,
          "addr": "1KFGUyLTBVxGU4nkDC2E37fVHBFgsBpBWL",
          "valueSat": 69498,
          "value": 0.00069498,
          "doubleSpentTxID": null
        }
      ],
      "vout": [
        {
          "value": "0.00000998",
          "n": 0,
          "scriptPubKey": {
            "hex": "76a914314d768ce14fc1f5dffdac1e4a0ed13705d4a4a688ac",
            "asm": "OP_DUP OP_HASH160 314d768ce14fc1f5dffdac1e4a0ed13705d4a4a6 OP_EQUALVERIFY OP_CHECKSIG",
            "addresses": [
              "15VgudW7RawMLhKuSvovD7jbkk66wtCaBs"
            ],
            "type": "pubkeyhash"
          },
          "spentTxId": "ea756854b1254b87fe6aaed036ce67d5f0749ac86e2c7fd6a917d60fb4734369",
          "spentIndex": 2
        },
        {
          "value": "0.00111000",
          "n": 1,
          "scriptPubKey": {
            "hex": "a914daeb651917aff08efa258abe1960890402affd2c87",
            "asm": "OP_HASH160 daeb651917aff08efa258abe1960890402affd2c OP_EQUAL",
            "addresses": [
              "3MeZDtTzXmrGxxRgcs51CJdbeUesPHnNkd"
            ],
            "type": "scripthash"
          }
        }
      ],
      "blockhash": "000000000000000003da9160e08f2e507a8949e52af90302287dc34c56642b4b",
      "confirmations": 2977,
      "time": 1450148002,
      "blocktime": 1450148002,
      "valueOut": 0.00111998,
      "size": 519,
      "valueIn": 0.00121998,
      "fees": 0.0001
    }
  ]
}

However, insight clearly knows about the spending txn:

$ curl http://localhost:3001/insight-api/tx/bed5c9871fbcb6f63cd629579f532ed5dc728136e027ffdf81ccfacb7b181967 | jq
{
  "txid": "bed5c9871fbcb6f63cd629579f532ed5dc728136e027ffdf81ccfacb7b181967",
  "version": 1,
  "locktime": 0,
  "vin": [
    {
      "txid": "5d72866a181e37c6fe1b2624f48955f75d6c08974004d43a3bbd1e62eddfef91",
      "vout": 1,
      "scriptSig": {
        "asm": "3044022049d1f41a867aa84266a1f5d2f6283d2b1e6ee07d068a098615d7a7868a96ed78022060c798cbb4740277cb095c399fb10ebd2716894c203527b0e6e3ed797400d10701 3045022100de7c4c35c263cc2e1df1f2b06925225a72b9cb28e3b8bae4db7b078a1e4ac25c022031103dbe8993e94daa119d4c78e0bf52d3513e152d8b5bc192f8cb26ac3c683901 OP_1 OP_PUSHDATA1 632102f1fff97def324ddea032fed4c8249113b8dce12aaf614d11bb833e587072c8a9ad6704a9a07056b1756821026179020dba5ad8275cf6389a85a00c08f3597bb8617af8148f249a4cd719ab39ac",
        "hex": "473044022049d1f41a867aa84266a1f5d2f6283d2b1e6ee07d068a098615d7a7868a96ed78022060c798cbb4740277cb095c399fb10ebd2716894c203527b0e6e3ed797400d10701483045022100de7c4c35c263cc2e1df1f2b06925225a72b9cb28e3b8bae4db7b078a1e4ac25c022031103dbe8993e94daa119d4c78e0bf52d3513e152d8b5bc192f8cb26ac3c683901514c50632102f1fff97def324ddea032fed4c8249113b8dce12aaf614d11bb833e587072c8a9ad6704a9a07056b1756821026179020dba5ad8275cf6389a85a00c08f3597bb8617af8148f249a4cd719ab39ac"
      },
      "sequence": 4294967295,
      "n": 0,
      "addr": "3MeZDtTzXmrGxxRgcs51CJdbeUesPHnNkd",
      "valueSat": 111000,
      "value": 0.00111,
      "doubleSpentTxID": null
    }
  ],
  "vout": [
    {
      "value": "0.00100000",
      "n": 0,
      "scriptPubKey": {
        "hex": "76a914ffffb9d45c6cb46133f55a83c2fde9edb1c5f50688ac",
        "asm": "OP_DUP OP_HASH160 ffffb9d45c6cb46133f55a83c2fde9edb1c5f506 OP_EQUALVERIFY OP_CHECKSIG",
        "addresses": [
          "1QLbf4gnY1p6kDWMnBgWSjh45ezEZY5Cg9"
        ],
        "type": "pubkeyhash"
      },
      "spentTxId": "ea756854b1254b87fe6aaed036ce67d5f0749ac86e2c7fd6a917d60fb4734369",
      "spentIndex": 0
    },
    {
      "value": "0.00001000",
      "n": 1,
      "scriptPubKey": {
        "hex": "76a914314d768ce14fc1f5dffdac1e4a0ed13705d4a4a688ac",
        "asm": "OP_DUP OP_HASH160 314d768ce14fc1f5dffdac1e4a0ed13705d4a4a6 OP_EQUALVERIFY OP_CHECKSIG",
        "addresses": [
          "15VgudW7RawMLhKuSvovD7jbkk66wtCaBs"
        ],
        "type": "pubkeyhash"
      },
      "spentTxId": "ea756854b1254b87fe6aaed036ce67d5f0749ac86e2c7fd6a917d60fb4734369",
      "spentIndex": 3
    }
  ],
  "blockhash": "000000000000000003da9160e08f2e507a8949e52af90302287dc34c56642b4b",
  "confirmations": 2977,
  "time": 1450148002,
  "blocktime": 1450148002,
  "valueOut": 0.00101,
  "size": 347,
  "valueIn": 0.00111,
  "fees": 0.0001
}

What's interesting is that it seems older versions of the insight-api (at least that running on https://insight.bitpay.com) do get it correct:

$ curl https://insight.bitpay.com/api/tx/5d72866a181e37c6fe1b2624f48955f75d6c08974004d43a3bbd1e62eddfef91 | jq
{
  "txid": "5d72866a181e37c6fe1b2624f48955f75d6c08974004d43a3bbd1e62eddfef91",
  "version": 1,
  "locktime": 0,
  "vin": [
    {
      "txid": "19f733b4fe010220ae82c137845aa759d97cacb8e1aa6cf1e575ddb34661e861",
      "vout": 0,
      "scriptSig": {
        "asm": "3044022034815bb602501467c69a052fc8f2c08107259a0ef0af4cf391b6bc0ef26cdc40022044bcc0793ba8535af88c30396ebeb827406ef4de20deaae3aa64474babb98fbe01 02f463a13a3c70d5c3c322faaf59a4f07b982f27cede45c2fd8bb8e456b4976bac",
        "hex": "473044022034815bb602501467c69a052fc8f2c08107259a0ef0af4cf391b6bc0ef26cdc40022044bcc0793ba8535af88c30396ebeb827406ef4de20deaae3aa64474babb98fbe012102f463a13a3c70d5c3c322faaf59a4f07b982f27cede45c2fd8bb8e456b4976bac"
      },
      "sequence": 4294967295,
      "n": 0,
      "addr": "1NmPCkWvNRrSKEwH4A8cnTrd6naFUJM1yt",
      "valueSat": 12502,
      "value": 0.00012502,
      "doubleSpentTxID": null,
      "isConfirmed": true,
      "confirmations": 3493,
      "unconfirmedInput": false
    },
    {
      "txid": "4b071b7ae4116c1be4cfc2c05ca5d5adcafb44da4191587eb124a2a10979241c",
      "vout": 1,
      "scriptSig": {
        "asm": "3045022100d5baa898275b71e29862bcfe11fbe4773fcf4bcac4b7cd42c9a158408ef2094b02202163e360e02de794e118da2df773cbe570670ecea7cce0ac8eaf0a76b23a431501 02f463a13a3c70d5c3c322faaf59a4f07b982f27cede45c2fd8bb8e456b4976bac",
        "hex": "483045022100d5baa898275b71e29862bcfe11fbe4773fcf4bcac4b7cd42c9a158408ef2094b02202163e360e02de794e118da2df773cbe570670ecea7cce0ac8eaf0a76b23a4315012102f463a13a3c70d5c3c322faaf59a4f07b982f27cede45c2fd8bb8e456b4976bac"
      },
      "sequence": 4294967295,
      "n": 1,
      "addr": "1NmPCkWvNRrSKEwH4A8cnTrd6naFUJM1yt",
      "valueSat": 39998,
      "value": 0.00039998,
      "doubleSpentTxID": null,
      "isConfirmed": true,
      "confirmations": 3493,
      "unconfirmedInput": false
    },
    {
      "txid": "8b6bdb768c3fe5fde9fd7cbdd61a765b4c47e75073f86432b5ea36fe381a86c9",
      "vout": 1,
      "scriptSig": {
        "asm": "3045022100923ff8a988e28ad0e54cbd417bdfeb8d250a82bfabc424f0414f3423855458d60220744b4a92279ca030dd22af44fd4d14fa4da0213a5ba158607366c2e266910c3d01 024d5be20d806be94f102e11e37970b006ba1e1d8d898ccb09adf7ce9e200c4780",
        "hex": "483045022100923ff8a988e28ad0e54cbd417bdfeb8d250a82bfabc424f0414f3423855458d60220744b4a92279ca030dd22af44fd4d14fa4da0213a5ba158607366c2e266910c3d0121024d5be20d806be94f102e11e37970b006ba1e1d8d898ccb09adf7ce9e200c4780"
      },
      "sequence": 4294967295,
      "n": 2,
      "addr": "1KFGUyLTBVxGU4nkDC2E37fVHBFgsBpBWL",
      "valueSat": 69498,
      "value": 0.00069498,
      "doubleSpentTxID": null,
      "isConfirmed": true,
      "confirmations": 3495,
      "unconfirmedInput": false
    }
  ],
  "vout": [
    {
      "value": "0.00000998",
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 314d768ce14fc1f5dffdac1e4a0ed13705d4a4a6 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914314d768ce14fc1f5dffdac1e4a0ed13705d4a4a688ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "15VgudW7RawMLhKuSvovD7jbkk66wtCaBs"
        ]
      },
      "spentTxId": "ea756854b1254b87fe6aaed036ce67d5f0749ac86e2c7fd6a917d60fb4734369",
      "spentIndex": 2,
      "spentTs": 1450306110
    },
    {
      "value": "0.00111000",
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_HASH160 daeb651917aff08efa258abe1960890402affd2c OP_EQUAL",
        "hex": "a914daeb651917aff08efa258abe1960890402affd2c87",
        "reqSigs": 1,
        "type": "scripthash",
        "addresses": [
          "3MeZDtTzXmrGxxRgcs51CJdbeUesPHnNkd"
        ]
      },
      "spentTxId": "bed5c9871fbcb6f63cd629579f532ed5dc728136e027ffdf81ccfacb7b181967",
      "spentIndex": 0,
      "spentTs": 1450148002
    }
  ],
  "blockhash": "000000000000000003da9160e08f2e507a8949e52af90302287dc34c56642b4b",
  "confirmations": 2977,
  "time": 1450148002,
  "blocktime": 1450148002,
  "valueOut": 0.00111998,
  "size": 519,
  "valueIn": 0.00121998,
  "fees": 0.0001
}

For completeness:

$ curl http://localhost:3001/insight-api/status | jq
{
  "info": {
    "version": 110200,
    "protocolversion": 70002,
    "blocks": 391438,
    "timeoffset": 0,
    "connections": 8,
    "difficulty": 103880340815.45589,
    "testnet": false,
    "relayfee": 5000,
    "errors": ""
  }
}

Is there some sort of bug in newer versions preventing P2SH addresses from being correctly indexed?

@braydonf
Copy link
Contributor

This should be resolved in bitcore@4.0.0 (with insight-api@0.4.0 and bitcore-node@3.0.0). In summary, the spent info is now indexed based on the address of the previous output script instead of determining the address from the input script which only works in standard p2sh cases. Indexes are now a part of bitcoin itself, see: https://github.com/bitpay/bitcoin/tree/0.12-bitcore

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

2 participants