def test_bitcoin_fund_solver():

    fund_solver = FundSolver(private_key=sender_wallet.private_key())

    assert sender_wallet.private_key() == fund_solver.private_key.hexlify()

    assert isinstance(fund_solver.solve(), P2pkhSolver)

    with pytest.raises(TypeError, match="private key must be string format"):
        FundSolver(float())
Example #2
0
def test_bitcoin_fund_solver():

    fund_solver = FundSolver(
        xprivate_key=_["bitcoin"]["wallet"]["sender"]["root_xprivate_key"],
        path=_["bitcoin"]["wallet"]["sender"]["derivation"]["path"],
        account=_["bitcoin"]["wallet"]["sender"]["derivation"]["account"],
        change=_["bitcoin"]["wallet"]["sender"]["derivation"]["change"],
        address=_["bitcoin"]["wallet"]["sender"]["derivation"]["address"])

    assert isinstance(fund_solver.solve(network=_["bitcoin"]["network"]),
                      P2pkhSolver)
Example #3
0
def test_bitcoin_fund_signature():

    unsigned_fund_transaction_raw = _["bitcoin"]["fund"]["unsigned"][
        "transaction_raw"]

    fund_solver = FundSolver(
        xprivate_key=_["bitcoin"]["wallet"]["sender"]["root_xprivate_key"],
        path=_["bitcoin"]["wallet"]["sender"]["derivation"]["path"],
        account=_["bitcoin"]["wallet"]["sender"]["derivation"]["account"],
        change=_["bitcoin"]["wallet"]["sender"]["derivation"]["change"],
        address=_["bitcoin"]["wallet"]["sender"]["derivation"]["address"])

    signature = Signature(network=_["bitcoin"]["network"]).sign(
        transaction_raw=unsigned_fund_transaction_raw, solver=fund_solver)

    assert signature.type() == _["bitcoin"]["fund"]["signed"]["type"]
    assert signature.fee() == _["bitcoin"]["fund"]["signed"]["fee"]
    assert signature.hash() == _["bitcoin"]["fund"]["signed"]["hash"]
    assert signature.raw() == _["bitcoin"]["fund"]["signed"]["raw"]
    assert signature.json() == _["bitcoin"]["fund"]["signed"]["json"]
    assert signature.transaction_raw() == clean_transaction_raw(
        transaction_raw=_["bitcoin"]["fund"]["signed"]["transaction_raw"])

    fund_signature = FundSignature(network=_["bitcoin"]["network"]).sign(
        transaction_raw=unsigned_fund_transaction_raw, solver=fund_solver)

    assert fund_signature.type() == _["bitcoin"]["fund"]["signed"]["type"]
    assert fund_signature.fee() == _["bitcoin"]["fund"]["signed"]["fee"]
    assert fund_signature.hash() == _["bitcoin"]["fund"]["signed"]["hash"]
    assert fund_signature.raw() == _["bitcoin"]["fund"]["signed"]["raw"]
    assert fund_signature.json() == _["bitcoin"]["fund"]["signed"]["json"]
    assert fund_signature.transaction_raw() == clean_transaction_raw(
        transaction_raw=_["bitcoin"]["fund"]["signed"]["transaction_raw"])
Example #4
0
def test_bitcoin_fund_transaction():

    htlc = HTLC(network=_["bitcoin"]["network"]).build_htlc(
        secret_hash=_["bitcoin"]["htlc"]["secret"]["hash"],
        recipient_address=_["bitcoin"]["wallet"]["recipient"]["address"],
        sender_address=_["bitcoin"]["wallet"]["sender"]["address"],
        endtime=_["bitcoin"]["htlc"]["endtime"])

    unsigned_fund_transaction = FundTransaction(
        network=_["bitcoin"]["network"])

    unsigned_fund_transaction.build_transaction(
        address=_["bitcoin"]["wallet"]["sender"]["address"],
        htlc=htlc,
        amount=_["bitcoin"]["amount"],
        unit=_["bitcoin"]["unit"])

    assert unsigned_fund_transaction.type(
    ) == _["bitcoin"]["fund"]["unsigned"]["type"]
    assert unsigned_fund_transaction.fee(
    ) == _["bitcoin"]["fund"]["unsigned"]["fee"]
    assert unsigned_fund_transaction.hash(
    ) == _["bitcoin"]["fund"]["unsigned"]["hash"]
    assert unsigned_fund_transaction.raw(
    ) == _["bitcoin"]["fund"]["unsigned"]["raw"]
    assert unsigned_fund_transaction.json(
    ) == _["bitcoin"]["fund"]["unsigned"]["json"]
    assert unsigned_fund_transaction.transaction_raw(
    ) == clean_transaction_raw(
        transaction_raw=_["bitcoin"]["fund"]["unsigned"]["transaction_raw"])

    signed_fund_transaction = unsigned_fund_transaction.sign(solver=FundSolver(
        xprivate_key=_["bitcoin"]["wallet"]["sender"]["root_xprivate_key"],
        path=_["bitcoin"]["wallet"]["sender"]["derivation"]["path"],
        account=_["bitcoin"]["wallet"]["sender"]["derivation"]["account"],
        change=_["bitcoin"]["wallet"]["sender"]["derivation"]["change"],
        address=_["bitcoin"]["wallet"]["sender"]["derivation"]["address"]))

    assert signed_fund_transaction.type(
    ) == _["bitcoin"]["fund"]["signed"]["type"]
    assert signed_fund_transaction.fee(
    ) == _["bitcoin"]["fund"]["signed"]["fee"]
    assert signed_fund_transaction.hash(
    ) == _["bitcoin"]["fund"]["signed"]["hash"]
    assert signed_fund_transaction.raw(
    ) == _["bitcoin"]["fund"]["signed"]["raw"]
    assert signed_fund_transaction.json(
    ) == _["bitcoin"]["fund"]["signed"]["json"]
    assert signed_fund_transaction.transaction_raw() == clean_transaction_raw(
        transaction_raw=_["bitcoin"]["fund"]["signed"]["transaction_raw"])
Example #5
0
def test_bitcoin_fund_transaction():

    unsigned_fund_transaction = FundTransaction(network=_["bitcoin"]["network"])

    unsigned_fund_transaction.build_transaction(
        address=_["bitcoin"]["wallet"]["sender"]["address"],
        htlc_address=_["bitcoin"]["htlc"]["address"],
        amount=(
            _["bitcoin"]["amount"] if _["bitcoin"]["unit"] == "SATOSHI" else amount_unit_converter(
                _["bitcoin"]["amount"], f"{_['bitcoin']['unit']}2SATOSHI")
        )
    )

    assert unsigned_fund_transaction.type() == _["bitcoin"]["fund"]["unsigned"]["type"]
    assert unsigned_fund_transaction.fee() == _["bitcoin"]["fund"]["unsigned"]["fee"]
    assert unsigned_fund_transaction.hash() == _["bitcoin"]["fund"]["unsigned"]["hash"]
    assert unsigned_fund_transaction.raw() == _["bitcoin"]["fund"]["unsigned"]["raw"]
    assert unsigned_fund_transaction.json() == _["bitcoin"]["fund"]["unsigned"]["json"]
    assert unsigned_fund_transaction.transaction_raw() == clean_transaction_raw(
        transaction_raw=_["bitcoin"]["fund"]["unsigned"]["transaction_raw"]
    )

    signed_fund_transaction = unsigned_fund_transaction.sign(
        solver=FundSolver(
            root_xprivate_key=_["bitcoin"]["wallet"]["sender"]["root_xprivate_key"],
            path=_["bitcoin"]["wallet"]["sender"]["derivation"]["path"],
            account=_["bitcoin"]["wallet"]["sender"]["derivation"]["account"],
            change=_["bitcoin"]["wallet"]["sender"]["derivation"]["change"],
            address=_["bitcoin"]["wallet"]["sender"]["derivation"]["address"]
        )
    )

    assert signed_fund_transaction.type() == _["bitcoin"]["fund"]["signed"]["type"]
    assert signed_fund_transaction.fee() == _["bitcoin"]["fund"]["signed"]["fee"]
    assert signed_fund_transaction.hash() == _["bitcoin"]["fund"]["signed"]["hash"]
    assert signed_fund_transaction.raw() == _["bitcoin"]["fund"]["signed"]["raw"]
    assert signed_fund_transaction.json() == _["bitcoin"]["fund"]["signed"]["json"]
    assert signed_fund_transaction.transaction_raw() == clean_transaction_raw(
        transaction_raw=_["bitcoin"]["fund"]["signed"]["transaction_raw"]
    )
def test_signature_exceptions():

    with pytest.raises(
            ValueError,
            match=
            "invalid network, please choose only mainnet or testnet networks"):
        Signature(network="solonet")

    with pytest.raises(ValueError,
                       match="transaction script is none, sign first"):
        Signature().hash()

    with pytest.raises(ValueError,
                       match="transaction script is none, sign first"):
        Signature().json()

    with pytest.raises(
            ValueError,
            match="transaction script is none, build transaction first"):
        Signature().raw()

    with pytest.raises(ValueError, match="not found type, sign first"):
        Signature().type()

    with pytest.raises(ValueError,
                       match="there is no signed data, sign first"):
        Signature().signed_raw()

    with pytest.raises(
            TypeError,
            match=r"invalid Bitcoin fund unsigned transaction type, .*"):
        FundSignature().sign(
            unsigned_raw=
            "eyJmZWUiOiA1NzYsICJyYXciOiAiMDIwMDAwMDAwMWVjMzEyZTkyZDgzODdiMTVmNjIzOGQ0OTE4MzQ0YjYyYWIxNDdkN2YzODQ0ZGM4MWU2NTM3NzZmZThiODRlZjMwMDAwMDAwMDAwZmZmZmZmZmYwMWQwMjQwMDAwMDAwMDAwMDAxOTc2YTkxNDY0YTgzOTBiMGIxNjg1ZmNiZjJkNGI0NTcxMThkYzhkYTkyZDU1MzQ4OGFjMDAwMDAwMDAiLCAib3V0cHV0cyI6IHsidmFsdWUiOiAxMDAwMCwgIm4iOiAwLCAic2NyaXB0X3B1YmtleSI6ICJhOTE0MmJiMDEzYzNlNGJlYjA4NDIxZGVkY2Y4MTVjYjY1YTVjMzg4MTc4Yjg3In0sICJuZXR3b3JrIjogInRlc3RuZXQiLCAidHlwZSI6ICJiaXRjb2luX3JlZnVuZF91bnNpZ25lZCJ9",
            solver=FundSolver(private_key=sender_wallet.private_key()))

    with pytest.raises(
            TypeError,
            match=r"invalid Bitcoin claim unsigned transaction type, .*"):
        ClaimSignature().sign(
            unsigned_raw=
            "eyJmZWUiOiA2NzgsICJyYXciOiAiMDIwMDAwMDAwMWVjMzEyZTkyZDgzODdiMTVmNjIzOGQ0OTE4MzQ0YjYyYWIxNDdkN2YzODQ0ZGM4MWU2NTM3NzZmZThiODRlZjMwMTAwMDAwMDAwZmZmZmZmZmYwMjEwMjcwMDAwMDAwMDAwMDAxN2E5MTQyYmIwMTNjM2U0YmViMDg0MjFkZWRjZjgxNWNiNjVhNWMzODgxNzhiODc1MDhhMGUwMDAwMDAwMDAwMTk3NmE5MTQ2NGE4MzkwYjBiMTY4NWZjYmYyZDRiNDU3MTE4ZGM4ZGE5MmQ1NTM0ODhhYzAwMDAwMDAwIiwgIm91dHB1dHMiOiBbeyJhbW91bnQiOiA5NjM1OTAsICJuIjogMSwgInNjcmlwdCI6ICI3NmE5MTQ2NGE4MzkwYjBiMTY4NWZjYmYyZDRiNDU3MTE4ZGM4ZGE5MmQ1NTM0ODhhYyJ9XSwgIm5ldHdvcmsiOiAidGVzdG5ldCIsICJ0eXBlIjogImJpdGNvaW5fZnVuZF91bnNpZ25lZCJ9",
            solver=ClaimSolver(private_key=recipient_wallet.private_key(),
                               secret="Hello Meheret!",
                               secret_hash=sha256("Hello Meheret!"),
                               recipient_address=recipient_wallet.address(),
                               sender_address=sender_wallet.address(),
                               sequence=1000))

    with pytest.raises(
            TypeError,
            match=r"invalid Bitcoin refund unsigned transaction type, .*"):
        RefundSignature().sign(
            unsigned_raw=
            "eyJmZWUiOiA1NzYsICJyYXciOiAiMDIwMDAwMDAwMWVjMzEyZTkyZDgzODdiMTVmNjIzOGQ0OTE4MzQ0YjYyYWIxNDdkN2YzODQ0ZGM4MWU2NTM3NzZmZThiODRlZjMwMDAwMDAwMDAwZmZmZmZmZmYwMWQwMjQwMDAwMDAwMDAwMDAxOTc2YTkxNDk4Zjg3OWZiN2Y4YjQ5NTFkZWU5YmM4YTAzMjdiNzkyZmJlMzMyYjg4OGFjMDAwMDAwMDAiLCAib3V0cHV0cyI6IHsiYW1vdW50IjogMTAwMDAsICJuIjogMCwgInNjcmlwdCI6ICJhOTE0MmJiMDEzYzNlNGJlYjA4NDIxZGVkY2Y4MTVjYjY1YTVjMzg4MTc4Yjg3In0sICJuZXR3b3JrIjogInRlc3RuZXQiLCAidHlwZSI6ICJiaXRjb2luX2NsYWltX3Vuc2lnbmVkIn0",
            solver=RefundSolver(private_key=sender_wallet.private_key(),
                                secret_hash=sha256("Hello Meheret!"),
                                recipient_address=recipient_wallet.address(),
                                sender_address=sender_wallet.address(),
                                sequence=1000))

    with pytest.raises(ValueError,
                       match="invalid Bitcoin unsigned transaction raw"):
        Signature().sign("eyJtIjogImFzZCJ9", "")

    with pytest.raises(ValueError,
                       match="invalid Bitcoin unsigned fund transaction raw"):
        FundSignature().sign("eyJtIjogImFzZCJ9", "")

    with pytest.raises(ValueError,
                       match="invalid Bitcoin unsigned claim transaction raw"):
        ClaimSignature().sign("eyJtIjogImFzZCJ9", "")

    with pytest.raises(
            ValueError,
            match="invalid Bitcoin unsigned refund transaction raw"):
        RefundSignature().sign("eyJtIjogImFzZCJ9", "")

    with pytest.raises(
            TypeError,
            match=
            "invalid Bitcoin solver, it's only takes Bitcoin FundSolver class"
    ):
        FundSignature().sign(
            unsigned_raw=
            "eyJmZWUiOiA2NzgsICJyYXciOiAiMDIwMDAwMDAwMWVjMzEyZTkyZDgzODdiMTVmNjIzOGQ0OTE4MzQ0YjYyYWIxNDdkN2YzODQ0ZGM4MWU2NTM3NzZmZThiODRlZjMwMTAwMDAwMDAwZmZmZmZmZmYwMjEwMjcwMDAwMDAwMDAwMDAxN2E5MTQyYmIwMTNjM2U0YmViMDg0MjFkZWRjZjgxNWNiNjVhNWMzODgxNzhiODc1MDhhMGUwMDAwMDAwMDAwMTk3NmE5MTQ2NGE4MzkwYjBiMTY4NWZjYmYyZDRiNDU3MTE4ZGM4ZGE5MmQ1NTM0ODhhYzAwMDAwMDAwIiwgIm91dHB1dHMiOiBbeyJhbW91bnQiOiA5NjM1OTAsICJuIjogMSwgInNjcmlwdCI6ICI3NmE5MTQ2NGE4MzkwYjBiMTY4NWZjYmYyZDRiNDU3MTE4ZGM4ZGE5MmQ1NTM0ODhhYyJ9XSwgIm5ldHdvcmsiOiAidGVzdG5ldCIsICJ0eXBlIjogImJpdGNvaW5fZnVuZF91bnNpZ25lZCJ9",
            solver=RefundSolver(private_key=sender_wallet.private_key(),
                                secret_hash=sha256("Hello Meheret!"),
                                recipient_address=recipient_wallet.address(),
                                sender_address=sender_wallet.address(),
                                sequence=1000))

    with pytest.raises(
            TypeError,
            match=
            "invalid Bitcoin solver, it's only takes Bitcoin ClaimSolver class"
    ):
        ClaimSignature().sign(
            unsigned_raw=
            "eyJmZWUiOiA1NzYsICJyYXciOiAiMDIwMDAwMDAwMWVjMzEyZTkyZDgzODdiMTVmNjIzOGQ0OTE4MzQ0YjYyYWIxNDdkN2YzODQ0ZGM4MWU2NTM3NzZmZThiODRlZjMwMDAwMDAwMDAwZmZmZmZmZmYwMWQwMjQwMDAwMDAwMDAwMDAxOTc2YTkxNDk4Zjg3OWZiN2Y4YjQ5NTFkZWU5YmM4YTAzMjdiNzkyZmJlMzMyYjg4OGFjMDAwMDAwMDAiLCAib3V0cHV0cyI6IHsiYW1vdW50IjogMTAwMDAsICJuIjogMCwgInNjcmlwdCI6ICJhOTE0MmJiMDEzYzNlNGJlYjA4NDIxZGVkY2Y4MTVjYjY1YTVjMzg4MTc4Yjg3In0sICJuZXR3b3JrIjogInRlc3RuZXQiLCAidHlwZSI6ICJiaXRjb2luX2NsYWltX3Vuc2lnbmVkIn0",
            solver=FundSolver(private_key=sender_wallet.private_key()))

    with pytest.raises(
            TypeError,
            match=
            "invalid Bitcoin solver, it's only takes Bitcoin RefundSolver class"
    ):
        RefundSignature().sign(
            unsigned_raw=
            "eyJmZWUiOiA1NzYsICJyYXciOiAiMDIwMDAwMDAwMWVjMzEyZTkyZDgzODdiMTVmNjIzOGQ0OTE4MzQ0YjYyYWIxNDdkN2YzODQ0ZGM4MWU2NTM3NzZmZThiODRlZjMwMDAwMDAwMDAwZmZmZmZmZmYwMWQwMjQwMDAwMDAwMDAwMDAxOTc2YTkxNDY0YTgzOTBiMGIxNjg1ZmNiZjJkNGI0NTcxMThkYzhkYTkyZDU1MzQ4OGFjMDAwMDAwMDAiLCAib3V0cHV0cyI6IHsidmFsdWUiOiAxMDAwMCwgIm4iOiAwLCAic2NyaXB0X3B1YmtleSI6ICJhOTE0MmJiMDEzYzNlNGJlYjA4NDIxZGVkY2Y4MTVjYjY1YTVjMzg4MTc4Yjg3In0sICJuZXR3b3JrIjogInRlc3RuZXQiLCAidHlwZSI6ICJiaXRjb2luX3JlZnVuZF91bnNpZ25lZCJ9",
            solver=ClaimSolver(private_key=recipient_wallet.private_key(),
                               secret="Hello Meheret!",
                               secret_hash=sha256("Hello Meheret!"),
                               recipient_address=recipient_wallet.address(),
                               sender_address=sender_wallet.address(),
                               sequence=1000))
def test_bitcoin_fund_signature():

    unsigned_fund_transaction_raw = "eyJmZWUiOiA2NzgsICJyYXciOiAiMDIwMDAwMDAwMWVjMzEyZTkyZDgzODdiMTVmNjIzOGQ0OTE4MzQ0YjYyYWIxNDdkN2YzODQ0ZGM4MWU2NTM3NzZmZThiODRlZjMwMTAwMDAwMDAwZmZmZmZmZmYwMjEwMjcwMDAwMDAwMDAwMDAxN2E5MTQyYmIwMTNjM2U0YmViMDg0MjFkZWRjZjgxNWNiNjVhNWMzODgxNzhiODc1MDhhMGUwMDAwMDAwMDAwMTk3NmE5MTQ2NGE4MzkwYjBiMTY4NWZjYmYyZDRiNDU3MTE4ZGM4ZGE5MmQ1NTM0ODhhYzAwMDAwMDAwIiwgIm91dHB1dHMiOiBbeyJhbW91bnQiOiA5NjM1OTAsICJuIjogMSwgInNjcmlwdCI6ICI3NmE5MTQ2NGE4MzkwYjBiMTY4NWZjYmYyZDRiNDU3MTE4ZGM4ZGE5MmQ1NTM0ODhhYyJ9XSwgIm5ldHdvcmsiOiAidGVzdG5ldCIsICJ0eXBlIjogImJpdGNvaW5fZnVuZF91bnNpZ25lZCJ9"

    signature = Signature(version=2, network=network).sign(
        unsigned_raw=unsigned_fund_transaction_raw,
        solver=FundSolver(private_key=sender_wallet.private_key()))

    fund_signature = FundSignature(version=2, network=network).sign(
        unsigned_raw=unsigned_fund_transaction_raw,
        solver=FundSolver(private_key=sender_wallet.private_key()))

    assert signature.fee() == fund_signature.fee() == 678
    assert signature.hash() == fund_signature.hash(
    ) == "7e52333d38b7571807caac7971c925dd2c007dbf34a6c46138ff3d0213281d60"
    assert signature.raw() == fund_signature.raw(
    ) == "0200000001ec312e92d8387b15f6238d4918344b62ab147d7f3844dc81e653776fe8b84ef3010000006b483045022100b4d4de4c10bec380a9f07019d5232a9af9f0c2321e5efcf33f5326a60378144502203e1ab2ddaac8afade132832e715f055f956d3e730b9d035a4e99ec9dfdc7acfd012103c56a6005d4a8892d28cc3f7265e5685b548627d59108973e474c4e26f69a4c84ffffffff02102700000000000017a9142bb013c3e4beb08421dedcf815cb65a5c388178b87508a0e00000000001976a91464a8390b0b1685fcbf2d4b457118dc8da92d553488ac00000000"
    assert signature.json() == fund_signature.json() == {
        'hex':
        '0200000001ec312e92d8387b15f6238d4918344b62ab147d7f3844dc81e653776fe8b84ef3010000006b483045022100b4d4de4c10bec380a9f07019d5232a9af9f0c2321e5efcf33f5326a60378144502203e1ab2ddaac8afade132832e715f055f956d3e730b9d035a4e99ec9dfdc7acfd012103c56a6005d4a8892d28cc3f7265e5685b548627d59108973e474c4e26f69a4c84ffffffff02102700000000000017a9142bb013c3e4beb08421dedcf815cb65a5c388178b87508a0e00000000001976a91464a8390b0b1685fcbf2d4b457118dc8da92d553488ac00000000',
        'txid':
        '7e52333d38b7571807caac7971c925dd2c007dbf34a6c46138ff3d0213281d60',
        'hash':
        '7e52333d38b7571807caac7971c925dd2c007dbf34a6c46138ff3d0213281d60',
        'size':
        224,
        'vsize':
        224,
        'version':
        2,
        'locktime':
        0,
        'vin': [{
            'txid':
            'f34eb8e86f7753e681dc44387f7d14ab624b3418498d23f6157b38d8922e31ec',
            'vout': 1,
            'scriptSig': {
                'asm':
                '3045022100b4d4de4c10bec380a9f07019d5232a9af9f0c2321e5efcf33f5326a60378144502203e1ab2ddaac8afade132832e715f055f956d3e730b9d035a4e99ec9dfdc7acfd01 03c56a6005d4a8892d28cc3f7265e5685b548627d59108973e474c4e26f69a4c84',
                'hex':
                '483045022100b4d4de4c10bec380a9f07019d5232a9af9f0c2321e5efcf33f5326a60378144502203e1ab2ddaac8afade132832e715f055f956d3e730b9d035a4e99ec9dfdc7acfd012103c56a6005d4a8892d28cc3f7265e5685b548627d59108973e474c4e26f69a4c84'
            },
            'sequence': '4294967295'
        }],
        'vout': [{
            'value': '0.00010000',
            'n': 0,
            'scriptPubKey': {
                'asm':
                'OP_HASH160 2bb013c3e4beb08421dedcf815cb65a5c388178b OP_EQUAL',
                'hex': 'a9142bb013c3e4beb08421dedcf815cb65a5c388178b87',
                'type': 'p2sh',
                'address': '2MwEDybGC34949zgzWX4M9FHmE3crDSUydP'
            }
        }, {
            'value': '0.00952912',
            'n': 1,
            'scriptPubKey': {
                'asm':
                'OP_DUP OP_HASH160 64a8390b0b1685fcbf2d4b457118dc8da92d5534 OP_EQUALVERIFY OP_CHECKSIG',
                'hex': '76a91464a8390b0b1685fcbf2d4b457118dc8da92d553488ac',
                'type': 'p2pkh',
                'address': 'mphBPZf15cRFcL5tUq6mCbE84XobZ1vg7Q'
            }
        }]
    }
    assert signature.type() == fund_signature.type() == "bitcoin_fund_signed"
    assert signature.signed_raw() == fund_signature.signed_raw(
    ) == "eyJyYXciOiAiMDIwMDAwMDAwMWVjMzEyZTkyZDgzODdiMTVmNjIzOGQ0OTE4MzQ0YjYyYWIxNDdkN2YzODQ0ZGM4MWU2NTM3NzZmZThiODRlZjMwMTAwMDAwMDZiNDgzMDQ1MDIyMTAwYjRkNGRlNGMxMGJlYzM4MGE5ZjA3MDE5ZDUyMzJhOWFmOWYwYzIzMjFlNWVmY2YzM2Y1MzI2YTYwMzc4MTQ0NTAyMjAzZTFhYjJkZGFhYzhhZmFkZTEzMjgzMmU3MTVmMDU1Zjk1NmQzZTczMGI5ZDAzNWE0ZTk5ZWM5ZGZkYzdhY2ZkMDEyMTAzYzU2YTYwMDVkNGE4ODkyZDI4Y2MzZjcyNjVlNTY4NWI1NDg2MjdkNTkxMDg5NzNlNDc0YzRlMjZmNjlhNGM4NGZmZmZmZmZmMDIxMDI3MDAwMDAwMDAwMDAwMTdhOTE0MmJiMDEzYzNlNGJlYjA4NDIxZGVkY2Y4MTVjYjY1YTVjMzg4MTc4Yjg3NTA4YTBlMDAwMDAwMDAwMDE5NzZhOTE0NjRhODM5MGIwYjE2ODVmY2JmMmQ0YjQ1NzExOGRjOGRhOTJkNTUzNDg4YWMwMDAwMDAwMCIsICJmZWUiOiA2NzgsICJuZXR3b3JrIjogInRlc3RuZXQiLCAidHlwZSI6ICJiaXRjb2luX2Z1bmRfc2lnbmVkIn0="
Example #8
0
print("Unsigned Fund Transaction Fee:",
      unsigned_fund_transaction.fee(unit="SATOSHI"), "SATOSHI")
print("Unsigned Fund Transaction Hash:", unsigned_fund_transaction.hash())
print("Unsigned Fund Transaction Main Raw:", unsigned_fund_transaction.raw())
# print("Unsigned Fund Transaction Json:", json.dumps(unsigned_fund_transaction.json(), indent=4))
print("Unsigned Fund Transaction Type:", unsigned_fund_transaction.type())

unsigned_fund_transaction_raw: str = unsigned_fund_transaction.transaction_raw(
)
print("Unsigned Fund Transaction Raw:", unsigned_fund_transaction_raw)

print("=" * 10, "Signed Fund Transaction")

# Initialize fund solver
fund_solver: FundSolver = FundSolver(
    root_xprivate_key=sender_wallet.root_xprivate_key())

# Sing unsigned fund transaction
signed_fund_transaction: FundTransaction = unsigned_fund_transaction.sign(
    solver=fund_solver)

print("Signed Fund Transaction Fee:",
      signed_fund_transaction.fee(unit="SATOSHI"), "SATOSHI")
print("Signed Fund Transaction Hash:", signed_fund_transaction.hash())
print("Signed Fund Transaction Main Raw:", signed_fund_transaction.raw())
# print("Signed Fund Transaction Json:", json.dumps(signed_fund_transaction.json(), indent=4))
print("Signed Fund Transaction Type:", signed_fund_transaction.type())

signed_fund_transaction_raw = signed_fund_transaction.transaction_raw()
print("Signed Fund Transaction Raw:", signed_fund_transaction_raw)
Example #9
0
)

print("Unsigned Fund Transaction Fee:", unsigned_fund_transaction.fee())
print("Unsigned Fund Transaction Hash:", unsigned_fund_transaction.hash())
print("Unsigned Fund Transaction Raw:", unsigned_fund_transaction.raw())
# print("Unsigned Fund Transaction Json:", json.dumps(unsigned_fund_transaction.json(), indent=4))
print("Unsigned Fund Transaction Type:", unsigned_fund_transaction.type())

unsigned_fund_raw = unsigned_fund_transaction.unsigned_raw()
print("Unsigned Fund Transaction Unsigned Raw:", unsigned_fund_raw)

print("=" * 10, "Signed Fund Transaction")

# Initializing fund solver
fund_solver = FundSolver(
    private_key=sender_private_key
)

# Singing unsigned fund transaction
signed_fund_transaction = unsigned_fund_transaction.sign(solver=fund_solver)

print("Signed Fund Transaction Fee:", signed_fund_transaction.fee())
print("Signed Fund Transaction Hash:", signed_fund_transaction.hash())
print("Signed Fund Transaction Raw:", signed_fund_transaction.raw())
# print("Signed Fund Transaction Json:", json.dumps(signed_fund_transaction.json(), indent=4))
print("Signed Fund Transaction Type:", signed_fund_transaction.type())

print("=" * 10, "Fund Signature")

# Initializing fund signature
fund_signature = FundSignature(network=NETWORK)
def test_bitcoin_fund_transaction():

    unsigned_fund_transaction = FundTransaction(version=2, network=network)

    unsigned_fund_transaction.build_transaction(
        wallet=sender_wallet,
        htlc=HTLC(network=network).init(
            secret_hash=sha256("Hello Meheret!"),
            recipient_address=recipient_wallet.address(),
            sender_address=sender_wallet.address(),
            sequence=1000),
        amount=10_000)

    assert unsigned_fund_transaction.fee() == 678
    assert unsigned_fund_transaction.hash(
    ) == "f05f2afb0706020cc15b66d63e2fd9d89cfe5ce7a9f458f3a8a6fb3c1849cf20"
    assert unsigned_fund_transaction.raw(
    ) == "0200000001ec312e92d8387b15f6238d4918344b62ab147d7f3844dc81e653776fe8b84ef30100000000ffffffff02102700000000000017a9142bb013c3e4beb08421dedcf815cb65a5c388178b87508a0e00000000001976a91464a8390b0b1685fcbf2d4b457118dc8da92d553488ac00000000"
    assert unsigned_fund_transaction.json() == {
        'hex':
        '0200000001ec312e92d8387b15f6238d4918344b62ab147d7f3844dc81e653776fe8b84ef30100000000ffffffff02102700000000000017a9142bb013c3e4beb08421dedcf815cb65a5c388178b87508a0e00000000001976a91464a8390b0b1685fcbf2d4b457118dc8da92d553488ac00000000',
        'txid':
        'f05f2afb0706020cc15b66d63e2fd9d89cfe5ce7a9f458f3a8a6fb3c1849cf20',
        'hash':
        'f05f2afb0706020cc15b66d63e2fd9d89cfe5ce7a9f458f3a8a6fb3c1849cf20',
        'size':
        117,
        'vsize':
        117,
        'version':
        2,
        'locktime':
        0,
        'vin': [{
            'txid':
            'f34eb8e86f7753e681dc44387f7d14ab624b3418498d23f6157b38d8922e31ec',
            'vout': 1,
            'scriptSig': {
                'asm': '',
                'hex': ''
            },
            'sequence': '4294967295'
        }],
        'vout': [{
            'value': '0.00010000',
            'n': 0,
            'scriptPubKey': {
                'asm':
                'OP_HASH160 2bb013c3e4beb08421dedcf815cb65a5c388178b OP_EQUAL',
                'hex': 'a9142bb013c3e4beb08421dedcf815cb65a5c388178b87',
                'type': 'p2sh',
                'address': '2MwEDybGC34949zgzWX4M9FHmE3crDSUydP'
            }
        }, {
            'value': '0.00952912',
            'n': 1,
            'scriptPubKey': {
                'asm':
                'OP_DUP OP_HASH160 64a8390b0b1685fcbf2d4b457118dc8da92d5534 OP_EQUALVERIFY OP_CHECKSIG',
                'hex': '76a91464a8390b0b1685fcbf2d4b457118dc8da92d553488ac',
                'type': 'p2pkh',
                'address': 'mphBPZf15cRFcL5tUq6mCbE84XobZ1vg7Q'
            }
        }]
    }
    assert unsigned_fund_transaction.type() == "bitcoin_fund_unsigned"
    assert unsigned_fund_transaction.unsigned_raw(
    ) == "eyJmZWUiOiA2NzgsICJyYXciOiAiMDIwMDAwMDAwMWVjMzEyZTkyZDgzODdiMTVmNjIzOGQ0OTE4MzQ0YjYyYWIxNDdkN2YzODQ0ZGM4MWU2NTM3NzZmZThiODRlZjMwMTAwMDAwMDAwZmZmZmZmZmYwMjEwMjcwMDAwMDAwMDAwMDAxN2E5MTQyYmIwMTNjM2U0YmViMDg0MjFkZWRjZjgxNWNiNjVhNWMzODgxNzhiODc1MDhhMGUwMDAwMDAwMDAwMTk3NmE5MTQ2NGE4MzkwYjBiMTY4NWZjYmYyZDRiNDU3MTE4ZGM4ZGE5MmQ1NTM0ODhhYzAwMDAwMDAwIiwgIm91dHB1dHMiOiBbeyJhbW91bnQiOiA5NjM1OTAsICJuIjogMSwgInNjcmlwdCI6ICI3NmE5MTQ2NGE4MzkwYjBiMTY4NWZjYmYyZDRiNDU3MTE4ZGM4ZGE5MmQ1NTM0ODhhYyJ9XSwgIm5ldHdvcmsiOiAidGVzdG5ldCIsICJ0eXBlIjogImJpdGNvaW5fZnVuZF91bnNpZ25lZCJ9"

    signed_fund_transaction = unsigned_fund_transaction.sign(solver=FundSolver(
        private_key=sender_wallet.private_key()))

    assert signed_fund_transaction.fee() == 678
    assert signed_fund_transaction.hash(
    ) == "7e52333d38b7571807caac7971c925dd2c007dbf34a6c46138ff3d0213281d60"
    assert signed_fund_transaction.raw(
    ) == "0200000001ec312e92d8387b15f6238d4918344b62ab147d7f3844dc81e653776fe8b84ef3010000006b483045022100b4d4de4c10bec380a9f07019d5232a9af9f0c2321e5efcf33f5326a60378144502203e1ab2ddaac8afade132832e715f055f956d3e730b9d035a4e99ec9dfdc7acfd012103c56a6005d4a8892d28cc3f7265e5685b548627d59108973e474c4e26f69a4c84ffffffff02102700000000000017a9142bb013c3e4beb08421dedcf815cb65a5c388178b87508a0e00000000001976a91464a8390b0b1685fcbf2d4b457118dc8da92d553488ac00000000"
    assert signed_fund_transaction.json() == {
        'hex':
        '0200000001ec312e92d8387b15f6238d4918344b62ab147d7f3844dc81e653776fe8b84ef3010000006b483045022100b4d4de4c10bec380a9f07019d5232a9af9f0c2321e5efcf33f5326a60378144502203e1ab2ddaac8afade132832e715f055f956d3e730b9d035a4e99ec9dfdc7acfd012103c56a6005d4a8892d28cc3f7265e5685b548627d59108973e474c4e26f69a4c84ffffffff02102700000000000017a9142bb013c3e4beb08421dedcf815cb65a5c388178b87508a0e00000000001976a91464a8390b0b1685fcbf2d4b457118dc8da92d553488ac00000000',
        'txid':
        '7e52333d38b7571807caac7971c925dd2c007dbf34a6c46138ff3d0213281d60',
        'hash':
        '7e52333d38b7571807caac7971c925dd2c007dbf34a6c46138ff3d0213281d60',
        'size':
        224,
        'vsize':
        224,
        'version':
        2,
        'locktime':
        0,
        'vin': [{
            'txid':
            'f34eb8e86f7753e681dc44387f7d14ab624b3418498d23f6157b38d8922e31ec',
            'vout': 1,
            'scriptSig': {
                'asm':
                '3045022100b4d4de4c10bec380a9f07019d5232a9af9f0c2321e5efcf33f5326a60378144502203e1ab2ddaac8afade132832e715f055f956d3e730b9d035a4e99ec9dfdc7acfd01 03c56a6005d4a8892d28cc3f7265e5685b548627d59108973e474c4e26f69a4c84',
                'hex':
                '483045022100b4d4de4c10bec380a9f07019d5232a9af9f0c2321e5efcf33f5326a60378144502203e1ab2ddaac8afade132832e715f055f956d3e730b9d035a4e99ec9dfdc7acfd012103c56a6005d4a8892d28cc3f7265e5685b548627d59108973e474c4e26f69a4c84'
            },
            'sequence': '4294967295'
        }],
        'vout': [{
            'value': '0.00010000',
            'n': 0,
            'scriptPubKey': {
                'asm':
                'OP_HASH160 2bb013c3e4beb08421dedcf815cb65a5c388178b OP_EQUAL',
                'hex': 'a9142bb013c3e4beb08421dedcf815cb65a5c388178b87',
                'type': 'p2sh',
                'address': '2MwEDybGC34949zgzWX4M9FHmE3crDSUydP'
            }
        }, {
            'value': '0.00952912',
            'n': 1,
            'scriptPubKey': {
                'asm':
                'OP_DUP OP_HASH160 64a8390b0b1685fcbf2d4b457118dc8da92d5534 OP_EQUALVERIFY OP_CHECKSIG',
                'hex': '76a91464a8390b0b1685fcbf2d4b457118dc8da92d553488ac',
                'type': 'p2pkh',
                'address': 'mphBPZf15cRFcL5tUq6mCbE84XobZ1vg7Q'
            }
        }]
    }
    assert signed_fund_transaction.type() == "bitcoin_fund_signed"
Example #11
0
print("Unsigned Fund Transaction Fee:",
      unsigned_fund_transaction.fee(unit="Satoshi"), "Satoshi")
print("Unsigned Fund Transaction Hash:", unsigned_fund_transaction.hash())
print("Unsigned Fund Transaction Main Raw:", unsigned_fund_transaction.raw())
# print("Unsigned Fund Transaction Json:", json.dumps(unsigned_fund_transaction.json(), indent=4))
print("Unsigned Fund Transaction Type:", unsigned_fund_transaction.type())

unsigned_fund_transaction_raw: str = unsigned_fund_transaction.transaction_raw(
)
print("Unsigned Fund Transaction Raw:", unsigned_fund_transaction_raw)

print("=" * 10, "Signed Fund Transaction")

# Initialize fund solver
fund_solver: FundSolver = FundSolver(
    xprivate_key=sender_wallet.root_xprivate_key(), path=sender_wallet.path())

# Sing unsigned fund transaction
signed_fund_transaction: FundTransaction = unsigned_fund_transaction.sign(
    solver=fund_solver)

print("Signed Fund Transaction Fee:",
      signed_fund_transaction.fee(unit="Satoshi"), "Satoshi")
print("Signed Fund Transaction Hash:", signed_fund_transaction.hash())
print("Signed Fund Transaction Main Raw:", signed_fund_transaction.raw())
# print("Signed Fund Transaction Json:", json.dumps(signed_fund_transaction.json(), indent=4))
print("Signed Fund Transaction Type:", signed_fund_transaction.type())

signed_fund_transaction_raw = signed_fund_transaction.transaction_raw()
print("Signed Fund Transaction Raw:", signed_fund_transaction_raw)