Hash Time Lock Contract (HTLC)¶
Bitcoin Hash Time Lock Contract (HTLC).
-
class
shuttle.providers.bitcoin.htlc.
HTLC
(network='testnet')¶ Bitcoin Hash Time Lock Contract (HTLC) class.
- Parameters
network (str) – Bitcoin network, defaults to testnet.
- Returns
HTLC – Bitcoin HTLC instance.
Note
Bitcoin has only two networks,
mainnet
andtestnet
.-
init
(secret_hash, recipient_address, sender_address, sequence=1000)¶ Initialize Bitcoin Hash Time Lock Contract (HTLC).
- Parameters
secret_hash (str) – secret sha-256 hash.
recipient_address (str) – Bitcoin recipient address.
sender_address (str) – Bitcoin sender address.
sequence (int) – Bitcoin sequence number of expiration block, defaults to 1000.
- Returns
HTLC – Bitcoin Hash Time Lock Contract (HTLC) instance.
>>> from shuttle.providers.bitcoin.htlc import HTLC >>> htlc = HTLC(network="testnet") >>> htlc.init(secret_hash="3a26da82ead15a80533a02696656b14b5dbfd84eb14790f2e1be5e9e45820eeb", recipient_address="muTnffLDR5LtFeLR2i3WsKVfdyvzfyPnVB", sender_address="mphBPZf15cRFcL5tUq6mCbE84XobZ1vg7Q", sequence=1000) <shuttle.providers.bitcoin.htlc.HTLC object at 0x0409DAF0>
-
from_opcode
(opcode)¶ Initiate Bitcoin Hash Time Lock Contract (HTLC) from opcode script.
- Parameters
opcode (str) – Bitcoin opcode script.
- Returns
HTLC – Bitcoin Hash Time Lock Contract (HTLC) instance.
>>> from shuttle.providers.bitcoin.htlc import HTLC >>> htlc = HTLC(network="testnet") >>> htlc_opcode_script = "OP_IF OP_HASH256 821124b554d13f247b1e5d10b84e44fb1296f18f38bbaa1bea34a12c843e0158 OP_EQUALVERIFY OP_DUP OP_HASH160 98f879fb7f8b4951dee9bc8a0327b792fbe332b8 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE e803 OP_CHECKSEQUENCEVERIFY OP_DROP OP_DUP OP_HASH160 64a8390b0b1685fcbf2d4b457118dc8da92d5534 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF" >>> htlc.from_opcode(opcode=htlc_opcode_script) <shuttle.providers.bitcoin.htlc.HTLC object at 0x0409DAF0>
-
from_bytecode
(bytecode)¶ Initiate Bitcoin Hash Time Lock Contract (HTLC) from bytecode.
- Parameters
bytecode (str) – Bitcoin bytecode.
- Returns
HTLC – Bitcoin Hash Time Lock Contract (HTLC) instance.
>>> from shuttle.providers.bitcoin.htlc import HTLC >>> htlc = HTLC(network="testnet") >>> htlc_bytecode = "63aa20821124b554d13f247b1e5d10b84e44fb1296f18f38bbaa1bea34a12c843e01588876a91498f879fb7f8b4951dee9bc8a0327b792fbe332b888ac6702e803b27576a91464a8390b0b1685fcbf2d4b457118dc8da92d553488ac68" >>> htlc.from_bytecode(bytecode=htlc_bytecode) <shuttle.providers.bitcoin.htlc.HTLC object at 0x0409DAF0>
-
bytecode
()¶ Get Bitcoin htlc bytecode.
- Returns
str – Bitcoin Hash Time Lock Contract (HTLC) bytecode.
>>> from shuttle.providers.bitcoin.htlc import HTLC >>> htlc = HTLC(network="testnet") >>> htlc.init("3a26da82ead15a80533a02696656b14b5dbfd84eb14790f2e1be5e9e45820eeb", "muTnffLDR5LtFeLR2i3WsKVfdyvzfyPnVB", "mphBPZf15cRFcL5tUq6mCbE84XobZ1vg7Q", 1000) >>> htlc.bytecode() "63aa20821124b554d13f247b1e5d10b84e44fb1296f18f38bbaa1bea34a12c843e01588876a91498f879fb7f8b4951dee9bc8a0327b792fbe332b888ac6702e803b27576a91464a8390b0b1685fcbf2d4b457118dc8da92d553488ac68"
-
opcode
()¶ Get Bitcoin htlc opcode.
- Returns
str – Bitcoin Hash Time Lock Contract (HTLC) opcode.
>>> from shuttle.providers.bitcoin.htlc import HTLC >>> htlc = HTLC(network="testnet") >>> htlc.init("3a26da82ead15a80533a02696656b14b5dbfd84eb14790f2e1be5e9e45820eeb", "muTnffLDR5LtFeLR2i3WsKVfdyvzfyPnVB", "mphBPZf15cRFcL5tUq6mCbE84XobZ1vg7Q", 1000) >>> htlc.opcode() "OP_IF OP_HASH256 821124b554d13f247b1e5d10b84e44fb1296f18f38bbaa1bea34a12c843e0158 OP_EQUALVERIFY OP_DUP OP_HASH160 98f879fb7f8b4951dee9bc8a0327b792fbe332b8 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE e803 OP_CHECKSEQUENCEVERIFY OP_DROP OP_DUP OP_HASH160 64a8390b0b1685fcbf2d4b457118dc8da92d5534 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF"
-
hash
()¶ Get Bitcoin Hash Time Lock Contract (HTLC) hash.
- Returns
str – Bitcoin Hash Time Lock Contract (HTLC) hash.
>>> from shuttle.providers.bitcoin.htlc import HTLC >>> htlc = HTLC(network="testnet") >>> htlc.init("3a26da82ead15a80533a02696656b14b5dbfd84eb14790f2e1be5e9e45820eeb", "muTnffLDR5LtFeLR2i3WsKVfdyvzfyPnVB", "mphBPZf15cRFcL5tUq6mCbE84XobZ1vg7Q", 1000) >>> htlc.hash() "a9142bb013c3e4beb08421dedcf815cb65a5c388178b87"
-
address
()¶ Get Bitcoin Hash Time Lock Contract (HTLC) address.
- Returns
str – Bitcoin Hash Time Lock Contract (HTLC) address.
>>> from shuttle.providers.bitcoin.htlc import HTLC >>> htlc = HTLC(network="testnet") >>> htlc.init("3a26da82ead15a80533a02696656b14b5dbfd84eb14790f2e1be5e9e45820eeb", "muTnffLDR5LtFeLR2i3WsKVfdyvzfyPnVB", "mphBPZf15cRFcL5tUq6mCbE84XobZ1vg7Q", 1000) >>> htlc.address() "2MwEDybGC34949zgzWX4M9FHmE3crDSUydP"