Exemplo n.º 1
0
def test_vapor_claim_transaction():

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

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

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

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

    assert signed_claim_transaction.type(
    ) == _["vapor"]["claim"]["signed"]["type"]
    assert signed_claim_transaction.fee(
    ) == _["vapor"]["claim"]["signed"]["fee"]
    assert signed_claim_transaction.hash(
    ) == _["vapor"]["claim"]["signed"]["hash"]
    assert signed_claim_transaction.raw(
    ) == _["vapor"]["claim"]["signed"]["raw"]
    # assert signed_claim_transaction.json() == _["vapor"]["claim"]["signed"]["json"]
    assert signed_claim_transaction.unsigned_datas(
    ) == _["vapor"]["claim"]["signed"]["unsigned_datas"]
    assert signed_claim_transaction.signatures(
    ) == _["vapor"]["claim"]["signed"]["signatures"]
    assert signed_claim_transaction.transaction_raw() == clean_transaction_raw(
        transaction_raw=_["vapor"]["claim"]["signed"]["transaction_raw"])
Exemplo n.º 2
0
def test_vapor_normal_transaction():

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

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

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

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

    assert signed_normal_transaction.type(
    ) == _["vapor"]["normal"]["signed"]["type"]
    assert signed_normal_transaction.fee(
    ) == _["vapor"]["normal"]["signed"]["fee"]
    assert signed_normal_transaction.hash(
    ) == _["vapor"]["normal"]["signed"]["hash"]
    assert signed_normal_transaction.raw(
    ) == _["vapor"]["normal"]["signed"]["raw"]
    # assert signed_normal_transaction.json() == _["vapor"]["normal"]["signed"]["json"]
    assert signed_normal_transaction.unsigned_datas(
    ) == _["vapor"]["normal"]["signed"]["unsigned_datas"]
    assert signed_normal_transaction.signatures(
    ) == _["vapor"]["normal"]["signed"]["signatures"]
    assert signed_normal_transaction.transaction_raw(
    ) == clean_transaction_raw(
        transaction_raw=_["vapor"]["normal"]["signed"]["transaction_raw"])
Exemplo n.º 3
0
from swap.providers.vapor.solver import FundSolver
from swap.providers.vapor.signature import FundSignature
from swap.providers.vapor.utils import (
    submit_transaction_raw, amount_unit_converter
)

import json

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

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

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

# Print some Vapor 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())
Exemplo n.º 4
0
import json

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

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

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

# Print some Vapor 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())
Exemplo n.º 5
0
print("Private Key:", sender_wallet.private_key())
print("Public Key:", sender_wallet.public_key())
print("Address:", sender_wallet.address())
print("Balance:", sender_wallet.balance(asset=ASSET, unit="BTM"), "BTM")

print("=" * 10, "Unsigned Normal Transaction")

# Initialize normal transaction
unsigned_normal_transaction: NormalTransaction = NormalTransaction(
    network=NETWORK)
# Build normal transaction
unsigned_normal_transaction.build_transaction(
    address=sender_wallet.address(),
    recipients={
        "vp1q3plwvmvy4qhjmp5zffzmk50aagpujt6flnf63h":
        amount_unit_converter(0.1, "BTM2NEU")
    },
    asset=ASSET)

print("Unsigned Normal Transaction Fee:",
      unsigned_normal_transaction.fee(unit="NEU"), "NEU")
print("Unsigned Normal Transaction Hash:", unsigned_normal_transaction.hash())
print("Unsigned Normal Transaction Main Raw:",
      unsigned_normal_transaction.raw())
# print("Unsigned Normal Transaction Json:", json.dumps(unsigned_normal_transaction.json(), indent=4))
print("Unsigned Normal Transaction Unsigned Datas:",
      json.dumps(unsigned_normal_transaction.unsigned_datas(), indent=4))
print("Unsigned Normal Transaction Signatures:",
      json.dumps(unsigned_normal_transaction.signatures(), indent=4))
print("Unsigned Normal Transaction Type:", unsigned_normal_transaction.type())