示例#1
0
def test_bytom_htlc():

    htlc = HTLC(network="mainnet").init(
        secret_hash=sha256("Hello Meheret!".encode()).hex(),
        recipient_public=
        "91ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2",
        sender_public=
        "3e0a377ae4afa031d4551599d9bb7d5b27f4736d77f78cac4d476f0ffba5ae3e",
        sequence=1000,
        use_script=False)

    assert htlc.bytecode() == "02e803203e0a377ae4afa031d4551599d9bb7d5b27f4736d77f78cac4d476f0ffba5ae3e2091ff" \
                              "7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2203a26da82ead15a80" \
                              "533a02696656b14b5dbfd84eb14790f2e1be5e9e45820eeb741f547a6416000000557aa888537a" \
                              "7cae7cac631f000000537acd9f6972ae7cac00c0"
    assert htlc.opcode() == "0xe803 0x3e0a377ae4afa031d4551599d9bb7d5b27f4736d77f78cac4d476f0ffba5ae3e 0x91ff" \
                            "7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2 0x3a26da82ead15a805" \
                            "33a02696656b14b5dbfd84eb14790f2e1be5e9e45820eeb DEPTH 0x547a6416000000557aa88853" \
                            "7a7cae7cac631f000000537acd9f6972ae7cac FALSE CHECKPREDICATE"
    assert htlc.hash(
    ) == "a5addb7eb5649d10031304ece72d9ccc9dc424abcda895d904a309727424e40e"
    assert htlc.address(
    ) == "bm1q5kkakl44vjw3qqcnqnkwwtvuejwugf9tek5ftkgy5vyhyapyus8qgcttcs"

    assert HTLC().from_bytecode(bytecode=htlc.bytecode())
示例#2
0
# print("Recipient Balance:", recipient_balance)

print("=" * 10, "Hash Time Lock Contract (HTLC) between Sender and Recipient")

# Initializing Hash Time Lock Contract (HTLC)
htlc = HTLC(network=NETWORK).init(secret_hash=sha256(
    "Hello Meheret!".encode()).hex(),
                                  recipient_public=recipient_public_key,
                                  sender_public=sender_public_key,
                                  sequence=1000)

htlc_bytecode = htlc.bytecode()
print("HTLC Bytecode:", htlc_bytecode)
htlc_opcode = htlc.opcode()
print("HTLC OP_Code:", htlc_opcode)
htlc_hash = htlc.hash()
print("HTLC Hash:", htlc_hash)
htlc_address = htlc.address()
print("HTLC Address:", htlc_address)

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

# Initializing fund transaction
unsigned_fund_transaction = FundTransaction(network=NETWORK)
# Building fund transaction
unsigned_fund_transaction.build_transaction(wallet=sender_wallet,
                                            htlc=htlc,
                                            amount=AMOUNT,
                                            asset=ASSET)

print("Unsigned Fund Transaction Fee:", unsigned_fund_transaction.fee())