比特币P2SH交易数据结构解析

1、解析原生交易
decoderawtransaction 01000000000101708256c5896fb3f00ef37601f8e30c5b460dbcd1fca1cd7199f9b56fc4ecd54000000000232200201aaa5a03ce8d33280eb958c98430c2a6177f3604a5fae374e9ed5c4703f152c3ffffffff0100c5dc030000000017a91462426ef7c71e744780d9d7540573e736105fad1c87040047304402204a5be4397ffa09c4de16a180d8fc8b0723edca6fc1ff28447fde7ced40941f0802207f3a34e899b6e5730338825aa3666077886c6a5d23a3363bbb07f1ee3828efd70147304402207410638a0b28f359d63e8a07cbc8a36d3e2d8cedd289d815151befa1daf1988d0220545d3add1545682f60a828d1aad5f52a3bd1e6849c1ab736d4e4781425b9a2e60169522102ee9f84122a4c96b0b50c6ece628430208f527c94b5abb79450f520bab7ef088c21038220abc643545ba7c6fde337e08247785222ba5bcf8d69cf7cdd077d9bbbd0262103889848ac7b663b20d98bd9fbb15b0c6bfa16d986ad9c7ea8eec406a25ef25a6253ae00000000

{
  "txid": "b615db2e38a415ad1436ddbdee847584256a0630f8ebfe64548ea31ebefa9c97",
  "hash": "9ee60d6baf34857adc1b3096abbef18ee48f37c4416d095e95987291c771f67d",
  "version": 1,
  "size": 372,
  "vsize": 182,
  "locktime": 0,
  "vin": [
    {
      "txid": "40d5ecc46fb5f99971cda1fcd1bc0d465b0ce3f80176f30ef0b36f89c5568270",
      "vout": 0,//为指定txid交易的0号输出
      "scriptSig": {
        "asm": "00201aaa5a03ce8d33280eb958c98430c2a6177f3604a5fae374e9ed5c4703f152c3",//解锁脚本
        "hex": "2200201aaa5a03ce8d33280eb958c98430c2a6177f3604a5fae374e9ed5c4703f152c3"
      },
      "txinwitness": [
        "",
        "304402204a5be4397ffa09c4de16a180d8fc8b0723edca6fc1ff28447fde7ced40941f0802207f3a34e899b6e5730338825aa3666077886c6a5d23a3363bbb07f1ee3828efd701",//sign0
        "304402207410638a0b28f359d63e8a07cbc8a36d3e2d8cedd289d815151befa1daf1988d0220545d3add1545682f60a828d1aad5f52a3bd1e6849c1ab736d4e4781425b9a2e601",//sign1
        "522102ee9f84122a4c96b0b50c6ece628430208f527c94b5abb79450f520bab7ef088c21038220abc643545ba7c6fde337e08247785222ba5bcf8d69cf7cdd077d9bbbd0262103889848ac7b663b20d98bd9fbb15b0c6bfa16d986ad9c7ea8eec406a25ef25a6253ae"//赎回脚本
      ],
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 0.64800000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_HASH160 62426ef7c71e744780d9d7540573e736105fad1c OP_EQUAL",//锁定脚本
        "hex": "a91462426ef7c71e744780d9d7540573e736105fad1c87",
        "reqSigs": 1,
        "type": "scripthash",
        "addresses": [
          "3AeZjDo9yvwweoK8atdsqxC5Pxg59j17JM"
        ]
      }
    }
  ]
}


2、解析p2sh的解锁脚本
decodescript 00201aaa5a03ce8d33280eb958c98430c2a6177f3604a5fae374e9ed5c4703f152c3

{
  "asm": "0 1aaa5a03ce8d33280eb958c98430c2a6177f3604a5fae374e9ed5c4703f152c3",
  "reqSigs": 1,
  "type": "witness_v0_scripthash",
  "addresses": [
    "bc1qr2495q7w35ejsr4etrycgvxz5cth7dsy5hawxa8fa4wywql32tps8whzel"
  ],
  "p2sh": "3Q99PXASzaXweaLWD4x3bFn49KK9kGoTgK"
}


3、赎回脚本
decodescript 522102ee9f84122a4c96b0b50c6ece628430208f527c94b5abb79450f520bab7ef088c21038220abc643545ba7c6fde337e08247785222ba5bcf8d69cf7cdd077d9bbbd0262103889848ac7b663b20d98bd9fbb15b0c6bfa16d986ad9c7ea8eec406a25ef25a6253ae

{
  "asm": "2 02ee9f84122a4c96b0b50c6ece628430208f527c94b5abb79450f520bab7ef088c 038220abc643545ba7c6fde337e08247785222ba5bcf8d69cf7cdd077d9bbbd026 03889848ac7b663b20d98bd9fbb15b0c6bfa16d986ad9c7ea8eec406a25ef25a62 3 OP_CHECKMULTISIG",
  "reqSigs": 2,
  "type": "multisig",
  "addresses": [
    "13HqBpC3FANBko4frrjyQhL3yzGYjz6Gyr",
    "1Kg1ZxNdMTLLKgvi3LXXayQhtLX1D5sgxU",
    "1DEbFEzHGF9mVT7xgQif8sKPfww228z2kf"
  ],
  "p2sh": "3H43VoteM46NQmKnT9FSzR731Jgu5fndaE"
}
该交易的utxo由三个地址拥有,如果想花掉这笔交易,需要提供两个地址的签名,才能解锁脚本。

你可能感兴趣的:(区块链和数字货币)