예제 #1
0
    def _getLatestBlock(self):
        request_data = self.rpc_interface.get_latest_block()
        if UNIT_TESTING:
            ipc = ipc_test_harness.IPCTestHarness(request_data, self.config)
        else:
            ipc = ipc_socket.GethInterface(request_data, self.config)
        response_stream = ipc.send()
        response_data = self.rpc_interface.process_response(response_stream)

        if type(response_data) == dict:
            self.total_rpc_delay += response_data["delay"]
            self.total_rpc_calls += 1
            if "result" in response_data:
                result_data = response_data["result"]
                self.latest_block = {'gas_limit': util.hex_to_dec(result_data["gasLimit"]),
                                     'gas_used': util.hex_to_dec(result_data["gasUsed"]), 'hash': result_data["hash"],
                                     'number': util.hex_to_dec(result_data["number"]),
                                     'size': util.hex_to_dec(result_data["size"]),
                                     'timestamp': util.hex_to_dec(result_data["timestamp"]),
                                     'transaction_count': len(result_data["transactions"])}
                message = "Successful getBlockByNumber IPC call: " + str(response_data["delay"]) + " seconds"
                if self.logger:
                    self.logger.info(message)
                else:
                    print(message)
                return True
        message = "getBlockByNumber API call failed."
        if self.logger:
            self.logger.error(message)
        else:
            print(message)
        return False
예제 #2
0
    def _eth_syncing(self):
        request_data = self.rpc_interface.check_sync()
        if UNIT_TESTING:
            ipc = ipc_test_harness.IPCTestHarness(request_data, self.config)
        else:
            ipc = ipc_socket.GethInterface(request_data, self.config)
        response_stream = ipc.send()
        response_data = self.rpc_interface.process_response(response_stream)

        if type(response_data) == dict:
            self.total_rpc_delay += response_data["delay"]
            self.total_rpc_calls += 1
            if "result" in response_data:
                syncing = response_data["result"]
                if type(syncing) == dict:
                    highest_block = util.hex_to_dec(syncing["highestBlock"])
                    current_block = util.hex_to_dec(syncing["currentBlock"])
                    self.synced = False
                    self.blocks_behind = highest_block - current_block
                else:
                    self.synced = True
                    self.blocks_behind = 0
                message = "Successful eth_syncing API call: " + str(response_data["delay"]) + " seconds"
                if self.logger:
                    self.logger.info(message)
                else:
                    print(message)
                return True
        else:
            message = "eth_syncing API called failed."
            if self.logger:
                self.logger.error(message)
            else:
                print(message)
            return False
예제 #3
0
def SB1(bytes):
    new_bytes = np.full((4, 4), "00")
    sb_matrix = generate_sb_matrix(type="inverse")
    for i in range(4):
        for j in range(4):
            my_byte = bytes.item((i, j))
            y = util.hex_to_dec(my_byte[0])
            x = util.hex_to_dec(my_byte[1])
            new_bytes.itemset((i, j), sb_matrix[y, x])
    return new_bytes
예제 #4
0
def SB_key(bytes):
    new_byte = ""
    sb_matrix = generate_sb_matrix()
    bytes = "".join(bytes)
    for i in range(int(len(bytes) / 2)):
        my_byte = bytes[i * 2:i * 2 + i + 2]
        y = util.hex_to_dec(my_byte[0])
        x = util.hex_to_dec(my_byte[1])
        new_byte += sb_matrix[y, x]
    return new_byte
예제 #5
0
    def _getBalance(self):
        request_data = self.rpc_interface.get_balance(self.config["account"])
        if UNIT_TESTING:
            ipc = ipc_test_harness.IPCTestHarness(request_data, self.config)
        else:
            ipc = ipc_socket.GethInterface(request_data, self.config)
        response_stream = ipc.send()
        response_data = self.rpc_interface.process_response(response_stream)

        if type(response_data) == dict:
            self.total_rpc_delay = response_data["delay"]
            self.total_rpc_calls += 1
            if "result" in response_data:
                message = "Successful eth_getBalance IPC call: " + str(response_data["delay"]) + " seconds"
                if self.logger:
                    self.logger.info(message)
                else:
                    print(message)
                self.balance = util.wei_to_ether(util.hex_to_dec(response_data["result"]))
                return True
        message = "eth_getBalance API call failed."
        if self.logger:
            self.logger.error(message)
        else:
            print(message)
        return False
예제 #6
0
    def _getBlockData(self, block_number):
        request_data = self.rpc_interface.get_block_transactions(block_number)
        if UNIT_TESTING:
            ipc = ipc_test_harness.IPCTestHarness(request_data, self.config)
        else:
            ipc = ipc_socket.GethInterface(request_data, self.config)
        response_stream = ipc.send()
        response_data = self.rpc_interface.process_response(response_stream)

        if type(response_data) == dict:
            self.total_rpc_delay += response_data["delay"]
            self.total_rpc_calls += 1
            if "result" in response_data:
                result_data = response_data["result"]
                if result_data is None:
                    message = "getBlockByNumber API call: block still pending"
                    if self.logger:
                        self.logger.error(message)
                    else:
                        print(message)
                    return None
                block_data = BlockData(
                    util.hex_to_dec(result_data["number"]),
                    result_data["hash"],
                    util.hex_to_dec(result_data["timestamp"]),
                    util.hex_to_dec(result_data["gasUsed"]),
                    util.hex_to_dec(result_data["gasLimit"]),
                    util.hex_to_dec(result_data["size"]),
                    len(result_data["transactions"]))

                for each_transaction in result_data["transactions"]:
                    new_obj = TransactionData(
                        each_transaction["from"],
                        util.hex_to_dec(each_transaction["gas"]),
                        util.hex_to_dec(each_transaction["gasPrice"]),
                        each_transaction["hash"], each_transaction["to"],
                        util.hex_to_dec(each_transaction["value"]))
                    block_data.transactions.append(new_obj)
                message = "Successful getBlockByNumber IPC call: " + str(
                    response_data["delay"]) + " seconds"
                if self.logger:
                    self.logger.info(message)
                else:
                    print(message)
                return block_data
        message = "getBlockByNumber API call failed."
        if self.logger:
            self.logger.error(message)
        else:
            print(message)
        return None
예제 #7
0
def mul(a, b):
    a = util.hex_to_dec(a)
    b = util.hex_to_dec(b)
    c = util.bin_to_hex(str(GF256(a) * GF256(b))[8:16])
    return c