Address

如何從原始交易中的輸入中提取地址

  • January 11, 2019

我需要幫助才能在離線模式下從“vin”獲取輸入地址。

我不知道<https://live.blockcypher.com/btc/decodetx/>是如何做到的。

原始交易範例:

交易編號:b0dd3d915a568c9d48e37b3fbfca58ae3276a5dba176fdf30f18af794310cc02

原始交易:

01000000000102b4370d52c1e1dc67b0250ef7bd5265146d4def0beacfefd99660a86baf97faf000000000232200202dc520822e73d4262000d3b456b16df1d07b0ba9d238f3063379d65840fd38e7feffffff92e7b08c7a67a7a783b52d83e7b051a4812e496fac181aaadcaa69a3b526ca500100000023220020357bc74e1f825c4628519a3322f2aa9b2c5bd55b523149d4e1f7fe2f273ce7d6feffffff02a08601000000000017a914113e1767186f0280174123ad0c22e8929f994c1c87f4fd01000000000017a9148160a47aeafb68288f0df8551d5d9dddd22a643387040047304402202575f8326e510b8213d70a8213ab1a36cd2984b16673ef3579960d0089ad13de022020ec4e78129c084103909acec0319f7d326fff699de142ab354be9570d68dc170147304402202bc22860e84e0311bbc175940c2b3b5435255dc7ca3fb0d12e5f03df80237b880220536eceee1aace094825f0fd884d057e395102f4e4627188fe6dd5648cdc7a457014752210274ecb4e28e6b7be314d844bb7561b605d537106f7f5c3eaba31a8cd3dd0097c8210343ed9c58350b4013b3c9a02da2148d59e8109a90f0fa0ea77d31b8570990d46352ae0400473044022042d6861f81b617cfbe51e7efefb59dd990d4c0057b43645d2f006db93b38c59e02204595b7f822546082b0ee1efb6966c97b2d8174c96b670a10bc9d78d3cf7ba99101483045022100bb3a612fe17f261a0c5e9db20a087362c10556571ef54866ab29cfdb94975236022037bebec4c0459bba21656cb36b331313c2dd6008ed7a2479efca659c7fc97c9d0147522103838edaeadeed0e9f660e725970787b69ad4926afe1f19626d5476d356cb3b4722103c37f3b264f674c6c2e273e06da7fb7fe720be6828f251c71d0cb10e349d0222d52ae2f3f0800

預期的“輸入地址”:

38Rgbmaxitveg1S8UNbWjwV5UMoBt3PtnG

3Bx1UMJieKFngvBA8m2VqE6s4wXYKWzhkP

謝謝你。

下面應用的**bitcoin-exlporer (bx) 工具**尚不支持分析原始十六進制交易 (TX) 的 segwit 編碼部分。但是,鑑於上面提供的原始 TX 以及與兩個輸入 UTXO 關聯的兩個相關 TX,下面的 bx 命令可以離線分析結果。

0ea77d31b8570990d46352ae0400473044022042d6861f81b617cfbe51e7efefb59dd990d4c0057b43645d2f006db93b38c59e02204595b7f822546082b0ee1efb6966c97b2d8174c96b670a10bc9d78d3cf7ba99101483045022100bb3a612fe17f261a0c5e9db20a087362c10556571ef54866ab29cfdb94975236022037bebec4c0459bba21656cb36b331313c2dd6008ed7a2479efca659c7fc97c9d0147522103838edaeadeed0e9f660e725970787b69ad4926afe1f19626d5476d356cb3b4722103c37f3b264f674c6c2e273e06da7fb7fe720be6828f251c71d0cb10e349d0222d52ae2f3f0800 | bx tx-解碼

{
   hash b0dd3d915a568c9d48e37b3fbfca58ae3276a5dba176fdf30f18af794310cc02
   inputs
   {
       input
       {
           address_hash 49e282ad0605c1cb63ff45fc34b14357859e8d08
           previous_output
           {
               hash f0fa97af6ba86096d9efcfea0bef4d6d146552bdf70e25b067dce1c1520d37b4
               index 0
           }
           script [00202dc520822e73d4262000d3b456b16df1d07b0ba9d238f3063379d65840fd38e7]
           sequence 4294967294
           witness "[] [304402202575f8326e510b8213d70a8213ab1a36cd2984b16673ef3579960d0089ad13de022020ec4e78129c084103909acec0319f7d326fff699de142ab354be9570d68dc1701] [304402202bc22860e84e0311bbc175940c2b3b5435255dc7ca3fb0d12e5f03df80237b880220536eceee1aace094825f0fd884d057e395102f4e4627188fe6dd5648cdc7a45701] [52210274ecb4e28e6b7be314d844bb7561b605d537106f7f5c3eaba31a8cd3dd0097c8210343ed9c58350b4013b3c9a02da2148d59e8109a90f0fa0ea77d31b8570990d46352ae]"
       }
       input
       {
           address_hash 70871ecb261f3df9a9d325b33ef6d8acb5074258
           previous_output
           {
               hash 50ca26b5a369aadcaa1a18ac6f492e81a451b0e7832db583a7a7677a8cb0e792
               index 1
           }
           script [0020357bc74e1f825c4628519a3322f2aa9b2c5bd55b523149d4e1f7fe2f273ce7d6]
           sequence 4294967294
           witness "[] [3044022042d6861f81b617cfbe51e7efefb59dd990d4c0057b43645d2f006db93b38c59e02204595b7f822546082b0ee1efb6966c97b2d8174c96b670a10bc9d78d3cf7ba99101] [3045022100bb3a612fe17f261a0c5e9db20a087362c10556571ef54866ab29cfdb94975236022037bebec4c0459bba21656cb36b331313c2dd6008ed7a2479efca659c7fc97c9d01] [522103838edaeadeed0e9f660e725970787b69ad4926afe1f19626d5476d356cb3b4722103c37f3b264f674c6c2e273e06da7fb7fe720be6828f251c71d0cb10e349d0222d52ae]"
       }
   }
   lock_time 540463
   outputs
   {
       output
       {
           address_hash 113e1767186f0280174123ad0c22e8929f994c1c
           script "hash160 [113e1767186f0280174123ad0c22e8929f994c1c] equal"
           value 100000
       }
       output
       {
           address_hash 8160a47aeafb68288f0df8551d5d9dddd22a6433
           script "hash160 [8160a47aeafb68288f0df8551d5d9dddd22a6433] equal"
           value 130548
       }
   }
   version 1
}

然後需要檢查與以下內容相關的保留腳本,以確定它們是 P2PKH 還是 P2SH 地址類型:

  1. 事務 ID f0fa97af6ba86096d9efcfea0bef4d6d146552bdf70e25b067dce1c1520d37b4 和索引 0

  2. 交易 ID 50ca26b5a369aadcaa1a18ac6f492e81a451b0e7832db583a7a7677a8cb0e792 和索引 1

% bx fetch-tx -c ~/bitcoin-explorer/bx-mainnet-remote.cfg f0fa97af6ba86096d9efcfea0bef4d6d146552bdf70e25b067dce1c1520d37b4

transaction
{
   hash f0fa97af6ba86096d9efcfea0bef4d6d146552bdf70e25b067dce1c1520d37b4
   inputs
   {
       input
       {
           address_hash 40ef0e3af404842b44912f6a65ca4adfb8f93a1a
           previous_output
           {
               hash f0eda490f5e8c3096b74b66524ff9c7b6fa1b9d4280e8372476af1d202a8b360
               index 1
           }
           script [0020de730ce4f827ac7c63ea8c9a47419875eacaf167f9391eb5d30817a181aca8d3]
           sequence 4294967294
       }
   }
   lock_time 539071
   outputs
   {
       output
       {
           address_hash 49e282ad0605c1cb63ff45fc34b14357859e8d08
           script "hash160 [49e282ad0605c1cb63ff45fc34b14357859e8d08] equal"
           value 18640
       }
       output
       {
           address_hash 113e1767186f0280174123ad0c22e8929f994c1c
           script "hash160 [113e1767186f0280174123ad0c22e8929f994c1c] equal"
           value 30000
       }
   }
   version 1
}

% bx fetch-tx -c ~/bitcoin-explorer/bx-mainnet-remote.cfg 50ca26b5a369aadcaa1a18ac6f492e81a451b0e7832db583a7a7677a8cb0e792

transaction
{
   hash 50ca26b5a369aadcaa1a18ac6f492e81a451b0e7832db583a7a7677a8cb0e792
   inputs
   {
       input
       {
           address_hash 62979379f3e415ef86d5dcecf9c93a9930333ce6
           previous_output
           {
               hash dbc6bff3ef644974667316072c6e28e5c58c18e62f8282ff624fde7d179639b2
               index 3
           }
           script [0020a9250a9c4e56b3d822717c37c713d30618f2af8f5932ded48fd6c8b3f0b5ff05]
           sequence 4294967295
       }
   }
   lock_time 0
   outputs
   {
       output
       {
           address_hash 877f4856923528187ab9708660fa201e4282ef8f
           script "dup hash160 [877f4856923528187ab9708660fa201e4282ef8f] equalverify checksig"
           value 10000
       }
       output
       {
           address_hash 70871ecb261f3df9a9d325b33ef6d8acb5074258
           script "hash160 [70871ecb261f3df9a9d325b33ef6d8acb5074258] equal"
           value 212250
       }
   }
   version 1
}

經檢查,兩種不同的產權負擔腳本均為 P2SH 形式:

  1. 腳本“hash160 [49e282ad0605c1cb63ff45fc34b14357859e8d08] 相等”

  2. 腳本“hash160 [70871ecb261f3df9a9d325b33ef6d8acb5074258] 相等”

兩個address_hash數據值的操作如下:

% 迴聲 49e282ad0605c1cb63ff45fc34b14357859e8d08 | bx base58check-encode -v 5 38Rgbmaxitveg1S8UNbWjwV5UMoBt3PtnG

% 迴聲 70871ecb261f3df9a9d325b33ef6d8acb5074258 | bx base58check-encode -v 5 3Bx1UMJieKFngvBA8m2VqE6s4wXYKWzhkP

如果特定地址是 P2PKH 形式,則將上述操作中的-v 5替換為。-v 0

順便說一句 - 根據對兩個 DER 編碼簽名的檢查並知道最後一個數據元素是腳本編碼的,看起來兩個贖回的 P2SH 輸入實際上都是 2 個多重簽名地址中的 2 個。

% 迴聲 52210274ecb4e28e6b7be314d844bb7561b605d537106f7f5c3eaba31a8cd3dd0097c8210343ed9c58350b4013b3c9a02da2148d59e8109a90f0fa0ead77d31b857090e | bx 腳本解碼

2 [0274ecb4e28e6b7be314d844bb7561b605d537106f7f5c3eaba31a8cd3dd0097c8] [0343ed9c58350b4013b3c9a02da2148d59e8109a90f0fa0ea77d31b8570990d463] 2 checkmultisig

% 迴聲 522103838edaeadeed0e9f660e725970787b69ad4926afe1f19626d5476d356cb3b4722103c37f3b264f674c6c2e273e06da7fb7fe720be6828f251c71d220cb10e34d|d bx 腳本解碼

2 [03838edaeadeed0e9f660e725970787b69ad4926afe1f19626d5476d356cb3b472] [03c37f3b264f674c6c2e273e06da7fb7fe720be6828f251c71d0cb10e349d0222d] 2 checkmultisig

比特幣資源管理器踢屁股!

引用自:https://bitcoin.stackexchange.com/questions/79024