Ejemplo n.º 1
0
def test_output_scripts_serialization() -> None:
    input_1 = TxIn(
        OutPoint(
            "75ddabb27b8845f5247975c8a5ba7c6f336c4570708ebe230caf6db5217ae858",
            0),
        b"",
        0xFFFFFFFF,
    )
    output_1 = TxOut(
        149990000,
        bytes.fromhex("a914256b3a9ae8145e5094329537dd4d7a25dbc9452087"))
    output_2 = TxOut(
        100000000,
        bytes.fromhex("001400aea9a2e5f0f876a588df5546e8742d1d87008f"))
    tx = Tx(2, 0, [input_1], [output_1, output_2])

    psbt = Psbt.from_tx(tx)

    # p2sh-p2wsh
    psbt.outputs[0].redeem_script = bytes.fromhex(
        "003BD89EE628E6EB745F99DF1E4AEF64A0DAA814850DAA509F30C0F472E0563C7A")
    psbt.outputs[0].witness_script = bytes.fromhex(
        "522103dcea327ff7b2b4449413d9dc24cef0cc9e7864bad9d6291f3f1a04b639422c312103a2c5199b333adfaed4fea7ab65485b9e23a6cb317ddae7e8c1f2bd673414bdd352ae"
    )

    assert Psbt.b64decode(psbt.b64encode()) == psbt
Ejemplo n.º 2
0
def test_creation() -> None:
    psbt_str = "cHNidP8BAJoCAAAAAljoeiG1ba8MI76OcHBFbDNvfLqlyHV5JPVFiHuyq911AAAAAAD/////g40EJ9DsZQpoqka7CwmK6kQiwHGyyng1Kgd5WdB86h0BAAAAAP////8CcKrwCAAAAAAWABTYXCtx0AYLCcmIauuBXlCZHdoSTQDh9QUAAAAAFgAUAK6pouXw+HaliN9VRuh0LR2HAI8AAAAAAAAAAAA="
    psbt = Psbt.b64decode(psbt_str)
    assert psbt.b64encode() == psbt_str

    output_1 = TxOut(
        149990000,
        ScriptPubKey("0014d85c2b71d0060b09c9886aeb815e50991dda124d"))
    output_2 = TxOut(
        100000000,
        ScriptPubKey("001400aea9a2e5f0f876a588df5546e8742d1d87008f"))
    input_1 = TxIn(
        OutPoint(
            "75ddabb27b8845f5247975c8a5ba7c6f336c4570708ebe230caf6db5217ae858",
            0),
        b"",
        0xFFFFFFFF,
    )
    input_2 = TxIn(
        OutPoint(
            "1dea7cd05979072a3578cab271c02244ea8a090bbb46aa680a65ecd027048d83",
            1),
        b"",
        0xFFFFFFFF,
    )
    transaction = Tx(2, 0, [input_1, input_2], [output_1, output_2])
    psbt_from_tx_ = Psbt.from_tx(transaction)
    assert psbt_from_tx_ == psbt
Ejemplo n.º 3
0
def test_psbt() -> None:
    prev_out = OutPoint(
        "9dcfdb5836ecfe146bdaa896605ba21222f83cd014dd47adde14fab2aba7de9b", 1)
    script_sig = b""
    sequence = 0xFFFFFFFF
    tx_in = TxIn(prev_out, script_sig, sequence)

    tx_out1 = TxOut(2500000, "a914f987c321394968be164053d352fc49763b2be55c87")
    tx_out2 = TxOut(
        6381891,
        "0020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d")
    version = 1
    lock_time = 0
    tx = Tx(version, lock_time, [tx_in], [tx_out1, tx_out2])
    psbt = Psbt.from_tx(tx)
    assert psbt == Psbt.parse(psbt.serialize())
    assert psbt == Psbt.from_dict(psbt.to_dict())