Transactions

比特幣交易的結構,特別是與前一筆交易的連結

  • September 6, 2022

我正在閱讀 Alexander Lipton 和 Adrien Treccani 的“區塊鍊和分佈式賬本”。

我試圖了解單個交易是如何联系在一起的。

在第 338 頁,他們給出了“第 400,000 塊典型交易的詳細資訊”(抱歉,我無法複製和粘貼文本):

來自本書,第 338 頁

當我使用https://blockchain.info/tx/928c4275dfd6270349e76aa5a49b355eefeb9e31ffbe95dd75fed81d219a23f8?format=jsonthen 查看此交易時,這就是我所看到的:

{
 "hash": "928c4275dfd6270349e76aa5a49b355eefeb9e31ffbe95dd75fed81d219a23f8",
 "ver": 1,
 "vin_sz": 1,
 "vout_sz": 1,
 "size": 191,
 "weight": 764,
 "fee": 100000,
 "relayed_by": "0.0.0.0",
 "lock_time": 0,
 "tx_index": 8730617388972831,
 "double_spend": false,
 "time": 1456417484,
 "block_index": 400000,
 "block_height": 400000,
 "inputs": [
   {
     "sequence": 4294967295,
     "witness": "",
     "script": "473044022100a98648381f405a6882989faa500147c7cb9f4ce03e912d18529fb3609e243a47021f798214efe634e8c47e158edae534f5652b98ce1bd3693fa95dcdd2c699d987012102bd63ab2a6215bdd16d554ea3fd5d83843bff9c76e0b8c6c150d58ee6ca7ea525",
     "index": 0,
     "prev_out": {
       "tx_index": 2867663739202288,
       "value": 321000000,
       "n": 5,
       "type": 0,
       "spent": true,
       "script": "76a914c53c08858049dccc686358e05a0371211fc77c5b88ac",
       "spending_outpoints": [
         {
           "tx_index": 8730617388972831,
           "n": 0
         }
       ],
       "addr": "1Jyt2ydxc9uTzHuj8DR8egqbLEwLa6kQPL"
     }
   }
 ],
 "out": [
   {
     "type": 0,
     "spent": true,
     "value": 320900000,
     "spending_outpoints": [
       {
         "tx_index": 8460568020598031,
         "n": 0
       }
     ],
     "n": 0,
     "tx_index": 8730617388972831,
     "script": "76a9142f58e6245481be77894d5f0f0e2641decdafc44788ac",
     "addr": "15KMFpvaHJLf26y7DkTFKjxijfYvAAdU2s"
   }
 ]
}

這似乎有些不同。特別是,沒有’Prev。TXID’ 欄位。這本書提到的前一筆交易 (5180fff4155787703d10f03cca1566794516ac65a67764e571dc9c34931f321d) 似乎根本不存在。

我的問題是:有沒有辦法確定哪些交易與哪些交易相關聯?

這似乎有些不同。

區塊鏈瀏覽器沒有顯示確切的區塊結構。他們通常會添加他們認為有用的額外衍生資訊。我還發現這具有誤導性,而且通常無濟於事。

你可能會發現一個不同的區塊鏈瀏覽器更有幫助(或者至少在對你來說不那麼重要的方式上沒有幫助)。例如For developers Raw Tx參見https://blockchair.com/bitcoin/transaction/928c4275dfd6270349e76aa5a49b355eefeb9e31ffbe95dd75fed81d219a23f8

有沒有辦法找出哪些交易連結到哪些交易?

是的。事務的每個輸入將該事務連結到由每個輸入的數據中的先前事務 ID 欄位(在您的範例中為“Prev.TxId”)標識的較早事務。

因此,例如,您可以解析比特幣核心創建的 BLK 文件以列出交易之間的這些連結。

> blockchain -file blk02000.dat -block 1 -tx 572

Transaction Details in Hex (Decimal/Symbolic):
 Version:................01000000 (1)
 Inputs:.................04 (4)
 Input:1
   Previous Transaction:.3476B395124F8C339802EDEDBA2FDFE13D28AF4C28E67BABBFCCC27E18EF97C7
   Previous Output Index:0000 (0)
   Script Length:........6A (106)
   Unlocking Script:.....47304402205EE39EA72444ECB77D5448C6742CE17F4887AAFD30FE90E4E20147
                         823803E5AF022067D94E7AEE43C56221B403989D50BE40F1DB5A6073635E100F
                         96D8C2656798960121026B61AC29519038AECC2BB6E2F57FE9310B82D7E7873A
                         C5F4501B823C4D8E5B43
   Sequence:.............FFFFFFFF
 Input:2
   Previous Transaction:.DC9C065A1C610B13604C79925331F9762F08344E9330B11F9F5E938C3F46754B
   Previous Output Index:0000 (0)
   Script Length:........6B (107)
   Unlocking Script:.....483045022100CF78C34E882E39EC2F76FD47218195156030B2FDF93E1D854FD9
                         DA17FEB785AE02200ECBE9A6402F4C597970F3F9CDB8C3FC4A700C1D8B0CA29F
                         07C71A4EF00C372B01210363CFCE0BD0D8BF56AAE3388EF5928E4F2EEB032606
                         A9B17506948CDEB0A5D8A2
   Sequence:.............FFFFFFFF
 Input:3
   Previous Transaction:.EF59C004545977F125CD33905A6AD17A4F7C5E7E55B96B6740C8B850F1AC6705
   Previous Output Index:0000 (0)
   Script Length:........6B (107)
   Unlocking Script:.....483045022100F29055D9A3D8BB9DD5ADEDAE3E2BD071488790F11290866CC5B9
                         08B7738578A402204DBCED4D7787D8D174385BCB7563BC0E7B16016E70E7F1BD
                         C28702F75283AA6A012103F8F5D44539C2679C090034F369B52B1FD309A0520B
                         F6C91F5E0C7E78FE3C30D4
   Sequence:.............FFFFFFFF
 Input:4
   Previous Transaction:.F3BEA54D65FE5E89D77E34C7E1C57D3B00E1C8327AAB0E4B3DA026C9FA7B8A16
   Previous Output Index:0001 (1)
   Script Length:........6A (106)
   Unlocking Script:.....4730440220598BB94163092C90EE14FC96BAD695915254F2FA990BF33F646D58
                         47D0A8EB9A02205893ED21FD19BC912A4D9D14C8B32F85F1C54D246529E5C95D
                         BDB53B90F4F7440121022547351C3502D195472035ACFE58E5D000EAACCF3290
                         4F0BA4057720A81F9D14
   Sequence:.............FFFFFFFF
 Outputs:................01 (1)
 Output 1
   Value:................2434000000000000 (13348)
   Script Length:........17 (23)
   Locking Script:.......A9146B6674CCB5ACA499B2A8F4A27127AD9DB9D6DD1487
 LockTime:...............00000000 (0)

請注意,每筆交易都由交易 ID 標識,該交易 ID 是交易中選定數據的雜湊(它不包括 SegWit 數據以與非 Segwit 節點兼容)

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