예제 #1
0
def test_normal_transaction():

    wallet: Wallet = Wallet(provider=HTTP_PROVIDER).from_entropy(
        entropy=_["wallet"]["entropy"],
        passphrase=_["wallet"]["passphrase"],
        language=_["wallet"]["language"]).from_path(path=_["wallet"]["path"])

    normal_transaction: NormalTransaction = NormalTransaction(
        provider=HTTP_PROVIDER)

    normal_transaction.build_transaction(
        address=wallet.address(prefix="xdc"),
        recipient="xdc9Cd6fD3519b259B251d881361CAae6BABdC5910b",
        value=amount_unit_converter(amount=0.1, unit="XDC2Wei"))

    normal_transaction.sign_transaction(
        root_xprivate_key=_["wallet"]["root_xprivate_key"],
        path=_["wallet"]["path"])

    assert normal_transaction.fee(
    ) == _["transaction"]["normal_transaction"]["fee"]
    assert normal_transaction.hash(
    ) == _["transaction"]["normal_transaction"]["hash"]
    assert normal_transaction.raw(
    ) == _["transaction"]["normal_transaction"]["raw"]
    assert normal_transaction.json(
    ) == _["transaction"]["normal_transaction"]["json"]
예제 #2
0
def test_contract_transaction():

    wallet: Wallet = Wallet(provider=HTTP_PROVIDER).from_entropy(
        entropy=_["wallet"]["entropy"],
        passphrase=_["wallet"]["passphrase"],
        language=_["wallet"]["language"]).from_path(path=_["wallet"]["path"])

    contract_transaction: ContractTransaction = ContractTransaction(
        provider=HTTP_PROVIDER)

    contract_transaction.build_transaction(
        address=wallet.address(prefix="xdc"),
        abi=ABI,
        bytecode=BYTECODE,
        value=amount_unit_converter(amount=0, unit="XDC2Wei"),
        estimate_gas=True)

    contract_transaction.sign_transaction(
        private_key=_["wallet"]["private_key"])

    assert contract_transaction.fee(
    ) == _["transaction"]["contract_transaction"]["fee"]
    assert contract_transaction.hash(
    ) == _["transaction"]["contract_transaction"]["hash"]
    assert contract_transaction.raw(
    ) == _["transaction"]["contract_transaction"]["raw"]
    assert contract_transaction.json(
    ) == _["transaction"]["contract_transaction"]["json"]
예제 #3
0
# Print all XinFin Wallet information's
# print(json.dumps(wallet.dumps(), indent=4, ensure_ascii=False))

print("Seed:", wallet.seed())
print("Root XPrivate Key:", wallet.root_xprivate_key())
print("Root XPublic Key:", wallet.root_xpublic_key())
print("XPrivate Key:", wallet.xprivate_key())
print("XPublic Key:", wallet.xpublic_key())
print("Uncompressed:", wallet.uncompressed())
print("Compressed:", wallet.compressed())
print("Chain Code:", wallet.chain_code())
print("Private Key:", wallet.private_key())
print("Public Key:", wallet.public_key())
print("Wallet Important Format:", wallet.wif())
print("Finger Print:", wallet.finger_print())
print("Semantic:", wallet.semantic())
print("Path:", wallet.path())
print("Hash:", wallet.hash())
print("Address:", wallet.address())
print("Balance:", amount_unit_converter(amount=wallet.balance(), unit="Wei2XDC"), "XDC")

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

MESSAGE_HASH: str = "34482808c8f9e9c78b9ba295438160cc5f1cc24d5bfd992aaef0602319cb379b"

print("Message Hash:", MESSAGE_HASH)
signature: str = wallet.sign(message_hash=MESSAGE_HASH)
print("Signature:", signature)
print("Verified:", wallet.verify(signature=signature, message_hash=MESSAGE_HASH))
예제 #4
0
# !/usr/bin/env python3

from pyxdc.utils import amount_unit_converter

print(amount_unit_converter(amount=0.25, unit="Gwei2Wei"), "Wei")
print(amount_unit_converter(amount=25_000_000_000, unit="Gwei2XDC"), "XDC")

print(amount_unit_converter(amount=25, unit="XDC2Wei"), "Wei")
print(amount_unit_converter(amount=25, unit="XDC2Gwei"), "Gwei")

print(amount_unit_converter(amount=25_000_000_000_000_000_000, unit="Wei2Gwei"), "Gwei")
print(amount_unit_converter(amount=25_000_000_000_000_000_000, unit="Wei2XDC"), "XDC")

예제 #5
0
#!/usr/bin/env python3

from pyxdc import (
    HTTP_PROVIDER, DEFAULT_PATH
)
from pyxdc.transaction import ContractTransaction
from pyxdc.utils import amount_unit_converter
from pyxdc.rpc import submit_transaction_raw
from pyxdc.wallet import Wallet

import json

# Wallet entropy hex string
ENTROPY: str = "92e6d1f7aa93ae88c432b57ef63aaf5f"
# Value for contract (Wei unit)
VALUE: int = amount_unit_converter(amount=0, unit="XDC2Wei")
# Contract bytecode
BYTECODE: str = "608060405234801561001057600080fd5b506040518060400160405280600581526020017f48656c6c6f00000000000" \
                "00000000000000000000000000000000000000000008152506000908051906020019061005c929190610062565b5061" \
                "0166565b82805461006e90610105565b90600052602060002090601f01602090048101928261009057600085556100d" \
                "7565b82601f106100a957805160ff19168380011785556100d7565b828001600101855582156100d7579182015b8281" \
                "11156100d65782518255916020019190600101906100bb565b5b5090506100e491906100e8565b5090565b5b8082111" \
                "56101015760008160009055506001016100e9565b5090565b6000600282049050600182168061011d57607f82169150" \
                "5b6020821081141561013157610130610137565b5b50919050565b7f4e487b710000000000000000000000000000000" \
                "0000000000000000000000000600052602260045260246000fd5b61053b806101756000396000f3fe60806040523480" \
                "1561001057600080fd5b50600436106100415760003560e01c8063a413686214610046578063cfae321714610062578" \
                "063ef690cc014610080575b600080fd5b610060600480360381019061005b91906102e3565b61009e565b005b61006a" \
                "6100b8565b604051610077919061035d565b60405180910390f35b61008861014a565b604051610095919061035d565" \
                "b60405180910390f35b80600090805190602001906100b49291906101d8565b5050565b6060600080546100c7906104" \
                "33565b80601f01602080910402602001604051908101604052809291908181526020018280546100f390610433565b8" \
                "0156101405780601f1061011557610100808354040283529160200191610140565b820191906000526020600020905b" \
예제 #6
0
#!/usr/bin/env python3

from pyxdc import HTTP_PROVIDER
from pyxdc.rpc import get_balance
from pyxdc.utils import (is_address, amount_unit_converter)

# XinFin mainnet address
ADDRESS_XDC: str = "xdc571ae1504e92fa40f85359efdb188c704a224eac"
# Ethereum mainnet address
ADDRESS_0X: str = "0x571ae1504e92fa40f85359efdb188c704a224eac"

# Check all addresses
assert is_address(address=ADDRESS_XDC)
assert is_address(address=ADDRESS_0X)

# Get all address balances
print(
    "XDC Address Balance:",
    amount_unit_converter(amount=get_balance(address=ADDRESS_XDC,
                                             provider=HTTP_PROVIDER),
                          unit="Wei2XDC"), "XDC")

print(
    "0x Address Balance:",
    amount_unit_converter(amount=get_balance(address=ADDRESS_0X,
                                             provider=HTTP_PROVIDER),
                          unit="Wei2XDC"), "XDC")