def test_p2s(): assert get_script_hash(bytecode=_["script"]["p2s"] ["bytecode"]) == _["script"]["p2s"]["script_hash"] assert get_p2sh_program(script_hash=_["script"]["p2s"]["script_hash"] ) == _["script"]["p2s"]["program"]["p2sh"] assert get_p2wsh_program(script_hash=_["script"]["p2s"]["script_hash"] ) == _["script"]["p2s"]["program"]["p2wsh"] assert get_p2wsh_address( script_hash=_["script"]["p2s"]["script_hash"], network="mainnet", vapor=False) == _["script"]["p2s"]["address"]["mainnet"] assert get_p2wsh_address( script_hash=_["script"]["p2s"]["script_hash"], network="solonet", vapor=False) == _["script"]["p2s"]["address"]["solonet"] assert get_p2wsh_address( script_hash=_["script"]["p2s"]["script_hash"], network="testnet", vapor=False) == _["script"]["p2s"]["address"]["testnet"] assert get_p2wsh_address( script_hash=_["script"]["p2s"]["script_hash"], network="mainnet", vapor=True) == _["script"]["p2s"]["vapor_address"]["mainnet"] assert get_p2wsh_address( script_hash=_["script"]["p2s"]["script_hash"], network="solonet", vapor=True) == _["script"]["p2s"]["vapor_address"]["solonet"] assert get_p2wsh_address( script_hash=_["script"]["p2s"]["script_hash"], network="testnet", vapor=True) == _["script"]["p2s"]["vapor_address"]["testnet"]
def hash(self) -> str: """ Get Vapor Hash Time Lock Contract (HTLC) hash. :returns: str -- Vapor HTLC hash. >>> from swap.providers.vapor.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" """ if not self._script or "program" not in self._script: raise ValueError("HTLC script is None, first build HTLC.") return get_script_hash(bytecode=self.bytecode())
def hash(self) -> 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 = HTLC(network="mainnet") >>> htlc.build_htlc(secret_hash=sha256("Hello Meheret!"), recipient_public_key="3e0a377ae4afa031d4551599d9bb7d5b27f4736d77f78cac4d476f0ffba5ae3e", sender_public_key="fe6b3fd4458291b19605d92837ae1060cc0237e68022b2eb9faf01a118226212", endblock=679208) >>> htlc.hash() "e7f4a9815f3a36c616c5666b97fb7fdacd3720c117d078c429494d1b617fe7d4" """ if not self._script or "program" not in self._script: raise ValueError("HTLC script is None, first build HTLC.") return get_script_hash(bytecode=self.bytecode())
def hash(self) -> str: """ Get Vapor Hash Time Lock Contract (HTLC) hash. :returns: str -- Vapor HTLC hash. >>> from swap.providers.vapor.htlc import HTLC >>> from swap.utils import sha256 >>> htlc: HTLC = HTLC(network="mainnet") >>> htlc.build_htlc(secret_hash=sha256("Hello Meheret!"), recipient_public_key="3e0a377ae4afa031d4551599d9bb7d5b27f4736d77f78cac4d476f0ffba5ae3e", sender_public_key="fe6b3fd4458291b19605d92837ae1060cc0237e68022b2eb9faf01a118226212", endblock=120723497) >>> htlc.hash() "34a3db50301b941b8ed43dcfdbd3381df1b739fa64ab77e4264f703a45e0be31" """ if not self._script or "program" not in self._script: raise ValueError("HTLC script is None, first build HTLC.") return get_script_hash(bytecode=self.bytecode())
#!/usr/bin/env python3 from pybytom.script import (get_script_hash, get_p2sh_program, get_p2wsh_program, get_p2wsh_address) # Choose network mainnet, solonet or testnet NETWORK: str = "mainnet" # Bytom Smart Contract program(bytecode) BYTECODE: str = "01642091ff7f525ff40874c4f47f0cab42e46e3bf53adad59adef9558ad1b6448" \ "f22e220ac13c0bb1445423a641754182d53f0677cd4351a0e743e6f10b35122c3" \ "d7ea01203a26da82ead15a80533a02696656b14b5dbfd84eb14790f2e1be5e9e4" \ "5820eeb741f547a6416000000557aa888537a7cae7cac631f000000537acd9f69" \ "72ae7cac00c0" # Get script hash script_hash = get_script_hash(bytecode=BYTECODE) print("Script Hash:", script_hash) # Get Pay to Script Hash(P2SH) program p2sh_program = get_p2sh_program(script_hash=script_hash) print("P2SH Program:", p2sh_program) # Get Pay to Witness Script Hash(P2WSH) program p2wsh_program = get_p2wsh_program(script_hash=script_hash) print("P2WSH Program:", p2wsh_program) # Get Pay to Witness Script Hash(P2WSH) address p2wsh_address = get_p2wsh_address(script_hash=script_hash, network=NETWORK, vapor=False) print("P2WSH Address:", p2wsh_address) # Get Pay to Witness Script Hash(P2WSH) vapor address p2wsh_vapor_address = get_p2wsh_address(script_hash=script_hash, network=NETWORK,