示例#1
0
    address=wallet.address(vapor=VAPOR),
    asset=ASSET,
    amount=amount_converter(0.0001, "BTM2NEU"),
    confirmations=1,
    network=NETWORK,
    vapor=VAPOR)

print("Estimated Transaction Fee:", estimated_transaction_fee)

# Build Bytom advanced transaction
unsigned_advanced_transaction.build_transaction(
    wallet.address(vapor=VAPOR),  # address
    [
        spend_utxo(utxo=find_p2wsh_utxo(
            transaction_id=
            "049d4c26bb15885572c16e0eefac5b2f4d0fde50eaf90f002272d39507ff315b",
            network=NETWORK,
            vapor=VAPOR))
    ],  # inputs
    [
        control_address(asset=ASSET,
                        amount=0.0001,
                        address=wallet.address(vapor=VAPOR),
                        symbol="BTM")
    ],  # outputs
    estimated_transaction_fee,  # fee
    1,  # confirmations
    False,  # forbid_chain_tx
)

print("\nUnsigned Advanced Transaction Fee:",
示例#2
0
def test_transaction():

    estimated_transaction_fee: int = estimate_transaction_fee(
        address=_["wallet"]["vapor_address"]["mainnet"],
        asset=ASSET,
        amount=amount_converter(0.0001, "BTM2NEU"),
        confirmations=1,
        network=_["network"],
        vapor=True)

    assert isinstance(estimated_transaction_fee, int)
    assert estimated_transaction_fee == 449000

    unsigned_transaction: Transaction = Transaction(
        network=_["network"], vapor=True
    ).build_transaction(
        address=_["wallet"]["vapor_address"]["mainnet"],
        inputs=[
            spend_utxo(utxo=find_p2wsh_utxo(
                transaction_id=
                "675392fcbc1867e247add457597611717229e5d2c46a53c44e3e61d6ce351474",
                network=_["network"],
                vapor=True))
        ],
        outputs=[
            control_address(asset=ASSET,
                            amount=amount_converter(0.0001, "BTM2NEU"),
                            address=_["wallet"]["vapor_address"]["mainnet"],
                            symbol="NEU",
                            vapor=True)
        ],
        fee=estimated_transaction_fee,
        confirmations=1,
        forbid_chain_tx=False)

    assert unsigned_transaction.fee(
    ) == _["transaction"]["transaction"]["unsigned"]["fee"]
    assert unsigned_transaction.confirmations(
    ) == _["transaction"]["transaction"]["unsigned"]["confirmations"]
    assert unsigned_transaction.hash(
    ) == _["transaction"]["transaction"]["unsigned"]["hash"]
    assert unsigned_transaction.raw(
    ) == _["transaction"]["transaction"]["unsigned"]["raw"]
    assert unsigned_transaction.json(
    ) == _["transaction"]["transaction"]["unsigned"]["json"]
    assert unsigned_transaction.unsigned_datas(
        False) == _["transaction"]["transaction"]["unsigned"]["unsigned_datas"]
    assert unsigned_transaction.signatures(
    ) == _["transaction"]["transaction"]["unsigned"]["signatures"]

    signed_transaction = unsigned_transaction.sign(
        xprivate_key=_["wallet"]["xprivate_key"],
        indexes=_["wallet"]["indexes"])

    assert signed_transaction.fee(
    ) == _["transaction"]["transaction"]["signed"]["fee"]
    assert signed_transaction.confirmations(
    ) == _["transaction"]["transaction"]["signed"]["confirmations"]
    assert signed_transaction.hash(
    ) == _["transaction"]["transaction"]["signed"]["hash"]
    assert signed_transaction.raw(
    ) == _["transaction"]["transaction"]["signed"]["raw"]
    assert signed_transaction.json(
    ) == _["transaction"]["transaction"]["signed"]["json"]
    assert signed_transaction.unsigned_datas(
        False) == _["transaction"]["transaction"]["signed"]["unsigned_datas"]
    assert signed_transaction.signatures(
    ) == _["transaction"]["transaction"]["signed"]["signatures"]
示例#3
0
    def build_transaction(
        self,
        address: str,
        transaction_hash: str,
        asset: Union[str, AssetNamespace] = config["asset"]
    ) -> "RefundTransaction":
        """
        Build Vapor refund transaction.

        :param address: Vapor sender wallet address.
        :type address: str
        :param transaction_hash: Vapor funded transaction hash/id
        :type transaction_hash: str
        :param asset: Vapor asset id, defaults to ``BTM``.
        :type asset: str, vapor.assets.AssetNamespace

        :returns: RefundTransaction -- Vapor refund transaction instance.

        >>> from swap.providers.vapor.transaction import RefundTransaction
        >>> refund_transaction: RefundTransaction = RefundTransaction(network="mainnet")
        >>> refund_transaction.build_transaction(address="vp1qk9vj4jaezlcnjdckds4fkm8fwv5kawmqwpnpvs", transaction_hash="37b36d7be5dfda0cc5dc3c918705464ff901dc5eadb6f4f049db03a679e02bfe", asset="ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
        <swap.providers.vapor.transaction.RefundTransaction object at 0x0409DAF0>
        """

        # Check parameter instances
        if not is_address(address, self._network):
            raise AddressError(
                f"Invalid Vapor sender '{address}' {self._network} address.")

        # Set address, fee, confirmations and transaction_hash
        self._address, self._asset, self._confirmations, self._transaction_hash = (
            address,
            (str(asset.ID) if isinstance(asset, AssetNamespace) else asset),
            config["confirmations"], transaction_hash)
        # Get transaction
        self._transaction_detail = get_transaction(
            transaction_hash=self._transaction_hash, network=self._network)
        # Find HTLC UTXO
        self._htlc_utxo = find_p2wsh_utxo(transaction=self._transaction_detail)
        if self._htlc_utxo is None:
            raise ValueError(
                "Invalid transaction id, there is no pay to witness script hash (P2WSH) address."
            )

        self._amount = self._htlc_utxo["amount"]

        # Estimating transaction fee
        self._fee = estimate_transaction_fee(
            address=self._htlc_utxo["address"],
            amount=self._amount,
            asset=self._asset,
            confirmations=self._confirmations,
            network=self._network) + 60000

        # Build transaction
        self._transaction = build_transaction(
            address=self._htlc_utxo["address"],
            transaction=dict(fee=str(
                amount_unit_converter(amount=self._fee, unit_from="NEU2BTM")),
                             confirmations=self._confirmations,
                             inputs=[spend_utxo(utxo=self._htlc_utxo["id"])],
                             outputs=[
                                 control_address(asset=self._asset,
                                                 amount=(self._amount -
                                                         self._fee),
                                                 address=self._address,
                                                 vapor=True)
                             ]),
            network=self._network)

        # Set transaction type
        self._type = "vapor_refund_unsigned"
        return self
示例#4
0
def test_advanced_transaction():

    estimated_transaction_fee: int = estimate_transaction_fee(
        address=_["wallet"]["address"]["mainnet"],
        asset=ASSET,
        amount=amount_converter(0.0001, "BTM2NEU"),
        confirmations=1,
        network=_["network"],
        vapor=False
    )

    assert isinstance(estimated_transaction_fee, int)
    assert estimated_transaction_fee == 449000

    unsigned_advanced_transaction: AdvancedTransaction = AdvancedTransaction(
        network=_["network"], vapor=False
    ).build_transaction(
        address=_["wallet"]["address"]["mainnet"],
        inputs=[
            spend_utxo(
                utxo=find_p2wsh_utxo(
                    transaction_id="049d4c26bb15885572c16e0eefac5b2f4d0fde50eaf90f002272d39507ff315b",
                    network=_["network"],
                    vapor=False
                )
            )
        ],
        outputs=[
            control_address(
                asset=ASSET,
                amount=10_000,
                address=_["wallet"]["address"]["mainnet"],
                symbol="NEU",
                vapor=False
            )
        ],
        fee=estimated_transaction_fee,
        confirmations=1,
        forbid_chain_tx=False
    )

    assert unsigned_advanced_transaction.fee() == _["transaction"]["advanced_transaction"]["unsigned"]["fee"]
    assert unsigned_advanced_transaction.confirmations() == _["transaction"]["advanced_transaction"]["unsigned"]["confirmations"]
    assert unsigned_advanced_transaction.hash() == _["transaction"]["advanced_transaction"]["unsigned"]["hash"]
    assert unsigned_advanced_transaction.raw() == _["transaction"]["advanced_transaction"]["unsigned"]["raw"]
    assert unsigned_advanced_transaction.json() == _["transaction"]["advanced_transaction"]["unsigned"]["json"]
    assert unsigned_advanced_transaction.unsigned_datas(False) == _["transaction"]["advanced_transaction"]["unsigned"]["unsigned_datas"]
    assert unsigned_advanced_transaction.signatures() == _["transaction"]["advanced_transaction"]["unsigned"]["signatures"]

    signed_advanced_transaction = unsigned_advanced_transaction.sign(
        xprivate_key=_["wallet"]["xprivate_key"],
        indexes=_["wallet"]["indexes"]
    )

    assert signed_advanced_transaction.fee() == _["transaction"]["advanced_transaction"]["signed"]["fee"]
    assert signed_advanced_transaction.confirmations() == _["transaction"]["advanced_transaction"]["signed"]["confirmations"]
    assert signed_advanced_transaction.hash() == _["transaction"]["advanced_transaction"]["signed"]["hash"]
    assert signed_advanced_transaction.raw() == _["transaction"]["advanced_transaction"]["signed"]["raw"]
    assert signed_advanced_transaction.json() == _["transaction"]["advanced_transaction"]["signed"]["json"]
    assert signed_advanced_transaction.unsigned_datas(False) == _["transaction"]["advanced_transaction"]["signed"]["unsigned_datas"]
    assert signed_advanced_transaction.signatures() == _["transaction"]["advanced_transaction"]["signed"]["signatures"]
示例#5
0
    def build_transaction(
        self,
        address: str,
        transaction_hash: str,
        asset: Union[str, AssetNamespace] = config["asset"]
    ) -> "RefundTransaction":
        """
        Build Bytom refund transaction.

        :param address: Bytom sender wallet address.
        :type address: str
        :param transaction_hash: Bytom funded transaction hash/id
        :type transaction_hash: str
        :param asset: Bytom asset id, defaults to ``BTM``.
        :type asset: str, bytom.assets.AssetNamespace

        :returns: RefundTransaction -- Bytom refund transaction instance.

        >>> from swap.providers.bytom.transaction import RefundTransaction
        >>> refund_transaction: RefundTransaction = RefundTransaction(network="mainnet")
        >>> refund_transaction.build_transaction(address="bm1qk9vj4jaezlcnjdckds4fkm8fwv5kawmq9qrufx", transaction_hash="59b1e43b57cba1afa5834eb9886e4a9fba031c9880ce7ae29d32c36f6b47496f", asset="ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
        <swap.providers.bytom.transaction.RefundTransaction object at 0x0409DAF0>
        """

        # Check parameter instances
        if not is_address(address, self._network):
            raise AddressError(
                f"Invalid Bytom sender '{address}' {self._network} address.")

        # Set address, fee, confirmations and transaction_hash
        self._address, self._asset, self._confirmations, self._transaction_hash = (
            address,
            (str(asset.ID) if isinstance(asset, AssetNamespace) else asset),
            config["confirmations"], transaction_hash)
        # Get transaction
        self._transaction_detail = get_transaction(
            transaction_hash=self._transaction_hash, network=self._network)
        # Find HTLC UTXO
        self._htlc_utxo = find_p2wsh_utxo(transaction=self._transaction_detail)
        if self._htlc_utxo is None:
            raise ValueError(
                "Invalid transaction id, there is no pay to witness script hash (P2WSH) address."
            )

        self._amount = self._htlc_utxo["amount"]

        # Estimating transaction fee
        self._fee = estimate_transaction_fee(
            address=self._htlc_utxo["address"],
            amount=self._amount,
            asset=self._asset,
            confirmations=self._confirmations,
            network=self._network) + 60000

        # Build transaction
        self._transaction = build_transaction(
            address=self._htlc_utxo["address"],
            transaction=dict(fee=str(
                amount_unit_converter(amount=self._fee, unit_from="NEU2BTM")),
                             confirmations=self._confirmations,
                             inputs=[spend_utxo(utxo=self._htlc_utxo["id"])],
                             outputs=[
                                 control_address(asset=self._asset,
                                                 amount=(self._amount -
                                                         self._fee),
                                                 address=self._address,
                                                 vapor=False)
                             ]),
            network=self._network)

        # Set transaction type
        self._type = "bytom_refund_unsigned"
        return self
示例#6
0
    address=wallet.address(vapor=VAPOR),
    asset=ASSET,
    amount=amount_converter(0.0001, "BTM2NEU"),
    confirmations=1,
    network=NETWORK,
    vapor=VAPOR)

print("Estimated Transaction Fee:", estimated_transaction_fee)

# Build Bytom transaction
unsigned_transaction.build_transaction(
    address=wallet.address(vapor=VAPOR),
    inputs=[
        spend_utxo(utxo=find_p2wsh_utxo(
            transaction_id=
            "675392fcbc1867e247add457597611717229e5d2c46a53c44e3e61d6ce351474",
            network=NETWORK,
            vapor=VAPOR))
    ],
    outputs=[
        control_address(asset=ASSET,
                        amount=amount_converter(0.0001, "BTM2NEU"),
                        address=wallet.address(vapor=VAPOR),
                        symbol="NEU",
                        vapor=VAPOR)
    ],
    fee=estimated_transaction_fee,
    confirmations=1)

print("\nUnsigned Transaction Fee:", unsigned_transaction.fee())
print("Unsigned Transaction Confirmations:",