Hash Time Lock Contract (HTLC)¶
Bytom Hash Time Lock Contract (HTLC).
-
class
swap.providers.bytom.htlc.
HTLC
(network: str = 'mainnet')¶ Bytom Hash Time Lock Contract (HTLC).
- Parameters
network (str) – Bytom network, defaults to mainnet.
- Returns
HTLC – Bytom HTLC instance.
Note
Bytom has only three networks,
mainnet
,solonet
andtestnet
.-
build_htlc
(secret_hash: str, recipient_public_key: str, sender_public_key: str, sequence: int = 1000, use_script: bool = False) → swap.providers.bytom.htlc.HTLC¶ Build Bytom Hash Time Lock Contract (HTLC).
- Parameters
secret_hash (str) – secret sha-256 hash.
recipient_public_key (str) – Bytom recipient public key.
sender_public_key (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 swap.providers.bytom.htlc import HTLC >>> from swap.utils import sha256 >>> htlc = HTLC(network="mainnet") >>> htlc.build_htlc(secret_hash=sha256("Hello Meheret!"), recipient_public_key="3e0a377ae4afa031d4551599d9bb7d5b27f4736d77f78cac4d476f0ffba5ae3e", sender_public_key="91ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2", sequence=1000, use_script=False) <swap.providers.bytom.htlc.HTLC object at 0x0409DAF0>
-
from_bytecode
(bytecode: str) → swap.providers.bytom.htlc.HTLC¶ Initialize Bytom Hash Time Lock Contract (HTLC) from bytecode.
- Parameters
bytecode (str) – Bytom bytecode.
- Returns
HTLC – Bytom Hash Time Lock Contract (HTLC) instance.
>>> from swap.providers.bytom.htlc import HTLC >>> htlc = HTLC(network="testnet") >>> bytecode = "02e8032091ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2203e0a377ae4afa031d4551599d9bb7d5b27f4736d77f78cac4d476f0ffba5ae3e203a26da82ead15a80533a02696656b14b5dbfd84eb14790f2e1be5e9e45820eeb741f547a6416000000557aa888537a7cae7cac631f000000537acd9f6972ae7cac00c0" >>> htlc.from_bytecode(bytecode=bytecode) <swap.providers.bitcoin.htlc.HTLC object at 0x0409DAF0>
-
bytecode
() → str¶ Get Bytom Hash Time Lock Contract (HTLC) bytecode.
- Returns
str – Bytom HTLC bytecode.
>>> from swap.providers.bytom.htlc import HTLC >>> from swap.utils import sha256 >>> htlc = HTLC(network="mainnet") >>> htlc.build_htlc(sha256("Hello Meheret!"), "3e0a377ae4afa031d4551599d9bb7d5b27f4736d77f78cac4d476f0ffba5ae3e", "91ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2", 1000, False) >>> htlc.bytecode() "02e8032091ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2203e0a377ae4afa031d4551599d9bb7d5b27f4736d77f78cac4d476f0ffba5ae3e203a26da82ead15a80533a02696656b14b5dbfd84eb14790f2e1be5e9e45820eeb741f547a6416000000557aa888537a7cae7cac631f000000537acd9f6972ae7cac00c0"
-
opcode
() → Optional[str]¶ Get Bytom Hash Time Lock Contract (HTLC) OP_Code.
- Returns
str – Bytom HTLC opcode.
>>> from swap.providers.bytom.htlc import HTLC >>> from swap.utils import sha256 >>> htlc = HTLC(network="mainnet") >>> htlc.build_htlc(sha256("Hello Meheret!"), "3e0a377ae4afa031d4551599d9bb7d5b27f4736d77f78cac4d476f0ffba5ae3e", "91ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2", 1000, False) >>> htlc.opcode() "0xe803 0x91ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2 0x3e0a377ae4afa031d4551599d9bb7d5b27f4736d77f78cac4d476f0ffba5ae3e 0x3a26da82ead15a80533a02696656b14b5dbfd84eb14790f2e1be5e9e45820eeb DEPTH 0x547a6416000000557aa888537a7cae7cac631f000000537acd9f6972ae7cac FALSE CHECKPREDICATE"
-
hash
() → str¶ Get Bytom Hash Time Lock Contract (HTLC) hash.
- Returns
str – Bytom HTLC hash.
>>> from swap.providers.bytom.htlc import HTLC >>> from swap.utils import sha256 >>> htlc = HTLC(network="mainnet") >>> htlc.build_htlc(sha256("Hello Meheret!"), "3e0a377ae4afa031d4551599d9bb7d5b27f4736d77f78cac4d476f0ffba5ae3e", "91ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2", 1000, False) >>> htlc.hash() "4f8f0e88d0a44b3d884b07b6dd4536518ffcbb596a91ca0e6b2f37e96463bbfc"
-
address
() → str¶ Get Bytom Hash Time Lock Contract (HTLC) address.
- Returns
str – Bytom HTLC address.
>>> from swap.providers.bytom.htlc import HTLC >>> from swap.utils import sha256 >>> htlc = HTLC(network="mainnet") >>> htlc.build_htlc(sha256("Hello Meheret!"), "3e0a377ae4afa031d4551599d9bb7d5b27f4736d77f78cac4d476f0ffba5ae3e", "91ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2", 1000, False) >>> htlc.address() "bm1qf78sazxs539nmzztq7md63fk2x8lew6ed2gu5rnt9um7jerrh07q3yf5q8"
-
balance
(asset: str = 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff') → int¶ Get Bytom HTLC balance.
- Parameters
asset (str) – Bytom asset id, defaults to BTM asset.
- Returns
int – Bytom HTLC balance (NEU amount).
>>> from swap.providers.bytom.htlc import HTLC >>> from swap.utils import sha256 >>> htlc = HTLC(network="mainnet") >>> htlc.build_htlc(sha256("Hello Meheret!"), "3e0a377ae4afa031d4551599d9bb7d5b27f4736d77f78cac4d476f0ffba5ae3e", "91ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2", 1000, False) >>> htlc.balance(asset="ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") 30000
-
utxos
(asset: str = 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', limit: int = 15) → list¶ Get Bytom HTLC unspent transaction output (UTXO’s).
- Parameters
asset (str) – Bytom asset id, defaults to BTM asset.
limit (int) – Limit of UTXO’s, default is 15.
- Returns
list – Bytom unspent transaction outputs.
>>> from swap.providers.bytom.htlc import HTLC >>> from swap.utils import sha256 >>> htlc = HTLC(network="mainnet") >>> htlc.build_htlc(sha256("Hello Meheret!"), "3e0a377ae4afa031d4551599d9bb7d5b27f4736d77f78cac4d476f0ffba5ae3e", "91ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448f22e2", 1000, False) >>> htlc.utxos(asset="ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") [{'hash': '8a0d861767240a284ebed0320b11b81253727ecdac0c80bc6a88127327c0d8a1', 'asset': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'amount': 10000}, {'hash': '76c9ec09f4990122337b1cb9925abc5c5de115065cb1eea7adb7b5fdeb2c6e1e', 'asset': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'amount': 10000}, {'hash': '2637748a967aa5428008aa57159b9795f3aff63b81c72df0575041e7df1efe01', 'asset': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'amount': 10000}]