hiro99ma blog

rust: rust-bitcoin と BDK (2)

2025/09/17

前回の続き。
Rust Bitcoin Cookbook は制作途中だそうだが、量が少ないのでちょうどよさそうだ。
中身は読んでもらえば良いので、気がついたところだけメモに残そう。

SegWit V0

$ cargo add bitcoin --features "std, rand-std"
    Updating crates.io index
      Adding bitcoin v0.32.7 to dependencies
             Features:
             + rand-std
             + secp-recovery
             + std
             - actual-serde
             - base64
             - bitcoinconsensus
             - bitcoinconsensus-std
             - ordered
             - rand
             - secp-lowmemory
             - serde
    Updating crates.io index
     Locking 29 packages to latest Rust 1.89.0 compatible versions

main()input_index は、previous outpoint というか vin というかの何番目に対して署名するかだろう。

p2wpkh_signature_hashDUMMY_UTXO_AMOUNT よりも dummy_utxo.value の方がよいのではないかな。

関数仕様は見ていないが、P2WPKH はこんな感じだよね、という順番に並んでいるだけだ。
いやあ、楽だねぇ。

     Running `target/debug/segwit_v0`
Transaction {
    version: Version(
        2,
    ),
    lock_time: 0 blocks,
    input: [
        TxIn {
            previous_output: OutPoint {
                txid: 0000000000000000000000000000000000000000000000000000000000000000,
                vout: 0,
            },
            script_sig: Script(),
            sequence: Sequence(0xfffffffd),
            witness: Witness: {
                indices: 2,
                indices_start: 107,
                witnesses: [
                    [0x30, 0x45, 0x02, ... , 0x2f, 0x01],
                    [0x03, 0x89, ... , 0x85, 0x0f],
                ],
            }
            ,
        },
    ],
    output: [
        TxOut {
            value: 5000000 SAT,
            script_pubkey: Script(OP_0 OP_PUSHBYTES_20 f60834ef165253c571b11ce9fa74e46692fc5ec1),
        },
        TxOut {
            value: 14999000 SAT,
            script_pubkey: Script(OP_0 OP_PUSHBYTES_20 014c3fecc18006bf2d53c8b26cdcd5e4cf39116e),
        },
    ],
}

output の value を変更したが、fee がゼロになっても output の合計が input を超えてもエラーにはならなかった。 そういうチェックはしないようだ。

writer: hiro99ma

 < Top page

コメント(Google Formへ飛びます)

GitHub

X/Twitter

Homepage

About me