Пример #1
0
    def deploy_then_add_flow():
        global contract

        # For deploy, we initialize the smart contract with the compiled bytecode
        contract = SmartContract(bytecode=bytecode)
        user.sync_nonce(ElrondProxy(args.proxy))

        tx, address = environment.deploy_contract(
            contract=contract,
            owner=user,
            arguments=["0x0064"],
            gas_price=config.DEFAULT_GAS_PRICE,
            gas_limit=50000000,
            value=None,
            chain=config.get_chain_id(),
            version=config.get_tx_version())

        logger.info("Tx hash: %s", tx)
        logger.info("Contract address: %s", address.bech32())

        # We increment our copy of the nonce
        user.nonce += 1
        environment.execute_contract(contract=contract,
                                     caller=user,
                                     function="add",
                                     arguments=["0x0064"],
                                     gas_price=config.DEFAULT_GAS_PRICE,
                                     gas_limit=50000000,
                                     value=None,
                                     chain=config.get_chain_id(),
                                     version=config.get_tx_version())
Пример #2
0
    def execute(self,
                data,
                _sender=None,
                value="0",
                receiver=NFT_CONTRACT,
                gasLimit=60000000):
        if _sender is None: _sender = self._sender
        _sender.sync_nonce(self._proxy)

        t = Transaction()
        t.nonce = _sender.nonce
        t.version = get_tx_version()
        t.data = data
        t.receiver = receiver
        t.chainID = self._proxy.get_chain_id()
        t.gasLimit = gasLimit
        t.value = value
        t.sender = self._sender.address.bech32()
        t.gasPrice = DEFAULT_GAS_PRICE
        t.sign(self._sender)

        log("Execution d'une transaction sur " + BC_EXPLORER + "/address/" +
            t.sender)
        rc = t.send_wait_result(self._proxy, 60000)

        for r in rc["smartContractResults"]:
            if "data" in r:
                r["result"] = list()
                for p in r["data"].split("@"):
                    if len(p) > 0:
                        r["result"].append(hex_to_str(int(p, 16)))

        return rc["smartContractResults"]
Пример #3
0
def send_txs(proxy: ElrondProxy, sender: Account, num: int, sleep_after: int):
    print(
        f"Will send {num} transactions in bulk ({int(num / 2)} for each destination address). Will also sleep {sleep_after} seconds after each bulk."
    )

    bunch = BunchOfTransactions()
    chain_id = config.get_chain_id()
    tx_version = config.get_tx_version()

    for _ in range(0, int(num / 2)):
        bunch.add(
            sender,
            "erd1hqplnafrhnd4zv846wumat2462jy9jkmwxtp3nwmw8ye9eclr6fq40f044",
            sender.nonce, VALUE, "", GAS_PRICE, GAS_LIMIT, chain_id,
            tx_version)
        sender.nonce += 1
        bunch.add(
            sender,
            "erd1utftdvycwgl3xt0r44ekncentlxgmhucxfq3jt6cjz0w7h6qjchsjarml6",
            sender.nonce, VALUE, "", GAS_PRICE, GAS_LIMIT, chain_id,
            tx_version)
        sender.nonce += 1

    num_sent, _ = bunch.send(proxy)
    global counter
    counter += num_sent
    print(f"Sent {num_sent} transactions. Total: {counter}.")

    time.sleep(sleep_after)
Пример #4
0
def add_tx_args(sub: Any,
                with_nonce: bool = True,
                with_receiver: bool = True,
                with_data: bool = True,
                with_estimate_gas: bool = False):
    if with_nonce:
        sub.add_argument("--nonce",
                         type=int,
                         required=not ("--recall-nonce" in sys.argv),
                         help="# the nonce for the transaction")
        sub.add_argument(
            "--recall-nonce",
            action="store_true",
            default=False,
            help=
            "â­® whether to recall the nonce when creating the transaction (default: %(default)s)"
        )

    if with_receiver:
        sub.add_argument("--receiver",
                         required=True,
                         help="🖄 the address of the receiver")

    sub.add_argument("--gas-price",
                     default=config.DEFAULT_GAS_PRICE,
                     help="⛽ the gas price (default: %(default)d)")
    sub.add_argument("--gas-limit",
                     required=not ("--estimate-gas" in sys.argv),
                     help="⛽ the gas limit")
    if with_estimate_gas:
        sub.add_argument(
            "--estimate-gas",
            action="store_true",
            default=False,
            help="⛽ whether to estimate the gas limit (default: %(default)d)"
        )

    sub.add_argument("--value",
                     default="0",
                     help="the value to transfer (default: %(default)s)")

    if with_data:
        sub.add_argument(
            "--data",
            default="",
            help=
            "the payload, or 'memo' of the transaction (default: %(default)s)")

    sub.add_argument("--chain",
                     default=config.get_chain_id(),
                     help="the chain identifier (default: %(default)s)")
    sub.add_argument("--version",
                     type=int,
                     default=config.get_tx_version(),
                     help="the transaction version (default: %(default)s)")
Пример #5
0
    def upgrade_flow():
        global contract

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

        user.sync_nonce(proxy)
        environment.upgrade_contract(contract,
                                     caller=user,
                                     arguments=[],
                                     gas_price=config.DEFAULT_GAS_PRICE,
                                     gas_limit=5000000,
                                     value=None,
                                     chain=config.get_chain_id(),
                                     version=config.get_tx_version())
Пример #6
0
    def _send_transaction(self, sender, receiver, data):
        tx_object = {
            "nonce": 1,
            "value": "0",
            "receiver": receiver,
            "sender": sender,
            "data": data,
            "chainID": config.get_chain_id(),
            "version": config.get_tx_version()
        }

        url = f"{self.proxy_url}/transaction/cost"

        raw_response = do_post(url, tx_object)
        return raw_response.get("txGasUnits", raw_response)
Пример #7
0
    def execute_flow():
        global contract
        function = input("Name of function: ")

        user.sync_nonce(proxy)
        tx = environment.execute_contract(contract=contract,
                                          caller=user,
                                          function=function,
                                          arguments=[],
                                          gas_price=config.DEFAULT_GAS_PRICE,
                                          gas_limit=5000000,
                                          value=None,
                                          chain=config.get_chain_id(),
                                          version=config.get_tx_version())

        logger.info("Tx hash: %s", tx)
Пример #8
0
def send_one_tx(proxy: ElrondProxy, sender: Account, receiver_address: str):
    tx = Transaction()
    tx.nonce = sender.nonce
    tx.value = "20000000000000000"  # 0.02 ERD
    tx.sender = sender.address.bech32()
    tx.receiver = receiver_address
    tx.gasPrice = 1000000000
    tx.gasLimit = 50000
    tx.data = ""
    tx.chainID = config.get_chain_id()
    tx.version = config.get_tx_version()

    tx.signature = signing.sign_transaction(tx, sender)
    tx.send(proxy)

    global counter
    counter += 1
    print(f"Sent transaction #{counter}, with nonce = {tx.nonce}.")
Пример #9
0
    def deploy_flow():
        global contract

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

        user.sync_nonce(proxy)
        tx, address = environment.deploy_contract(
            contract=contract,
            owner=user,
            arguments=[],
            gas_price=config.DEFAULT_GAS_PRICE,
            gas_limit=5000000,
            value=None,
            chain=config.get_chain_id(),
            version=config.get_tx_version())

        logger.info("Tx hash: %s", tx)
        logger.info("Contract address (hex): %s", address.hex())
        logger.info("Contract address (bech32): %s", address.bech32())
Пример #10
0
def main():
    logging.basicConfig(level=logging.DEBUG)

    parser = ArgumentParser()
    parser.add_argument("--proxy", default="https://testnet-api.elrond.com")
    parser.add_argument("--pem", required=True)
    parser.add_argument("--reward-address",
                        required=True,
                        help="the reward address")
    parser.add_argument("--nodes-file",
                        required=True,
                        help="file containing list of BLS keys, one per line")
    parser.add_argument("--value", required=True, help="the value to stake")
    args = parser.parse_args()

    proxy_url = args.proxy
    reward_address = Address(args.reward_address)
    lines = utils.read_lines(args.nodes_file)
    value = args.value
    chain = config.get_chain_id()

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

    print("Number of Nodes to stake:", len(lines))
    confirm_continuation()

    for line in lines:
        print(line[:8], "...", line[-8:])

    confirm_continuation()

    print("Elrond Proxy (or Observer) address:", proxy_url)
    print("Chain ID:", chain)
    confirm_continuation()

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

    stake_args: Any = utils.Object()
    stake_args.reward_address = reward_address.bech32()
    stake_args.number_of_nodes = len(lines)
    # Minor programming artifice (the CSV formatting),
    # so that we are compatible with erdpy 0.7.2 (this will change in the future)
    stake_args.nodes_public_keys = ",".join(lines)
    stake_args.estimate_gas = True
    stake_args.gas_price = 1000000000
    stake_args.value = args.value

    stake_args.pem = args.pem
    stake_args.proxy = proxy_url
    stake_args.chain = chain
    stake_args.version = config.get_tx_version()
    stake_args.recall_nonce = True

    print("Transaction will now be sent.")
    confirm_continuation()
    facade.prepare_and_send_stake_transaction(stake_args)
    print("Done.")
Пример #11
0
def get_tx_version() -> int:
    return config.get_tx_version()