Exemplo n.º 1
0
    def _emit_LLVM(self):
        logger.info("_emit_LLVM")

        tool = self._get_soll_path()
        args = [tool, "-action", "EmitLLVM", str(self.unit)]
        output = myprocess.run_process(args)
        utils.write_file(self.file_ll, output)
Exemplo n.º 2
0
    def _emit_funcions(self):
        logger.info("_emit_funcions")

        tool = self._get_soll_path()
        args = [tool, "-action", "EmitFuncSig", str(self.unit)]
        output = myprocess.run_process(args)
        utils.write_file(self.file_functions, output)
Exemplo n.º 3
0
    def _create_main_ll(self):
        logger.info("_create_main_ll")

        package_path = Path(__file__).parent
        template_path = package_path.joinpath("sol_main_ll.txt")
        template = utils.read_file(template_path)
        content = template.replace("{{NAME}}", self.unit_name)
        utils.write_file(self.file_main_ll, content)
Exemplo n.º 4
0
    def _replace_in_files(self, files, replacements):
        for file in files:
            content = utils.read_file(file)

            for to_replace, replacement in replacements:
                content = content.replace(to_replace, replacement)

            utils.write_file(file, content)
Exemplo n.º 5
0
def patch_source_code(testnet_config: TestnetConfiguration):
    logger.info("Patching the source code...")

    folder = testnet_config.node_source()

    file = path.join(folder, "core/constants.go")
    content = utils.read_file(file)
    utils.write_file(file, content)

    file = path.join(folder, "cmd/node/main.go")
    content = utils.read_file(file)
    content = content.replace("secondsToWaitForP2PBootstrap = 20",
                              "secondsToWaitForP2PBootstrap = 1")
    utils.write_file(file, content)
Exemplo n.º 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)
Exemplo n.º 7
0
    def __init__(self):
        tools_folder = get_tools_folder()

        txs_file_dir = path.join(tools_folder, "transactions")
        # create transactions directory if not exits
        if not os.path.exists(txs_file_dir):
            os.mkdir(txs_file_dir)

        self.txs_file_path = path.join(txs_file_dir, self._TXS_FILE_NAME)
        if not os.path.exists(self.txs_file_path):
            # create transactions file if not exits
            utils.write_file(self.txs_file_path,
                             '{"' + self._TXS_FIELD_NAME + '":[]}')

        self.txs_info_file_path = path.join(txs_file_dir,
                                            self._TXS_INFO_FILE_NAME)
        if not os.path.exists(self.txs_info_file_path):
            utils.write_file(self.txs_info_file_path, f"index:{0}")
Exemplo n.º 8
0
def write(pem_file, seed, pubkey, name=None):
    pem_file = path.expanduser(pem_file)

    if not name:
        name = pubkey.hex()

    header = f"-----BEGIN PRIVATE KEY for {name}-----"
    footer = f"-----END PRIVATE KEY for {name}-----"

    seed_hex = seed.hex()
    pubkey_hex = pubkey.hex()
    combined = seed_hex + pubkey_hex
    combined = combined.encode()
    key_base64 = base64.b64encode(combined).decode()

    payload_lines = textwrap.wrap(key_base64, 64)
    payload = "\n".join(payload_lines)
    content = "\n".join([header, payload, footer])
    utils.write_file(pem_file, content)
Exemplo n.º 9
0
 def save_to_file(self, filename):
     utils.write_file(filename, self.to_json())