blockchain-etl / bitcoin-etl

ETL scripts for Bitcoin, Litecoin, Dash, Zcash, Doge, Bitcoin Cash. Available in Google BigQuery https://goo.gl/oY5BCQ
https://twitter.com/BlockchainETL
MIT License
410 stars 123 forks source link

add the function of parsing out a bitcoin address from pubscript(pubkey) #45

Closed SuperLSH closed 4 years ago

SuperLSH commented 4 years ago
  1. for type"pubkey", parsing out the bircoin address form script_asm
  2. for OP_RETURN script, still keep the type as "nonstandard" and set the address as "nonstandard address"

Run the command: bitcoinetl export_all --start 620020 --end 620020 \ --partition-batch-size 5 \ --provider-uri http://username:password@localhost:8332 \ --output-dir ../bitcoin/temp \ --chain bitcoin \ --enrich true And here is one line of enriched file: {"hash": "3e749dc99d2c42e89ec9ee0abc51a37f9f855abeb91d9aece77661b8489e6576", "size": 446, "virtual_size": 446, "version": 1, "lock_time": 0, "block_number": 620020, "block_hash": "00000000000000000005ab9d9751d363592772a2def9f8570c4fb9430810029a", "block_timestamp": 1583256310, "is_coinbase": false, "index": 1058, "inputs": [{"index": 0, "spent_transaction_hash": "3af73cb6b080fb736ca1510c6dd178b4497a1b21eea0975258d789460ccb13c2", "spent_output_index": 1, "script_asm": "0 3045022100fcaeab9c8de71a00a3d8462fc4ae6f1e634c2d7a3230819b7bd06af8f39238c402204ea14023090bf7a7b4b57bdfcc2adfd715f40bbe974dd6ebd06f188bc43caf89[ALL|ANYONECANPAY] 3045022100cdcaf16caeae185f295ef3b2831f3efb898a6ebc798d5022933d53c6c200ff1f02206eb1dce9d09a19f2924bb163e5bd2351601b235cc3a1b09c2b34f61bda44d094[ALL|ANYONECANPAY]", "script_hex": "00483045022100fcaeab9c8de71a00a3d8462fc4ae6f1e634c2d7a3230819b7bd06af8f39238c402204ea14023090bf7a7b4b57bdfcc2adfd715f40bbe974dd6ebd06f188bc43caf8981483045022100cdcaf16caeae185f295ef3b2831f3efb898a6ebc798d5022933d53c6c200ff1f02206eb1dce9d09a19f2924bb163e5bd2351601b235cc3a1b09c2b34f61bda44d09481", "sequence": 4294967295, "required_signatures": 2, "type": "multisig", "addresses": ["185UNTEGmdF25Mz7PeNDYsF7NAe5YN3TDT", "1AuJVeXu3SmMBR6voUwo8BnvDEr2e7Zbz1"], "value": 9000}, {"index": 1, "spent_transaction_hash": "38e02dc808f780408b93292e22f1430f99362ca265af3b8c0ba9ac7d3781e30a", "spent_output_index": 3, "script_asm": "304402202e162f673a45f8fb8a6b4f4d958b5300f37ece2eefac1183fb220a15a032c03d022041edb332fba33bafeec109140088ff47cb73a752e1df55aa69969c73e00bf309[ALL]", "script_hex": "47304402202e162f673a45f8fb8a6b4f4d958b5300f37ece2eefac1183fb220a15a032c03d022041edb332fba33bafeec109140088ff47cb73a752e1df55aa69969c73e00bf30901", "sequence": 4294967295, "required_signatures": null, "type": "pubkey", "addresses": ["1CN8i6YVprrxtEYkjZPH8uNYX9zNrxEA3f"], "value": 5000}], "outputs": [{"index": 0, "script_asm": "OP_RETURN 15035 b7540d511806209ad44c2b154a013543dede8e26 e1388efbd859b68f9477ef75401938143d9385f3", "script_hex": "6a02bb3a14b7540d511806209ad44c2b154a013543dede8e2614e1388efbd859b68f9477ef75401938143d9385f3", "required_signatures": null, "type": "nonstandard", "addresses": ["nonstandard address"], "value": 0}, {"index": 1, "script_asm": "2 03fc92d155f45f73f5783dd10596c12f6622561ffa6c3dce93b2f017b642bb57fc 03cee36cc3a23c7afeb8ca1a7294b9141b0a224b63e40c0418974df154dae2caf6 2 OP_CHECKMULTISIG", "script_hex": "522103fc92d155f45f73f5783dd10596c12f6622561ffa6c3dce93b2f017b642bb57fc2103cee36cc3a23c7afeb8ca1a7294b9141b0a224b63e40c0418974df154dae2caf652ae", "required_signatures": 2, "type": "multisig", "addresses": ["185UNTEGmdF25Mz7PeNDYsF7NAe5YN3TDT", "1AuJVeXu3SmMBR6voUwo8BnvDEr2e7Zbz1"], "value": 9000}], "input_count": 2, "output_count": 2, "input_value": 14000, "output_value": 9000, "fee": 5000} Check it from here: https://www.blockchain.com/btc/tx/3e749dc99d2c42e89ec9ee0abc51a37f9f855abeb91d9aece77661b8489e6576

tokusyu commented 4 years ago

hi, thank you for you code! but I think this code has two problems.

  1. supports bitcoin address only because "version" parameter "00" is hard coded.
  2. doesn't keep "type" value if no "address" in response.(qtum has additional types without "address")

many bitcoin forked coins imported code from bitcoin core, so this behavior may spread to other coins and we need to consider it.

SuperLSH commented 4 years ago

hi, thank you for you code! but I think this code has two problems.

  1. supports bitcoin address only because "version" parameter "00" is hard coded.
  2. doesn't keep "type" value if no "address" in response.(qtum has additional types without "address")

many bitcoin forked coins imported code from bitcoin core, so this behavior may spread to other coins and we need to consider it.

Thank you for your reply. The two problems you mentioned do exist. Not taking into account bitcoin's derivative cryptocurrency is my weakness.