Hash Time Lock Contract (HTLC)

Bytom Hash Time Lock Contract (HTLC).

class shuttle.providers.bytom.htlc.HTLC(network='testnet')

Bytom Hash Time Lock Contract (HTLC) class.

Parameters

network (str) – Bytom network, defaults to testnet.

Returns

HTLC – Bytom HTLC instance.

Note

Bytom has only three networks, mainnet, solonet and testnet.

init(secret_hash, recipient_public, sender_public, sequence=1000, use_script=False)

Initialize Bytom Hash Time Lock Contract (HTLC).

Parameters
  • secret_hash (str) – secret sha-256 hash.

  • recipient_public (str) – Bytom recipient public key.

  • sender_public (str) – Bytom sender public key.

  • sequence (int) – Bytom sequence number(expiration block), defaults to Bytom config sequence.

  • use_script (bool) – Initialize HTLC by using script, default to False.

Returns

HTLC – Bytom Hash Time Lock Contract (HTLC) instance.

>>> from shuttle.providers.bytom.htlc import HTLC
>>> from shuttle.utils import sha256
>>> htlc = HTLC(network="mainnet")
>>> htlc.init(secret_hash=sha256("Hello Meheret!".encode()).hex(), recipient_public="91ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2", sender_public="d4351a0e743e6f10b35122ac13c0bb1445423a641754182d53f0677cc3d7ea01", sequence=1000, use_script=False)
<shuttle.providers.bytom.htlc.HTLC object at 0x0409DAF0>
bytecode()

Get Bytom htlc bytecode.

Returns

str – Bytom Hash Time Lock Contract (HTLC) bytecode.

>>> from shuttle.providers.bytom.htlc import HTLC
>>> from shuttle.utils import sha256
>>> htlc = HTLC(network="mainnet")
>>> htlc.init(sha256("Hello Meheret!".encode()).hex(), "91ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2", "d4351a0e743e6f10b35122ac13c0bb1445423a641754182d53f0677cc3d7ea01", 1000, False)
>>> htlc.bytecode()
"02e80320d4351a0e743e6f10b35122ac13c0bb1445423a641754182d53f0677cc3d7ea012091ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2203a26da82ead15a80533a02696656b14b5dbfd84eb14790f2e1be5e9e45820eeb741f547a6416000000557aa888537a7cae7cac631f000000537acd9f6972ae7cac00c0"
opcode()

Get Bytom htlc opcode.

Returns

str – Bytom Hash Time Lock Contract (HTLC) opcode.

>>> from shuttle.providers.bytom.htlc import HTLC
>>> from shuttle.utils import sha256
>>> htlc = HTLC(network="mainnet")
>>> htlc.init(sha256("Hello Meheret!".encode()).hex(), "91ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2", "d4351a0e743e6f10b35122ac13c0bb1445423a641754182d53f0677cc3d7ea01", 1000, False)
>>> htlc.opcode()
"0xe803 0xd4351a0e743e6f10b35122ac13c0bb1445423a641754182d53f0677cc3d7ea01 0x91ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2 0x3a26da82ead15a80533a02696656b14b5dbfd84eb14790f2e1be5e9e45820eeb DEPTH 0x547a6416000000557aa888537a7cae7cac631f000000537acd9f6972ae7cac FALSE CHECKPREDICATE"
hash()

Get Bytom Hash Time Lock Contract (HTLC) hash.

Returns

str – Bytom Hash Time Lock Contract (HTLC) hash.

>>> from shuttle.providers.bytom.htlc import HTLC
>>> from shuttle.utils import sha256
>>> htlc = HTLC(network="mainnet")
>>> htlc.init(sha256("Hello Meheret!".encode()).hex(), "91ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2", "d4351a0e743e6f10b35122ac13c0bb1445423a641754182d53f0677cc3d7ea01", 1000, False)
>>> htlc.hash()
"b3c67ffb38fa981ee368aa9dfc856bd62c6b93df9069deccd8159911c46c216a"
address()

Get Bytom Hash Time Lock Contract (HTLC) address.

Returns

str – Bytom Hash Time Lock Contract (HTLC) address.

>>> from shuttle.providers.bytom.htlc import HTLC
>>> from shuttle.utils import sha256
>>> htlc = HTLC(network="mainnet")
>>> htlc.init(sha256("Hello Meheret!".encode()).hex(), "91ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2", "d4351a0e743e6f10b35122ac13c0bb1445423a641754182d53f0677cc3d7ea01", 1000, False)
>>> htlc.address()
"bm1qk0r8l7ecl2vpacmg42wleptt6ckxhy7ljp5aanxczkv3r3rvy94q4a2zpc"