Esempio n. 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"]
Esempio n. 2
0
    def utxos(self,
              asset: Union[str, AssetNamespace] = config["asset"],
              limit: int = 15) -> list:
        """
        Get Bytom HTLC unspent transaction output (UTXO's).

        :param asset: Bytom asset id, defaults to ``BTM``.
        :type asset: str, bytom.assets.AssetNamespace
        :param limit: Limit of UTXO's, default is ``15``.
        :type limit: int

        :return: list -- Bytom unspent transaction outputs.

        >>> 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.utxos(asset="ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
        [{'hash': '1aaf7df33c1d41bc6108c93d8b6da6af1d7f68632f54516408a03ff86494a1f0', 'asset': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'amount': 10000000}]
        """

        return get_utxos(program=get_p2wsh_program(script_hash=self.hash()),
                         asset=(str(asset.ID) if isinstance(
                             asset, AssetNamespace) else asset),
                         limit=limit)
Esempio n. 3
0
    def utxos(self,
              asset: Union[str, AssetNamespace] = config["asset"],
              limit: int = 15) -> list:
        """
        Get Vapor HTLC unspent transaction output (UTXO's).

        :param asset: Vapor asset id, defaults to ``BTM``.
        :type asset: str, vapor.assets.AssetNamespace
        :param limit: Limit of UTXO's, default is ``15``.
        :type limit: int

        :return: list -- Vapor unspent transaction outputs.

        >>> 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.utxos(asset="ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
        [{'hash': '144dd8355cae0d9aea6ca3fb1ff685fb7b455b1f9cb0c5992c9035844c664ad1', 'asset': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'amount': 10000000}]
        """

        return get_utxos(program=get_p2wsh_program(script_hash=self.hash()),
                         asset=(str(asset.ID) if isinstance(
                             asset, AssetNamespace) else asset),
                         limit=limit)
Esempio n. 4
0
    def utxos(self, asset: Union[str, AssetNamespace] = config["asset"], limit: int = 15) -> list:
        """
        Get Vapor HTLC unspent transaction output (UTXO's).

        :param asset: Vapor asset id, defaults to BTM asset.
        :type asset: str, vapor.assets.AssetNamespace
        :param limit: Limit of UTXO's, default is 15.
        :type limit: int

        :return: list -- Vapor unspent transaction outputs.

        >>> 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.utxos(asset="ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
        [{'hash': '8a0d861767240a284ebed0320b11b81253727ecdac0c80bc6a88127327c0d8a1', 'asset': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'amount': 10000}, {'hash': '76c9ec09f4990122337b1cb9925abc5c5de115065cb1eea7adb7b5fdeb2c6e1e', 'asset': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'amount': 10000}, {'hash': '2637748a967aa5428008aa57159b9795f3aff63b81c72df0575041e7df1efe01', 'asset': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'amount': 10000}]
        """

        return get_utxos(
            program=get_p2wsh_program(script_hash=self.hash()),
            asset=(str(asset.ID) if isinstance(asset, AssetNamespace) else asset),
            limit=limit
        )
Esempio n. 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)