Beispiel #1
0
def get_last_block_nonce(args):
    proxy_url = args.proxy
    shard = args.shard
    proxy = ElrondProxy(proxy_url)
    nonce = proxy.get_last_block_nonce(shard)
    print(nonce)
    return nonce
Beispiel #2
0
def create_transaction(args: Any):
    args = utils.as_object(args)

    cli_shared.check_broadcast_args(args)
    cli_shared.prepare_nonce_in_args(args)

    if args.data_file:
        args.data = utils.read_file(args.data_file)

    tx = do_prepare_transaction(args)

    if hasattr(args, "relay") and args.relay:
        args.outfile.write(tx.serialize_as_inner())
        return

    send_wait_result = args.wait_result and args.send and not args.simulate
    send_only = args.send and not (args.wait_result or args.simulate)
    simulate = args.simulate and not (send_only or send_wait_result)

    try:
        if send_wait_result:
            proxy = ElrondProxy(args.proxy)
            response = tx.send_wait_result(proxy, args.timeout)
            utils.dump_out_json(response)
        elif send_only:
            tx.send(ElrondProxy(args.proxy))
        elif simulate:
            response = tx.simulate(ElrondProxy(args.proxy))
            utils.dump_out_json(response)
    finally:
        tx.dump_to(args.outfile)
def get_transaction(args: Any):
    args = utils.as_object(args)

    proxy = ElrondProxy(args.proxy)

    response = proxy.get_transaction(args.hash, args.sender)
    utils.dump_out_json(response)
Beispiel #4
0
def _send_or_simulate(tx: Transaction, args: Any):
    if args.send:
        tx.send(ElrondProxy(args.proxy))
        return None
    elif args.simulate:
        response = tx.simulate(ElrondProxy(args.proxy))
        return response
Beispiel #5
0
def get_account_transactions(args: Any):
    proxy_url = args.proxy
    address = args.address
    proxy = ElrondProxy(proxy_url)

    response = proxy.get_account_transactions(Address(address))
    utils.dump_out_json(response, args.outfile)
Beispiel #6
0
def get_transaction(args: Any):
    args = utils.as_object(args)
    omit_fields = cli_shared.parse_omit_fields_arg(args)

    proxy = ElrondProxy(args.proxy)

    transaction = proxy.get_transaction(args.hash, args.sender)
    utils.omit_fields(transaction, omit_fields)
    utils.dump_out_json(transaction)
Beispiel #7
0
def get_account(args: Any):
    proxy_url = args.proxy
    address = args.address
    proxy = ElrondProxy(proxy_url)
    account = proxy.get_account(Address(address))

    if args.balance:
        print(account.get("balance", 0))
    elif args.nonce:
        print(account.get("nonce", 0))
    else:
        print(account)
Beispiel #8
0
def get_account(args: Any):
    proxy_url = args.proxy
    address = args.address
    proxy = ElrondProxy(proxy_url)
    account = proxy.get_account(Address(address))
    omit_fields = cli_shared.parse_omit_fields_arg(args)

    if args.balance:
        print(account.get("balance", 0))
    elif args.nonce:
        print(account.get("nonce", 0))
    else:
        utils.omit_fields(account, omit_fields)
        utils.dump_out_json(account)
Beispiel #9
0
def _send_or_simulate(tx: Transaction, args: Any):
    send_wait_result = args.wait_result and args.send and not args.simulate
    send_only = args.send and not (args.wait_result or args.simulate)
    simulate = args.simulate and not (send_only or send_wait_result)

    if send_wait_result:
        proxy = ElrondProxy(args.proxy)
        response = tx.send_wait_result(proxy, args.timeout)
        return None
    elif send_only:
        tx.send(ElrondProxy(args.proxy))
        return None
    elif simulate:
        response = tx.simulate(ElrondProxy(args.proxy))
        return response
Beispiel #10
0
def main():
    logging.basicConfig(level=logging.DEBUG)

    parser = ArgumentParser()
    parser.add_argument("--proxy", default="https://testnet-api.elrond.com")
    parser.add_argument("--keyfile", help="wallet JSON keyfile", required=True)
    parser.add_argument("--passfile", help="wallet password file", required=True)
    parser.add_argument("--reward-address", required=True, help="the reward address")
    parser.add_argument("--validators-file", required=True, help="validators JSON file (with links to PEM files)")
    parser.add_argument("--value", required=True, help="the value to stake")
    args = parser.parse_args()
    args.estimate_gas = True
    args.pem = None

    proxy = ElrondProxy(args.proxy)
    network = proxy.get_network_config()
    args.chain = network.chain_id
    args.gas_price = network.min_gas_price
    args.version = network.min_tx_version

    print("Reward address:")
    print(Address(args.reward_address).bech32())
    confirm_continuation()

    prepare_args_for_stake(args)
    print("Transaction data:")
    print(args.data)
    confirm_continuation()

    print("Elrond Proxy (or Observer) address:", args.proxy)
    print("Chain ID:", args.chain)
    confirm_continuation()

    print("Value to stake:")
    print(int(args.value) / int(math.pow(10, 18)), "ERD")
    confirm_continuation()

    node_operator = Account(key_file=args.keyfile, pass_file=args.passfile)
    node_operator.sync_nonce(proxy)
    args.nonce = node_operator.nonce

    tx = do_prepare_transaction(args)
    tx.dump_to(sys.stdout)
    print("Transaction will now be sent.")
    confirm_continuation()

    tx.send(proxy)
    print("Done.")
Beispiel #11
0
def do_unjail(args: Any):
    cli_shared.prepare_nonce_in_args(args)
    args = validators.parse_args_for_un_jail(args)
    tx = do_prepare_transaction(args)

    try:
        tx.send(ElrondProxy(args.proxy))
    finally:
        tx.dump_to(args.outfile)
Beispiel #12
0
def change_reward_address(args: Any):
    cli_shared.prepare_nonce_in_args(args)
    args = validators.parse_args_for_changing_reward_address(args)
    tx = do_prepare_transaction(args)

    try:
        tx.send(ElrondProxy(args.proxy))
    finally:
        tx.dump_to(args.outfile)
Beispiel #13
0
def send_transaction(args: Any):
    args = utils.as_object(args)

    tx = Transaction.load_from_file(args.infile)

    try:
        tx.send(ElrondProxy(args.proxy))
    finally:
        tx.dump_to(args.outfile)
Beispiel #14
0
def query(args: Any):
    logger.debug("query")

    contract_address = args.contract
    function = args.function
    arguments = args.arguments

    contract = SmartContract(contract_address)
    result = contract.query(ElrondProxy(args.proxy), function, arguments)
    utils.dump_out_json(result)
Beispiel #15
0
def prepare_nonce_in_args(args: Any):
    if args.recall_nonce:
        if args.pem:
            account = Account(pem_file=args.pem, pem_index=args.pem_index)
        elif args.keyfile and args.passfile:
            account = Account(key_file=args.keyfile, pass_file=args.passfile)
        else:
            raise errors.NoWalletProvided()

        account.sync_nonce(ElrondProxy(args.proxy))
        args.nonce = account.nonce
Beispiel #16
0
def _prepare_sender(args: Any) -> Account:
    if args.pem:
        sender = Account(pem_file=args.pem, pem_index=args.pem_index)
    elif args.keyfile and args.passfile:
        sender = Account(key_file=args.keyfile, pass_file=args.passfile)
    else:
        raise errors.NoWalletProvided()

    sender.nonce = args.nonce
    if args.recall_nonce:
        sender.sync_nonce(ElrondProxy(args.proxy))

    return sender
Beispiel #17
0
def register(args: Any):
    args = utils.as_object(args)

    cli_shared.check_broadcast_args(args)
    cli_shared.prepare_nonce_in_args(args)
    args.receiver = dns_address_for_name(args.name).bech32()
    args.data = dns_register_data(args.name)

    tx = do_prepare_transaction(args)

    if hasattr(args, "relay") and args.relay:
        args.outfile.write(tx.serialize_as_inner())
        return

    try:
        if args.send:
            tx.send(ElrondProxy(args.proxy))
        elif args.simulate:
            response = tx.simulate(ElrondProxy(args.proxy))
            utils.dump_out_json(response)
    finally:
        tx.dump_to(args.outfile)
def create_transaction(args: Any):
    args = utils.as_object(args)

    cli_shared.check_broadcast_args(args)
    cli_shared.prepare_nonce_in_args(args)

    if args.data_file:
        args.data = utils.read_file(args.data_file)

    tx = do_prepare_transaction(args)

    if hasattr(args, "relay") and args.relay:
        args.outfile.write(tx.serialize_as_inner())
        return

    try:
        if args.send:
            tx.send(ElrondProxy(args.proxy))
        elif args.simulate:
            response = tx.simulate(ElrondProxy(args.proxy))
            utils.dump_out_json(response)
    finally:
        tx.dump_to(args.outfile)
Beispiel #19
0
def get_version(args: Any):
    proxy = ElrondProxy(args.proxy)
    if args.all:
        t = PrettyTable([
            'Shard ID', 'Contract address (bech32)', 'Contract address (hex)',
            'Version'
        ])
        for shard_id in range(0, 256):
            address = compute_dns_address_for_shard_id(shard_id)
            v = version(shard_id, proxy)
            t.add_row([shard_id, address, address.hex(), v])
        print(t)
    else:
        shard_id = int(args.shard_id)
        print(version(shard_id, proxy))
Beispiel #20
0
    def dispatch_transactions(self, args):
        data = self._read_json_file()
        txs = data[self._TXS_FIELD_NAME]
        txs_index = self._read_index()

        total_txs = len(txs) - txs_index
        if total_txs == 0 or len(txs) == 0:
            logger.info("No transactions to dispatch")
            return

        proxy = ElrondProxy(args.proxy)
        # Need to sync nonce
        if args.pem:
            owner = Account(pem_file=args.pem)
        elif args.keyfile and args.passfile:
            owner = Account(key_file=args.keyfile, pass_file=args.passfile)

        owner.sync_nonce(proxy)
        nonce = owner.nonce
        old_nonce = nonce

        print(nonce)
        bunch = BunchOfTransactions()
        idx = txs_index
        while idx < len(txs):
            tx = txs[idx]
            # TODO CHECK IF BUNCH OF TRANSACTION generate transactions with chain id and version
            bunch.add(owner, tx.get("receiver"), nonce, tx.get("value"),
                      tx.get("data"), tx.get("gasPrice"), tx.get("gasLimit"))
            # increment nonce
            nonce += 1
            idx += 1

        logger.info(f"Sending {total_txs} transactions")
        try:
            num_sent, hashes = bunch.send(proxy)
        except Exception:
            logger.error("No valid transactions to send")
            num_sent = 0
            hashes = []

        logger.info(f"{num_sent} transactions were accepted by observers")
        for key in hashes:
            print(f"tx {txs_index+int(key)}: hash => {hashes[key]}")

        utils.write_file(self.txs_info_file_path, f"index:{len(txs)}")
        # wait until transactions are executed
        _wait_to_execute_txs(proxy, owner, old_nonce + num_sent)
Beispiel #21
0
def get_gas_price(args: Any) -> Any:
    proxy_url = args.proxy
    proxy = ElrondProxy(proxy_url)
    price = proxy.get_gas_price()
    print(price)
    return price
Beispiel #22
0
def get_registration_cost(args: Any):
    print(registration_cost(args.shard_id, ElrondProxy(args.proxy)))
Beispiel #23
0
def dns_validate_name(args: Any):
    validate_name(args.name, args.shard_id, ElrondProxy(args.proxy))
Beispiel #24
0
def dns_resolve(args: Any):
    addr = resolve(args.name, ElrondProxy(args.proxy))
    if addr.hex() != Address.zero().hex():
        print(addr.bech32())
Beispiel #25
0
logger = logging.getLogger("examples")

if __name__ == '__main__':
    parser = ArgumentParser()
    parser.add_argument("--proxy",
                        help="testnet Proxy URL",
                        default=config.get_proxy())
    parser.add_argument("--contract", help="existing contract address")
    parser.add_argument("--pem", help="PEM file", required=True)
    args = parser.parse_args()

    logging.basicConfig(level=logging.DEBUG)

    # Now, we create a environment which intermediates deployment and execution
    proxy = ElrondProxy(args.proxy)
    environment = TestnetEnvironment(args.proxy)
    user = Account(pem_file=args.pem)

    # We initialize the smart contract with an actual address if IF was previously deployed,
    contract = SmartContract(address=args.contract,
                             metadata=CodeMetadata(upgradeable=True))

    # A flow defines the desired steps to interact with the contract.
    def deploy_flow():
        global contract

        project = ProjectClang(input("Path to contract project: "))
        contract.bytecode = project.get_bytecode()

        user.sync_nonce(proxy)
Beispiel #26
0
def get_version(args: Any):
    print(version(args.shard_id, ElrondProxy(args.proxy)))
 def __init__(self):
     self.CLIENT = proxy = ElrondProxy(Config.PROXY)
Beispiel #28
0
def send_or_simulate(tx: Transaction, args: Any):
    if args.send:
        tx.send(ElrondProxy(args.proxy))
    elif args.simulate:
        response = tx.simulate(ElrondProxy(args.proxy))
        utils.dump_out_json(response)
Beispiel #29
0
def get_chain_id(args):
    proxy_url = args.proxy
    proxy = ElrondProxy(proxy_url)
    chain_id = proxy.get_chain_id()
    print(chain_id)
    return chain_id
Beispiel #30
0
def get_num_shards(args):
    proxy_url = args.proxy
    proxy = ElrondProxy(proxy_url)
    num_shards = proxy.get_num_shards()
    print(num_shards)
    return num_shards