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 and testnet.

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(secret_hash, recipient_address, sender_address, 100)
>>> htlc.address()
"2N729UBGZB3xjsGFRgKivy4bSjkaJGMVSpB"
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(secret_hash, recipient_address, sender_address, 100)
>>> htlc.bytecode()
"63aa20b9b9a0c47ecee7fd94812573a7b14afa02ec250dbdb5875a55c4d02367fcc2ab8876a9147b7c4431a43b612a72f8229935c469f1f690365888ac6755b27576a9146bce65e58a50b97989930e9a4ff1ac1a77515ef188ac68"
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.from_bytecode(htlc_bytecode)
<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.from_opcode(htlc_opcode_script)
<shuttle.providers.bitcoin.htlc.HTLC object at 0x0409DAF0>
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(secret_hash, recipient_address, sender_address, 100)
>>> htlc.hash()
"a914971894c58d85981c16c2059d422bcde0b156d04487"
init(secret_hash, recipient_address, sender_address, sequence=100)

Initialize bitcoin Hash Time Lock Contract (HTLC).

Parameters
  • secret_hash (hash) – 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, recipient_address, sender_address, 100)
<shuttle.providers.bitcoin.htlc.HTLC object at 0x0409DAF0>
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(secret_hash, recipient_address, sender_address, 100)
>>> htlc.opcode()
"OP_IF OP_HASH256 b9b9a0c47ecee7fd94812573a7b14afa02ec250dbdb5875a55c4d02367fcc2ab OP_EQUALVERIFY OP_DUP OP_HASH160 7b7c4431a43b612a72f8229935c469f1f6903658 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_5 OP_CHECKSEQUENCEVERIFY OP_DROP OP_DUP OP_HASH160 6bce65e58a50b97989930e9a4ff1ac1a77515ef1 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF"