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 Bitcoin config sequence (15).
- Returns
HTLC – Bitcoin Hash Time Lock Contract (HTLC) instance.
>>> from shuttle.providers.bitcoin.htlc import HTLC >>> htlc = HTLC(network="testnet") >>> htlc.init(secret_hash="4683a21fd5ce2425adc90a3674b6d8d3d418935540fc3a71c6ec3cb249925dd3", 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 0535b276351b7f7a7fe817ee0927fd7203ccaf68af8ec146486d28ab34d3b7de 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 = "63aa200535b276351b7f7a7fe817ee0927fd7203ccaf68af8ec146486d28ab34d3b7de8876a91498f879fb7f8b4951dee9bc8a0327b792fbe332b888ac6702e803b27576a91464a8390b0b1685fcbf2d4b457118dc8da92d553488ac68" >>> 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("4683a21fd5ce2425adc90a3674b6d8d3d418935540fc3a71c6ec3cb249925dd3", "muTnffLDR5LtFeLR2i3WsKVfdyvzfyPnVB", "mphBPZf15cRFcL5tUq6mCbE84XobZ1vg7Q", 1000) >>> htlc.bytecode() "63aa200535b276351b7f7a7fe817ee0927fd7203ccaf68af8ec146486d28ab34d3b7de8876a91498f879fb7f8b4951dee9bc8a0327b792fbe332b888ac6702e803b27576a91464a8390b0b1685fcbf2d4b457118dc8da92d553488ac68"
-
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("4683a21fd5ce2425adc90a3674b6d8d3d418935540fc3a71c6ec3cb249925dd3", "muTnffLDR5LtFeLR2i3WsKVfdyvzfyPnVB", "mphBPZf15cRFcL5tUq6mCbE84XobZ1vg7Q", 1000) >>> htlc.opcode() "OP_IF OP_HASH256 0535b276351b7f7a7fe817ee0927fd7203ccaf68af8ec146486d28ab34d3b7de 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("4683a21fd5ce2425adc90a3674b6d8d3d418935540fc3a71c6ec3cb249925dd3", "muTnffLDR5LtFeLR2i3WsKVfdyvzfyPnVB", "mphBPZf15cRFcL5tUq6mCbE84XobZ1vg7Q", 1000) >>> htlc.hash() "a91450dbc89c9a42e55b7995c2aa587631af0193d4b887"
-
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("4683a21fd5ce2425adc90a3674b6d8d3d418935540fc3a71c6ec3cb249925dd3", "muTnffLDR5LtFeLR2i3WsKVfdyvzfyPnVB", "mphBPZf15cRFcL5tUq6mCbE84XobZ1vg7Q", 1000) >>> htlc.address() "2MzcmLTwnccUbxdm13MYXvErCXTgs3DuEQ4"