Пример #1
0
def accept_pending_delegation(skale, delegation_id):
    print(f'Accepting delegation with ID: {delegation_id}')
    tx_res = skale.delegation_service.accept_pending_delegation(
        delegation_id=delegation_id,
        wait_for=True
    )
    check_receipt(tx_res.receipt)
Пример #2
0
def skip_delegation_delay(skale, delegation_id):
    print(f'Activating delegation with ID {delegation_id}')
    tx_res = skale.token_state._skip_transition_delay(
        delegation_id,
        wait_for=True
    )
    check_receipt(tx_res.receipt)
Пример #3
0
def link_address_to_validator(skale):
    print('Linking address to validator')
    tx_res = skale.delegation_service.link_node_address(
        node_address=skale.wallet.address,
        wait_for=True
    )
    check_receipt(tx_res.receipt)
Пример #4
0
def remove(ctx, schain_name):
    """ Command that removes schain by name """
    # TODO: check if this function works
    skale = ctx.obj['skale']
    res = skale.manager.delete_schain(schain_name)
    receipt = wait_receipt(skale.web3, res['tx'])
    check_receipt(receipt)
    print(f'sChain {schain_name} removed!')
Пример #5
0
def remove(ctx, node_name):
    """ Command to remove node spcified by name """
    skale = ctx.obj['skale']

    node_id = skale.nodes_data.node_name_to_index(node_name)
    res = skale.manager.delete_node_by_root(node_id)

    receipt = wait_receipt(skale.web3, res['tx'])
    check_receipt(receipt)
Пример #6
0
def create(ctx, amount):
    """ Command to create given amount of nodes """
    skale = ctx.obj['skale']

    print(f'Creating {amount} nodes...')
    for i in range(int(amount)):
        print(LONG_LINE)
        print(f'Creating {i+1}/{amount} node...')
        receipt = create_node(skale)
        check_receipt(receipt)
Пример #7
0
def create_validator(skale):
    print('Creating default validator')
    tx_res = skale.delegation_service.register_validator(
        name=D_VALIDATOR_NAME,
        description=D_VALIDATOR_DESC,
        fee_rate=D_VALIDATOR_FEE,
        min_delegation_amount=D_VALIDATOR_MIN_DEL,
        wait_for=True
    )
    check_receipt(tx_res.receipt)
Пример #8
0
def delegate_to_validator(skale):
    print(f'Delegating tokens to validator ID: {D_VALIDATOR_ID}')
    tx_res = skale.delegation_service.delegate(
        validator_id=D_VALIDATOR_ID,
        amount=get_test_delegation_amount(skale),
        delegation_period=D_DELEGATION_PERIOD,
        info=D_DELEGATION_INFO,
        wait_for=True
    )
    check_receipt(tx_res.receipt)
Пример #9
0
def send_ether(web3, sender_wallet, receiver_account, amount, wait_for=True):
    logger.info(f'Sending {amount} ETH from {sender_wallet.address} => '
                f'{receiver_account}')

    wei_amount = web3.toWei(amount, 'ether')
    tx = send_eth(web3, receiver_account, wei_amount, sender_wallet)
    if wait_for:
        receipt = wait_for_receipt_by_blocks(web3, tx)
        check_receipt(receipt)
        return receipt
    else:  # pragma: no cover
        return tx
Пример #10
0
def send_tokens(skale, sender_wallet, receiver_account, amount, wait_for=True):
    logger.info(
        f'Sending {amount} SKALE tokens from {sender_wallet.address} => '
        f'{receiver_account}')

    wei_amount = skale.web3.toWei(amount, 'ether')
    res = skale.token.transfer(receiver_account, wei_amount)
    if wait_for:
        receipt = wait_for_receipt_by_blocks(skale.web3, res['tx'])
        check_receipt(receipt)
        return receipt
    else:  # pragma: no cover
        return res['tx']
Пример #11
0
def create_schain(skale):
    type_of_nodes, lifetime_seconds, old_name = generate_random_schain_data()
    schain_name = generate_random_schain_name()
    price_in_wei = skale.schains.get_schain_price(type_of_nodes,
                                                  lifetime_seconds)

    res = skale.manager.create_schain(lifetime_seconds, type_of_nodes,
                                      price_in_wei, schain_name)
    receipt = wait_receipt(skale.web3, res['tx'])
    check_receipt(receipt)

    schain_struct = skale.schains_data.get_by_name(schain_name)
    schain_nodes = get_nodes_for_schain_config(skale, schain_name)
    return {'schain_struct': schain_struct, 'schain_nodes': schain_nodes}
Пример #12
0
def token_transfer(skale, address_to, tokens_amount):
    address_from = Web3.toChecksumAddress(skale.wallet.address)
    address_to = Web3.toChecksumAddress(address_to)
    balance_from_before = skale.token.get_balance(address_from)
    balance_to_before = skale.token.get_balance(address_to)
    print('Balance from before {}'.format(balance_from_before))
    print('Balance to before {}'.format(balance_to_before))

    res = skale.token.transfer(address_to, tokens_amount)
    receipt = wait_receipt(skale.web3, res['tx'])
    check_receipt(receipt)

    balance_from_after = skale.token.get_balance(address_from)
    balance_to_after = skale.token.get_balance(address_to)
    print('Balance from after {}'.format(balance_from_after))
    print('Balance to after {}'.format(balance_to_after))
    diff_from = balance_from_before - balance_from_after
    diff_to = balance_to_after - balance_to_before
    assert diff_from == diff_to
    return receipt
Пример #13
0
def cancel_pending_delegation(delegation_id: int, pk_file: str) -> None:
    skale = init_skale_w_wallet_from_config(pk_file)
    if not skale:
        return
    with yaspin(text='Canceling delegation request', color=SPIN_COLOR) as sp:
        tx_res = skale.delegation_service.cancel_pending_delegation(
            delegation_id=delegation_id)
        receipt = wait_receipt(skale.web3, tx_res.hash)
        if not check_receipt(receipt, raise_error=False):
            sp.write(f'Transaction failed, check receipt: {tx_res.hash}')
            return
        sp.write("✔ Delegation request canceled")
Пример #14
0
def delegate(validator_id, amount, delegation_period, info, pk_file):
    skale = init_skale_w_wallet_from_config(pk_file)
    if not skale:
        return
    with yaspin(text='Sending delegation request', color=SPIN_COLOR) as sp:
        tx_res = skale.delegation_service.delegate(
            validator_id=validator_id,
            amount=amount,
            delegation_period=delegation_period,
            info=info)
        receipt = wait_receipt(skale.web3, tx_res.hash)
        if not check_receipt(receipt, raise_error=False):
            sp.write(f'Transaction failed, check receipt: {tx_res.hash}')
            return
        sp.write("✔ Delegation request sent")
Пример #15
0
def check_tx_result(tx_hash, web3):
    receipt = wait_receipt(web3, tx_hash)
    return check_receipt(receipt, raise_error=False)
Пример #16
0
def enable_validator(skale):
    print(f'Enabling validator ID: {D_VALIDATOR_ID}')
    tx_res = skale.validator_service._enable_validator(D_VALIDATOR_ID, wait_for=True)
    check_receipt(tx_res.receipt)