Пример #1
0
def main():
    parser = ArgumentParser()
    parser.add_argument("--proxy", required=True)
    parser.add_argument("--minter", required=True)
    parser.add_argument("--minted-value",
                        required=False,
                        type=int,
                        default=MINTED_VALUE)
    parser.add_argument("--minted-folder", required=True)
    parser.add_argument("--minted-count", required=False, type=int)
    args = parser.parse_args()

    logging.basicConfig(level=logging.DEBUG)

    proxy = ElrondProxy(args.proxy)
    bunch = BunchOfTransactions()
    minter = Account(pem_file=args.minter)
    minted_repository = AccountsRepository(args.minted_folder)

    if args.minted_count:
        minted_repository.generate_accounts(args.minted_count)

    minter.sync_nonce(proxy)
    nonce = minter.nonce
    value = args.minted_value
    for minted in minted_repository.get_all():
        bunch.add(minter, minted.address.bech32(), nonce, value, "", GAS_PRICE,
                  GAS_LIMIT)
        nonce += 1

    bunch.send(proxy)
Пример #2
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
Пример #3
0
def prepare_and_send_transaction(args):
    proxy = ElrondProxy(args.proxy)

    # Need to sync nonce
    owner = Account(pem_file=args.pem)
    owner.sync_nonce(proxy)
    args.nonce = owner.nonce

    prepared = do_prepare_transaction(args)
    tx_hash = prepared.send(proxy)
    print(tx_hash)
    return tx_hash
Пример #4
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
Пример #5
0
def main():
    pem_file_name = "walletKey.pem"
    pem_path = "~/Elrond/testnet/filegen/output"

    pem_file = path.join(pem_path, pem_file_name)

    parser = ArgumentParser()
    parser.add_argument("--proxy", default="http://localhost:7950")
    args = parser.parse_args()

    shard0_index = get_index_by_shard_id(pem_file, 0)
    shard1_index = get_index_by_shard_id(pem_file, 1)

    logging.basicConfig(level=logging.DEBUG)

    proxy = ElrondProxy(args.proxy)
    network = proxy.get_network_config()

    alice = Account(pem_file=pem_file, pem_index=shard0_index)
    bob = Account(pem_file=pem_file, pem_index=shard1_index)

    bob.sync_nonce(proxy)

    innerTx = Transaction()
    innerTx.nonce = bob.nonce
    innerTx.value = "0"
    innerTx.sender = bob.address.bech32()
    innerTx.receiver = "erd1qqqqqqqqqqqqqpgqrchxzx5uu8sv3ceg8nx8cxc0gesezure5awqn46gtd"  # shard 2 address
    innerTx.gasPrice = 1000000000
    innerTx.gasLimit = 500000000
    innerTx.chainID = network.chain_id
    innerTx.version = network.min_tx_version
    innerTx.data = "version"
    innerTx.sign(bob)

    alice.sync_nonce(proxy)

    wrapperTx = Transaction()
    wrapperTx.nonce = alice.nonce
    wrapperTx.value = "0"
    wrapperTx.sender = alice.address.bech32()
    wrapperTx.receiver = bob.address.bech32()
    wrapperTx.gasPrice = 1000000000
    wrapperTx.gasLimit = 501109000
    wrapperTx.chainID = network.chain_id
    wrapperTx.version = network.min_tx_version
    wrapperTx.wrap_inner(innerTx)
    wrapperTx.sign(alice)

    wrapperTx.send(proxy)
Пример #6
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)
Пример #7
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.")
Пример #8
0
def main():
    parser = ArgumentParser()
    parser.add_argument("--proxy",
                        default="https://testnet-gateway.elrond.com")
    parser.add_argument("--pem", required=True)
    parser.add_argument(
        "--batch-size",
        type=int,
        default=50,
        help="how many transactions to send before recalling nonce")
    parser.add_argument(
        "--sleep-before-recall",
        type=int,
        default=15,
        help="how many seconds to sleep before recalling nonce")
    parser.add_argument(
        "--sleep-after-tx",
        required=True,
        help="how many seconds to sleep after sending a transaction")
    args = parser.parse_args()

    logging.basicConfig(level=logging.WARNING)

    print("Press CTRL+C to stop the script execution")

    proxy = ElrondProxy(args.proxy)
    sender = Account(pem_file=args.pem)
    batch_size = int(args.batch_size)
    sleep_after_tx = int(args.sleep_after_tx)
    sleep_before_recall = int(args.sleep_before_recall)

    while True:
        print(
            f"Sleeping {sleep_before_recall} seconds before recalling nonce and sending {batch_size} transactions..."
        )
        time.sleep(sleep_before_recall)

        try:
            sender.sync_nonce(proxy)
            print(f"Sender nonce recalled: nonce={sender.nonce}.")
            send_txs(proxy, sender, batch_size, sleep_after_tx)
        except errors.ProxyRequestError as err:
            logger.error(err)
Пример #9
0
def main():
    logging.basicConfig(level=logging.WARNING)

    parser = ArgumentParser()
    parser.add_argument("--proxy", default="http://myproxy:8079")
    parser.add_argument("--pem", required=True)
    args = parser.parse_args()

    items = payload.splitlines()
    items = [item.strip() for item in items if item]
    items = [parse_item(item) for item in items]

    print(len(items))

    proxy = ElrondProxy(args.proxy)
    sender = Account(pem_file=args.pem)
    sender.sync_nonce(proxy)

    bunch = BunchOfTransactions()
    chain_id = "1"
    tx_version = 1
    data = "foobar"
    gas_limit = 50000 + len(data) * 1500

    cost = 0

    for address, value in items:
        print(address, value)
        bunch.add(sender, address.bech32(), sender.nonce, str(value), data,
                  GAS_PRICE, gas_limit, chain_id, tx_version)
        sender.nonce += 1

        cost += value
        cost += gas_limit * GAS_PRICE

    print("Cost", cost)
    num_txs, _ = bunch.send(proxy)
    print("Sent", num_txs)
Пример #10
0
def main():
    parser = ArgumentParser()
    parser.add_argument("--proxy", default="https://api.elrond.com")
    parser.add_argument("--pem", required=True)
    args = parser.parse_args()

    logging.basicConfig(level=logging.WARNING)

    print("Press CTRL+C to stop the script execution")

    proxy = ElrondProxy(args.proxy)
    sender = Account(pem_file=args.pem)

    while True:
        sleep_time = 15
        print(f"Sleeping {sleep_time} seconds...")
        time.sleep(sleep_time)

        try:
            sender.sync_nonce(proxy)
            print(f"Sender nonce recalled: nonce={sender.nonce}.")
            send_txs(proxy, sender, 100)
        except errors.ProxyRequestError as err:
            logger.error(err)
Пример #11
0
    def get_sum_flow():
        answer = environment.query_contract(contract, "getSum")
        logger.info(f"Answer: {answer}")

    def add_flow(number):
        environment.execute_contract(contract=contract,
                                     caller=user,
                                     function="add",
                                     arguments=[number],
                                     gas_price=gas_price,
                                     gas_limit=50000000,
                                     value=None,
                                     chain=chain,
                                     version=tx_version)

    user.sync_nonce(ElrondProxy(args.proxy))

    while True:
        print("Let's run a flow.")
        print("1. Deploy")
        print("2. Query getSum()")
        print("3. Add()")

        try:
            choice = int(input("Choose:\n"))
        except Exception:
            break

        if choice == 1:
            environment.run_flow(deploy_flow)
            user.nonce += 1