def test_normal_transaction():

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

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

    unsigned_normal_transaction: NormalTransaction = NormalTransaction(
        network=_["network"], vapor=False).build_transaction(
            address=_["wallet"]["address"]["mainnet"],
            recipients={
                "bm1qg83h7fddr70dsw6c2c3zhc25fved9mhydp6u8d":
                amount_converter(0.0005, "BTM2NEU")
            },
            asset=ASSET,
            fee=estimated_transaction_fee,
            confirmations=1,
            forbid_chain_tx=False)

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

    signed_normal_transaction: NormalTransaction = unsigned_normal_transaction.sign(
        xprivate_key=_["wallet"]["xprivate_key"],
        indexes=_["wallet"]["indexes"])

    assert signed_normal_transaction.fee(
    ) == _["transaction"]["normal_transaction"]["signed"]["fee"]
    assert signed_normal_transaction.confirmations(
    ) == _["transaction"]["normal_transaction"]["signed"]["confirmations"]
    assert signed_normal_transaction.hash(
    ) == _["transaction"]["normal_transaction"]["signed"]["hash"]
    assert signed_normal_transaction.raw(
    ) == _["transaction"]["normal_transaction"]["signed"]["raw"]
    assert signed_normal_transaction.json(
    ) == _["transaction"]["normal_transaction"]["signed"]["json"]
    assert signed_normal_transaction.unsigned_datas(False) == _["transaction"][
        "normal_transaction"]["signed"]["unsigned_datas"]
    assert signed_normal_transaction.signatures(
    ) == _["transaction"]["normal_transaction"]["signed"]["signatures"]
Beispiel #2
0
# Initialize Bytom wallet
wallet: Wallet = Wallet(network=NETWORK)
# Get Bytom wallet from mnemonic
wallet.from_entropy(entropy=ENTROPY)
# Derivation from default indexes
wallet.from_indexes(indexes=DEFAULT_INDEXES)

# Initialize normal transaction
unsigned_normal_transaction: NormalTransaction = NormalTransaction(
    network=NETWORK, vapor=VAPOR)

# Estimate transaction fee (returned NEU amount)
estimated_transaction_fee: int = estimate_transaction_fee(
    address=wallet.address(vapor=VAPOR),
    asset=ASSET,
    amount=amount_converter(0.1, "BTM2NEU"),
    confirmations=1,
    network=NETWORK,
    vapor=VAPOR)

print("Estimated Transaction Fee:", estimated_transaction_fee)

# Build normal transaction
unsigned_normal_transaction.build_transaction(
    address=wallet.address(vapor=VAPOR),
    recipients={
        "vp1q9ndylx02syfwd7npehfxz4lddhzqsve2za23ag":
        amount_converter(0.1, "BTM2NEU")
    },
    asset=ASSET,
    fee=estimated_transaction_fee,
Beispiel #3
0
VAPOR_P2WPKH_ADDRESS: str = "vp1q9ndylx02syfwd7npehfxz4lddhzqsve2za23ag"
# Vapor Pay to Witness Script Hash Address
VAPOR_P2WSH_ADDRESS: str = "vp1qf78sazxs539nmzztq7md63fk2x8lew6ed2gu5rnt9um7jerrh07qcyvk37"

# Check all addresses
assert is_address(address=P2WPKH_ADDRESS, network=NETWORK, vapor=False)
assert is_address(address=P2WSH_ADDRESS, network=NETWORK, vapor=False)
assert is_address(address=VAPOR_P2WPKH_ADDRESS, network=NETWORK, vapor=True)
assert is_address(address=VAPOR_P2WSH_ADDRESS, network=NETWORK, vapor=True)

# Get all address balances
print(
    "P2WPKH Address Balance:",
    amount_converter(amount=get_balance(address=P2WPKH_ADDRESS,
                                        asset=ASSET,
                                        network=NETWORK,
                                        vapor=False),
                     symbol="NEU2BTM"), "BTM")
print(
    "P2WSH Address Balance:",
    amount_converter(amount=get_balance(address=P2WSH_ADDRESS,
                                        asset=ASSET,
                                        network=NETWORK,
                                        vapor=False),
                     symbol="NEU2BTM"), "BTM")
print(
    "Vapor P2WPKH Address Balance:",
    amount_converter(amount=get_balance(address=VAPOR_P2WPKH_ADDRESS,
                                        asset=ASSET,
                                        network=NETWORK,
                                        vapor=True),
Beispiel #4
0
# print(json.dumps(wallet.dumps(), indent=4, ensure_ascii=False))

print("XPrivate Key:", wallet.xprivate_key())
print("Expand XPrivate Key:", wallet.expand_xprivate_key())
print("XPublic Key:", wallet.xpublic_key())
# print("GUID:", wallet.guid())
print("Indexes:", wallet.indexes())
print("Path:", wallet.path())
print("Child XPrivate Key:", wallet.child_xprivate_key())
print("Child XPublic Key:", wallet.child_xpublic_key())
print("Private Key:", wallet.private_key())
print("Public Key:", wallet.public_key())
print("Program:", wallet.program())
print("Address:", wallet.address(vapor=False))
print("Vapor Address:", wallet.address(vapor=True))
print("Balance:",
      amount_converter(wallet.balance(asset=ASSET, vapor=False), "NEU2BTM"),
      "BTM")
print("Vapor Balance:",
      amount_converter(wallet.balance(asset=ASSET, vapor=True), "NEU2BTM"),
      "BTM")
print("UTXO's:", wallet.utxos(asset=ASSET, vapor=False))
print("Vapor UTXO's:", wallet.utxos(asset=ASSET, vapor=True))

print("-------- Sign & Verify --------")

print("Message:", MESSAGE)
signature = wallet.sign(message=MESSAGE)
print("Signature:", signature)
print("Verified:", wallet.verify(message=MESSAGE, signature=signature))
# Initialize Bytom wallet
wallet: Wallet = Wallet(network=NETWORK)
# Get Bytom wallet from mnemonic
wallet.from_mnemonic(mnemonic=MNEMONIC)
# Derivation from path
wallet.from_path(path=DEFAULT_PATH)

# Initialize Bytom advanced transaction
unsigned_advanced_transaction: AdvancedTransaction = AdvancedTransaction(
    network=NETWORK, vapor=VAPOR)

# Estimate transaction fee (returned NEU amount)
estimated_transaction_fee: int = estimate_transaction_fee(
    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))
Beispiel #6
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"]
Beispiel #7
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"]