コード例 #1
0
def test_xinfin_xrc20_htlc():

    xrc20_htlc = HTLC(network=_["xinfin"]["network"], xrc20=True).build_htlc(
        secret_hash=_["xinfin"]["xrc20_htlc"]["secret"]["hash"],
        recipient_address=_["xinfin"]["wallet"]["recipient"]["address"],
        sender_address=_["xinfin"]["wallet"]["sender"]["address"],
        endtime=_["xinfin"]["xrc20_htlc"]["endtime"],
        token_address=_["xinfin"]["xrc20_htlc"]["agreements"]["token_address"])

    assert xrc20_htlc.abi() == _["xinfin"]["xrc20_htlc"]["abi"]
    assert xrc20_htlc.bytecode() == _["xinfin"]["xrc20_htlc"]["bytecode"]
    assert xrc20_htlc.bytecode_runtime(
    ) == _["xinfin"]["xrc20_htlc"]["bytecode_runtime"]
    assert xrc20_htlc.opcode() == _["xinfin"]["xrc20_htlc"]["opcode"]
    assert xrc20_htlc.contract_address(
    ) == _["xinfin"]["xrc20_htlc"]["contract_address"]
    assert xrc20_htlc.agreements["secret_hash"] == _["xinfin"]["xrc20_htlc"][
        "agreements"]["secret_hash"]
    assert xrc20_htlc.agreements["recipient_address"] == _["xinfin"][
        "xrc20_htlc"]["agreements"]["recipient_address"]
    assert xrc20_htlc.agreements["sender_address"] == _["xinfin"][
        "xrc20_htlc"]["agreements"]["sender_address"]
    # assert xrc20_htlc.agreements["endtime"]["datetime"] == _["xinfin"]["xrc20_htlc"]["agreements"]["endtime"]["datetime"]
    assert xrc20_htlc.agreements["endtime"]["timestamp"] == _["xinfin"][
        "xrc20_htlc"]["agreements"]["endtime"]["timestamp"]
    assert xrc20_htlc.agreements["token_address"] == _["xinfin"]["xrc20_htlc"][
        "agreements"]["token_address"]
コード例 #2
0
def test_xinfin_xrc20_fund_transaction():

    xrc20_htlc = HTLC(
        contract_address=_["xinfin"]["xrc20_htlc"]["contract_address"],
        network=_["xinfin"]["network"],
        xrc20=True).build_htlc(
            secret_hash=_["xinfin"]["xrc20_htlc"]["secret"]["hash"],
            recipient_address=_["xinfin"]["wallet"]["recipient"]["address"],
            sender_address=_["xinfin"]["wallet"]["sender"]["address"],
            endtime=get_current_timestamp(plus=3600),
            token_address=_["xinfin"]["xrc20_htlc"]["agreements"]
            ["token_address"])

    unsigned_xrc20_fund_transaction = FundTransaction(
        network=_["xinfin"]["network"], xrc20=True)

    unsigned_xrc20_fund_transaction.build_transaction(
        address=_["xinfin"]["wallet"]["sender"]["address"],
        htlc=xrc20_htlc,
        amount=_["xinfin"]["xrc20_amount"] * (10**_["xinfin"]["decimals"]))

    assert unsigned_xrc20_fund_transaction.type(
    ) == _["xinfin"]["xrc20_fund"]["unsigned"]["type"]
    assert unsigned_xrc20_fund_transaction.fee(
    ) == _["xinfin"]["xrc20_fund"]["unsigned"]["fee"]
    assert unsigned_xrc20_fund_transaction.hash(
    ) == _["xinfin"]["xrc20_fund"]["unsigned"]["hash"]
    assert unsigned_xrc20_fund_transaction.raw(
    ) == _["xinfin"]["xrc20_fund"]["unsigned"]["raw"]
    assert isinstance(unsigned_xrc20_fund_transaction.json(), dict)
    assert unsigned_xrc20_fund_transaction.signature(
    ) == _["xinfin"]["xrc20_fund"]["unsigned"]["signature"]
    assert isinstance(unsigned_xrc20_fund_transaction.transaction_raw(), str)

    signed_xrc20_fund_transaction = unsigned_xrc20_fund_transaction.sign(
        solver=FundSolver(
            xprivate_key=_["xinfin"]["wallet"]["sender"]["root_xprivate_key"],
            path=_["xinfin"]["wallet"]["sender"]["derivation"]["path"],
            account=_["xinfin"]["wallet"]["sender"]["derivation"]["account"],
            change=_["xinfin"]["wallet"]["sender"]["derivation"]["change"],
            address=_["xinfin"]["wallet"]["sender"]["derivation"]["address"]))

    assert signed_xrc20_fund_transaction.type(
    ) == _["xinfin"]["xrc20_fund"]["signed"]["type"]
    assert signed_xrc20_fund_transaction.fee(
    ) == _["xinfin"]["xrc20_fund"]["signed"]["fee"]
    assert isinstance(signed_xrc20_fund_transaction.hash(), str)
    assert isinstance(signed_xrc20_fund_transaction.raw(), str)
    assert isinstance(signed_xrc20_fund_transaction.json(), dict)
    assert isinstance(signed_xrc20_fund_transaction.signature(), dict)
    assert isinstance(signed_xrc20_fund_transaction.transaction_raw(), str)
コード例 #3
0
ファイル: fund.py プロジェクト: saloppe73/swap
sender_wallet.from_path(path=DEFAULT_PATH)

# Print some XinFin sender wallet info's
print("Root XPrivate Key:", sender_wallet.root_xprivate_key())
print("Root XPublic Key:", sender_wallet.root_xpublic_key())
print("Private Key:", sender_wallet.private_key())
print("Public Key:", sender_wallet.public_key())
print("Path:", sender_wallet.path())
print("Address:", sender_wallet.address())
print("Balance:", sender_wallet.balance(unit="XDC"), "XDC")

print("=" * 10, "Build Hash Time Lock Contract (HTLC) between Sender and Recipient")

# Initialize XinFin HTLC
htlc: HTLC = HTLC(
    contract_address=CONTRACT_ADDRESS, network=NETWORK
)
# Build HTLC contract
htlc.build_htlc(
    secret_hash=SECRET_HASH,
    recipient_address=RECIPIENT_ADDRESS,
    sender_address=sender_wallet.address(),
    endtime=ENDTIME
)

# Print all XinFin HTLC info's
print("HTLC Agreements:", json.dumps(htlc.agreements, indent=4))
print("HTLC ABI:", htlc.abi())
print("HTLC Bytecode:", htlc.bytecode())
print("HTLC Bytecode Runtime:", htlc.bytecode_runtime())
print("HTLC OP_Code:", htlc.opcode())
コード例 #4
0
ファイル: deploy_htlc.py プロジェクト: saloppe73/swap
print("=" * 10, "Deploy HTLC from XinFin Account")

# Initialize XinFin wallet
wallet: Wallet = Wallet(network=NETWORK)
# Get XinFin wallet from private key
wallet.from_private_key(private_key=PRIVATE_KEY)

print("Private Key:", wallet.private_key())
print("Public Key:", wallet.public_key())
print("Address:", wallet.address())
print("Balance:", wallet.balance(unit="XDC"), "XDC")

print("=" * 10, "Compile Hash Time Lock Contract (HTLC) Smart contract")

# Initialize XinFin HTLC
htlc: HTLC = HTLC(network=NETWORK)

print("HTLC ABI:", htlc.abi())
print("HTLC Bytecode:", htlc.bytecode())
print("HTLC Bytecode Runtime:", htlc.bytecode_runtime())
print("HTLC OP_Code:", htlc.opcode())

print("=" * 10, "Build, Sign and Submit HTLC Transaction")

# Build HTLC transaction
htlc.build_transaction(address=wallet.address())

# Sign HTLC transaction
htlc.sign_transaction(private_key=wallet.private_key())

# Submit HTLC transaction raw
コード例 #5
0
ファイル: fund.py プロジェクト: movnetwork/swap
print("Root XPublic Key:", sender_wallet.root_xpublic_key())
print("Private Key:", sender_wallet.private_key())
print("Public Key:", sender_wallet.public_key())
print("Path:", sender_wallet.path())
print("Address:", sender_wallet.address())
print("Balance:", sender_wallet.balance(unit="XDC"), "XDC")
print("XRC20 Balance:",
      sender_wallet.xrc20_balance(token_address=TOKEN_ADDRESS))

print(
    "=" * 10,
    "Build Hash Time Lock Contract (HTLC) XRC20 between Sender and Recipient")

# Initialize XinFin HTLC XRC20 contract
htlc_xrc20: HTLC = HTLC(contract_address=CONTRACT_ADDRESS,
                        network=NETWORK,
                        xrc20=XRC20)
# Build HTLC XRC20 contract
htlc_xrc20.build_htlc(secret_hash=SECRET_HASH,
                      recipient_address=RECIPIENT_ADDRESS,
                      sender_address=sender_wallet.address(),
                      endtime=ENDTIME,
                      token_address=TOKEN_ADDRESS)

# Print all XinFin HTLC XRC20 info's
print("HTLC XRC20 Agreements:", json.dumps(htlc_xrc20.agreements, indent=4))
print("HTLC XRC20 ABI:", htlc_xrc20.abi())
print("HTLC XRC20 Bytecode:", htlc_xrc20.bytecode())
print("HTLC XRC20 Bytecode Runtime:", htlc_xrc20.bytecode_runtime())
print("HTLC XRC20 OP_Code:", htlc_xrc20.opcode())
print("HTLC XRC20 Contract Address:", htlc_xrc20.contract_address())
コード例 #6
0
print("=" * 10, "Deploy new HTLC XRC20 Contract from XinFin Account")

# Initialize XinFin wallet
wallet: Wallet = Wallet(network=NETWORK)
# Get XinFin wallet from private key
wallet.from_private_key(private_key=PRIVATE_KEY)

print("Private Key:", wallet.private_key())
print("Public Key:", wallet.public_key())
print("Address:", wallet.address())
print("Balance:", wallet.balance(unit="XDC"), "XDC")

print("=" * 10, "Compile Hash Time Lock Contract (HTLC) XRC20 Smart contract")

# Initialize XinFin HTLC XRC20
htlc_xrc20: HTLC = HTLC(network=NETWORK, xrc20=XRC20)

print("HTLC XRC20 ABI:", htlc_xrc20.abi())
print("HTLC XRC20 Bytecode:", htlc_xrc20.bytecode())
print("HTLC XRC20 Bytecode Runtime:", htlc_xrc20.bytecode_runtime())
print("HTLC XRC20 OP_Code:", htlc_xrc20.opcode())

print("=" * 10, "Build and Sign HTLC XRC20 Transaction")

# Build HTLC XRC20 transaction
htlc_xrc20.build_transaction(address=wallet.address())

# Sign HTLC XRC20 transaction
htlc_xrc20.sign_transaction(private_key=wallet.private_key())

print("HTLC XRC20 Transaction Fee:", htlc_xrc20.fee(unit="Wei"), "Wei")