Exemple #1
0
    def _admin_peers(self):
        request_data = self.rpc_interface.get_peers()
        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.peers = []
                for each in result_data:
                    self.peers.append(dict(enode=each["enode"],
                                           caps=each["caps"],
                                           id=each["id"],
                                           network=each["network"]))
                message = "Successful admin_Peers IPC call: " + str(response_data["delay"]) + " seconds"
                message += "(" + str(len(self.peers)) + " peers)"
                if self.logger:
                    self.logger.info(message)
                else:
                    print(message)
                return True
        message = "admin_peers IPC call failed."
        if self.logger:
            self.logger.error(message)
        else:
            print(message)
        return False
Exemple #2
0
    def _admin_node_info(self):
        request_data = self.rpc_interface.get_node_info()
        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.enode = result_data["enode"]
                self.name = result_data["name"]
                self.eth_node_id = result_data["id"]
                message = "Successful admin_nodeInfo IPC call: " + str(response_data["delay"]) + " seconds"
                if self.logger:
                    self.logger.info(message)
                else:
                    print(message)
                return True
        message = "admin_nodeInfo API call failed."
        if self.logger:
            self.logger.error(message)
        else:
            print(message)
        return False
Exemple #3
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
Exemple #4
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
Exemple #5
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
    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