hirosystems / chainhook

Extract transactions from Stacks and Bitcoin and build event driven re-org resistant indexers and databases.
GNU General Public License v3.0
158 stars 65 forks source link

p2pk equals brings back 0 actions taken but data is present #389

Closed timstackblock closed 10 months ago

timstackblock commented 1 year ago

Describe the bug p2pk equals is not bringing back data that I can see is present in the JSON output for a bitcoin transaction, here is the JSON output for the bitcoin transaction below.

I am scanning for = "equals": "1K6KoYC69NnafWJ7YgtrpwJxBLiijWqwa6"

Here are my decodes for the json file

P2PKH (Pay-to-Public-Key-Hash) Output:

Address: "1K6KoYC69NnafWJ7YgtrpwJxBLiijWqwa6" Output Script: "76a914c6740a12d0a7d556f89782bf5faf0e12cf25a63988ac" This is a standard P2PKH output, where the receiver's address is encoded in the output script.

https://www.blockchain.com/explorer/transactions/btc/b77dbae24e68470100e29707d3d4f215e0fb562701cc0df5e73ec74e6783eacb

BITCOIN TRANSACTION JSON OUTPUT FROM THE BITCOIN EXPLORER

[{
  "txid": "04f1b6c0cee44a8ba10cade754a36f405576120d33abd58b59b54af8109d7fc8",
  "size": 214,
  "version": 2,
  "locktime": 0,
  "fee": 0,
  "inputs": [
    {
      "coinbase": true,
      "txid": "0000000000000000000000000000000000000000000000000000000000000000",
      "output": 4294967295,
      "sigscript": "037a420c0460ccdc642f466f756e6472792055534120506f6f6c202364726f70676f6c642f09e42844000001ca10010000",
      "sequence": 4294967295,
      "pkscript": null,
      "value": null,
      "address": null,
      "witness": [
        "0000000000000000000000000000000000000000000000000000000000000000"
      ]
    }
  ],
  "outputs": [
    {
      "address": "bc1qxhmdufsvnuaaaer4ynz88fspdsxq2h9e9cetdj",
      "pkscript": "001435f6de260c9f3bdee47524c473a6016c0c055cb9",
      "value": 636015433,
      "spent": false,
      "spender": null
    },
    {
      "address": null,
      "pkscript": "6a24aa21a9ed59ffb003fd75f0f029a78b1ce2e3ee565b59001b040ea4535d4a711f3dde721f",
      "value": 0,
      "spent": false,
      "spender": null
    }
  ],
  "block": {
    "height": 803450,
    "position": 0
  },
  "deleted": false,
  "time": 1692191839,
  "rbf": false,
  "weight": 748
}](https://www.blockchain.com/explorer/transactions/btc/b77dbae24e68470100e29707d3d4f215e0fb562701cc0df5e73ec74e6783eacb)

MY PREDICATE FILE

{
  "uuid": "1",
  "name": "Hello Ordinals",
  "chain": "bitcoin",
  "version": 1,
  "networks": {
    "mainnet": {
      "start_block": 803449,
      "end_block": 803453,
      "if_this": {
        "scope": "outputs",
        "p2wsh": {
          "equals": "1K6KoYC69NnafWJ7YgtrpwJxBLiijWqwa6"
        }
      },
      "then_that": {
        "file_append": {
          "path": "automate/tests/bitcoin-predicates/p2pkh/p2pkh-file-results.json"
        }
      }
    }
  }

OUTPUT FROM CHAINHOOK

Screenshot 2023-08-16 at 11 56 31 AM
csgui commented 10 months ago

There is a problem with the predicate.

The type of transaction that was used in the Chainhook predicate is a SegWit P2WSH.

...
"p2wsh": {
    "equals": "1K6KoYC69NnafWJ7YgtrpwJxBLiijWqwa6"
}
...

To comparison using a Pay-to-Public-Key-Hash (P2PKH) the JSON key should be p2pkh

...
"p2pkh": {
    "equals": "1K6KoYC69NnafWJ7YgtrpwJxBLiijWqwa6"
}
...

With that change Chainhook is returning the following JSON result:

{
  "apply": [
    {
      "block_identifier": {
        "hash": "0x000000000000000000032d8644907c0ac72bd741dc3507874e9afc315bc7b4f2",
        "index": 803452
      },
      "metadata": {
        "network": "mainnet"
      },
      "parent_block_identifier": {
        "hash": "0x00000000000000000004d8e3682495f6953b2f45996d38828f44f22dce45f3ad",
        "index": 803451
      },
      "timestamp": 1692193080,
      "transactions": [
        {
          "metadata": {
            "proof": null
          },
          "operations": [],
          "transaction_identifier": {
            "hash": "0xb77dbae24e68470100e29707d3d4f215e0fb562701cc0df5e73ec74e6783eacb"
          }
        }
      ]
    }
  ],
  "chainhook": {
    "is_streaming_blocks": false,
    "predicate": {
      "p2pkh": {
        "equals": "1K6KoYC69NnafWJ7YgtrpwJxBLiijWqwa6"
      },
      "scope": "outputs"
    },
    "uuid": "1"
  },
  "rollback": []
}
{
  "apply": [
    {
      "block_identifier": {
        "hash": "0x000000000000000000032d8644907c0ac72bd741dc3507874e9afc315bc7b4f2",
        "index": 803452
      },
      "metadata": {
        "network": "mainnet"
      },
      "parent_block_identifier": {
        "hash": "0x00000000000000000004d8e3682495f6953b2f45996d38828f44f22dce45f3ad",
        "index": 803451
      },
      "timestamp": 1692193080,
      "transactions": [
        {
          "metadata": {
            "proof": null
          },
          "operations": [],
          "transaction_identifier": {
            "hash": "0xb77dbae24e68470100e29707d3d4f215e0fb562701cc0df5e73ec74e6783eacb"
          }
        }
      ]
    }
  ],
  "chainhook": {
    "is_streaming_blocks": false,
    "predicate": {
      "p2pkh": {
        "equals": "1K6KoYC69NnafWJ7YgtrpwJxBLiijWqwa6"
      },
      "scope": "outputs"
    },
    "uuid": "1"
  },
  "rollback": []
}