def test_bytom_claim_transaction():

    unsigned_claim_transaction = ClaimTransaction(
        network=_["bytom"]["network"])

    unsigned_claim_transaction.build_transaction(
        address=_["bytom"]["wallet"]["recipient"]["address"],
        transaction_id=_["bytom"]["transaction_id"],
        amount=(_["bytom"]["amount"]
                if _["bytom"]["unit"] == "NEU" else amount_unit_converter(
                    _["bytom"]["amount"], f"{_['bytom']['unit']}2NEU")),
        max_amount=_["bytom"]["max_amount"],
        asset=_["bytom"]["asset"],
    )

    assert unsigned_claim_transaction.type(
    ) == _["bytom"]["claim"]["unsigned"]["type"]
    assert unsigned_claim_transaction.fee(
    ) == _["bytom"]["claim"]["unsigned"]["fee"]
    assert unsigned_claim_transaction.hash(
    ) == _["bytom"]["claim"]["unsigned"]["hash"]
    assert unsigned_claim_transaction.raw(
    ) == _["bytom"]["claim"]["unsigned"]["raw"]
    # assert unsigned_claim_transaction.json() == _["bytom"]["claim"]["unsigned"]["json"]
    assert unsigned_claim_transaction.unsigned_datas(
    ) == _["bytom"]["claim"]["unsigned"]["unsigned_datas"]
    assert unsigned_claim_transaction.signatures(
    ) == _["bytom"]["claim"]["unsigned"]["signatures"]
    assert unsigned_claim_transaction.transaction_raw(
    ) == clean_transaction_raw(
        transaction_raw=_["bytom"]["claim"]["unsigned"]["transaction_raw"])

    signed_claim_transaction = unsigned_claim_transaction.sign(
        solver=ClaimSolver(
            xprivate_key=_["bytom"]["wallet"]["recipient"]["xprivate_key"],
            secret_key=_["bytom"]["htlc"]["secret"]["key"],
            bytecode=_["bytom"]["htlc"]["bytecode"],
            path=_["bytom"]["wallet"]["recipient"]["derivation"]["path"],
            account=_["bytom"]["wallet"]["recipient"]["derivation"]["account"],
            change=_["bytom"]["wallet"]["recipient"]["derivation"]["change"],
            address=_["bytom"]["wallet"]["recipient"]["derivation"]
            ["address"]))

    assert signed_claim_transaction.type(
    ) == _["bytom"]["claim"]["signed"]["type"]
    assert signed_claim_transaction.fee(
    ) == _["bytom"]["claim"]["signed"]["fee"]
    assert signed_claim_transaction.hash(
    ) == _["bytom"]["claim"]["signed"]["hash"]
    assert signed_claim_transaction.raw(
    ) == _["bytom"]["claim"]["signed"]["raw"]
    # assert signed_claim_transaction.json() == _["bytom"]["claim"]["signed"]["json"]
    assert signed_claim_transaction.unsigned_datas(
    ) == _["bytom"]["claim"]["signed"]["unsigned_datas"]
    assert signed_claim_transaction.signatures(
    ) == _["bytom"]["claim"]["signed"]["signatures"]
    assert signed_claim_transaction.transaction_raw() == clean_transaction_raw(
        transaction_raw=_["bytom"]["claim"]["signed"]["transaction_raw"])
def test_bytom_normal_transaction():

    unsigned_normal_transaction = NormalTransaction(
        network=_["bytom"]["network"])

    unsigned_normal_transaction.build_transaction(
        address=_["bytom"]["wallet"]["sender"]["address"],
        asset=_["bytom"]["asset"],
        recipients={
            _["bytom"]["wallet"]["recipient"]["address"]:
            (_["bytom"]["amount"]
             if _["bytom"]["unit"] == "NEU" else amount_unit_converter(
                 _["bytom"]["amount"], f"{_['bytom']['unit']}2NEU"))
        })

    assert unsigned_normal_transaction.type(
    ) == _["bytom"]["normal"]["unsigned"]["type"]
    assert unsigned_normal_transaction.fee(
    ) == _["bytom"]["normal"]["unsigned"]["fee"]
    assert unsigned_normal_transaction.hash(
    ) == _["bytom"]["normal"]["unsigned"]["hash"]
    assert unsigned_normal_transaction.raw(
    ) == _["bytom"]["normal"]["unsigned"]["raw"]
    # assert unsigned_normal_transaction.json() == _["bytom"]["normal"]["unsigned"]["json"]
    assert unsigned_normal_transaction.unsigned_datas(
    ) == _["bytom"]["normal"]["unsigned"]["unsigned_datas"]
    assert unsigned_normal_transaction.signatures(
    ) == _["bytom"]["normal"]["unsigned"]["signatures"]
    assert unsigned_normal_transaction.transaction_raw(
    ) == clean_transaction_raw(
        transaction_raw=_["bytom"]["normal"]["unsigned"]["transaction_raw"])

    signed_normal_transaction = unsigned_normal_transaction.sign(
        solver=NormalSolver(
            xprivate_key=_["bytom"]["wallet"]["sender"]["xprivate_key"],
            path=_["bytom"]["wallet"]["sender"]["derivation"]["path"],
            account=_["bytom"]["wallet"]["sender"]["derivation"]["account"],
            change=_["bytom"]["wallet"]["sender"]["derivation"]["change"],
            address=_["bytom"]["wallet"]["sender"]["derivation"]["address"]))

    assert signed_normal_transaction.type(
    ) == _["bytom"]["normal"]["signed"]["type"]
    assert signed_normal_transaction.fee(
    ) == _["bytom"]["normal"]["signed"]["fee"]
    assert signed_normal_transaction.hash(
    ) == _["bytom"]["normal"]["signed"]["hash"]
    assert signed_normal_transaction.raw(
    ) == _["bytom"]["normal"]["signed"]["raw"]
    # assert signed_normal_transaction.json() == _["bytom"]["normal"]["signed"]["json"]
    assert signed_normal_transaction.unsigned_datas(
    ) == _["bytom"]["normal"]["signed"]["unsigned_datas"]
    assert signed_normal_transaction.signatures(
    ) == _["bytom"]["normal"]["signed"]["signatures"]
    assert signed_normal_transaction.transaction_raw(
    ) == clean_transaction_raw(
        transaction_raw=_["bytom"]["normal"]["signed"]["transaction_raw"])
Beispiel #3
0
from swap.providers.bytom.assets import BTM as ASSET
from swap.providers.bytom.solver import FundSolver
from swap.providers.bytom.signature import FundSignature
from swap.providers.bytom.utils import (submit_transaction_raw,
                                        amount_unit_converter)

import json

# Choose network mainnet, solonet or testnet
NETWORK: str = "mainnet"
# Bytom sender wallet mnemonic
SENDER_MNEMONIC: str = "indicate warm sock mistake code spot acid ribbon sing over taxi toast"
# Bytom Hash Time Lock Contract (HTLC) address
HTLC_ADDRESS: str = "bm1qf78sazxs539nmzztq7md63fk2x8lew6ed2gu5rnt9um7jerrh07q3yf5q8"
# Bytom fund amount
AMOUNT: int = amount_unit_converter(0.1, "BTM2NEU")

print("=" * 10, "Sender Bytom Account")

# Initialize Bytom sender wallet
sender_wallet: Wallet = Wallet(network=NETWORK)
# Get Bytom sender wallet from mnemonic
sender_wallet.from_mnemonic(mnemonic=SENDER_MNEMONIC)
# Drive Bytom sender wallet from path
sender_wallet.from_path(path=DEFAULT_PATH)

# Print some Bytom sender wallet info's
print("XPrivate Key:", sender_wallet.xprivate_key())
print("XPublic Key:", sender_wallet.xpublic_key())
print("Private Key:", sender_wallet.private_key())
print("Public Key:", sender_wallet.public_key())
Beispiel #4
0
from swap.providers.bytom.assets import BTM as ASSET
from swap.providers.bytom.solver import NormalSolver
from swap.providers.bytom.signature import NormalSignature
from swap.providers.bytom.utils import (submit_transaction_raw,
                                        amount_unit_converter)

import json

# Choose network mainnet, solonet or testnet
NETWORK: str = "mainnet"
# Bytom sender wallet mnemonic
SENDER_MNEMONIC: str = "unfair divorce remind addict add roof park clown build renew illness fault"
# Bytom recipients address and amount
RECIPIENTS: dict = {
    "bm1q3plwvmvy4qhjmp5zffzmk50aagpujt6f5je85p":
    amount_unit_converter(0.1, "BTM2NEU")
}

print("=" * 10, "Sender Bytom Account")

# Initialize Bytom sender wallet
sender_wallet: Wallet = Wallet(network=NETWORK)
# Get Bytom sender wallet from mnemonic
sender_wallet.from_mnemonic(mnemonic=SENDER_MNEMONIC)
# Drive Bytom sender wallet from path
sender_wallet.from_path(path=DEFAULT_PATH)

# Print some Bytom sender wallet info's
print("XPrivate Key:", sender_wallet.xprivate_key())
print("XPublic Key:", sender_wallet.xpublic_key())
print("Private Key:", sender_wallet.private_key())
Beispiel #5
0
)

import json

# Choose network mainnet, solonet or testnet
NETWORK: str = "mainnet"
# Secret key hash
SECRET_HASH: str = sha256("Hello Meheret!")
# Bytom sender wallet mnemonic
SENDER_MNEMONIC: str = "unfair divorce remind addict add roof park clown build renew illness fault"
# Bytom recipient public key
RECIPIENT_PUBLIC_KEY: str = "3e0a377ae4afa031d4551599d9bb7d5b27f4736d77f78cac4d476f0ffba5ae3e"
# Expiration block height
ENDBLOCK: int = estimate_endblock(endtime=get_current_timestamp(plus=3600))  # 1 hour
# Bytom fund amount
AMOUNT: int = amount_unit_converter(0.1, unit_from="BTM2NEU")

print("=" * 10, "Sender Bytom Account")

# Initialize Bytom sender wallet
sender_wallet: Wallet = Wallet(network=NETWORK)
# Get Bytom sender wallet from mnemonic
sender_wallet.from_mnemonic(mnemonic=SENDER_MNEMONIC)
# Drive Bytom sender wallet from path
sender_wallet.from_path(path=DEFAULT_PATH)

# Print some Bytom sender wallet info's
print("XPrivate Key:", sender_wallet.xprivate_key())
print("XPublic Key:", sender_wallet.xpublic_key())
print("Private Key:", sender_wallet.private_key())
print("Public Key:", sender_wallet.public_key())