Example #1
0
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"]
Example #2
0
    def address(self) -> str:
        """
        Get Vapor Hash Time Lock Contract (HTLC) address.

        :returns: str -- Vapor HTLC address.

        >>> 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.address()
        "vp1qf78sazxs539nmzztq7md63fk2x8lew6ed2gu5rnt9um7jerrh07qcyvk37"
        """

        if not self._script or "program" not in self._script:
            raise ValueError("HTLC script is None, first build HTLC.")
        return get_p2wsh_address(script_hash=self.hash(), network=self._network, vapor=True)
Example #3
0
    def contract_address(self) -> 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 = HTLC(network="mainnet")
        >>> htlc.build_htlc(secret_hash=sha256("Hello Meheret!"), recipient_public_key="3e0a377ae4afa031d4551599d9bb7d5b27f4736d77f78cac4d476f0ffba5ae3e", sender_public_key="fe6b3fd4458291b19605d92837ae1060cc0237e68022b2eb9faf01a118226212", endblock=679208)
        >>> htlc.contract_address()
        "bm1qul62nq2l8gmvv9k9ve4e07mlmtxnwgxpzlg833pff9x3kctlul2q727jyy"
        """

        if self._contract_address:
            return self._contract_address
        if not self._script or "program" not in self._script:
            raise ValueError("HTLC script is None, first build HTLC.")
        return get_p2wsh_address(script_hash=self.hash(), network=self._network, vapor=False)
Example #4
0
    def contract_address(self) -> str:
        """
        Get Vapor Hash Time Lock Contract (HTLC) address.

        :returns: str -- Vapor HTLC address.

        >>> 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.contract_address()
        "vp1qxj3ak5psrw2phrk58h8ah5ecrhcmww06vj4h0epxfacr530qhccs4pczgc"
        """

        if self._contract_address:
            return self._contract_address
        if not self._script or "program" not in self._script:
            raise ValueError("HTLC script is None, first build HTLC.")
        return get_p2wsh_address(script_hash=self.hash(), network=self._network, vapor=True)
Example #5
0
                            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,
                                        vapor=True)
print("P2WSH Vapor Address:", p2wsh_vapor_address)