예제 #1
0
    def json_dict_to_receipt_log(self, json_dict):
        receipt_log = ReceiptLog()

        receipt_log.log_index = hex_to_dec(json_dict.get('logIndex', None))
        receipt_log.transaction_hash = json_dict.get('transactionHash', None)
        receipt_log.transaction_index = hex_to_dec(
            json_dict.get('transactionIndex', None))
        receipt_log.block_hash = json_dict.get('blockHash', None)
        receipt_log.block_number = hex_to_dec(
            json_dict.get('blockNumber', None))
        receipt_log.address = json_dict.get('address', None)
        receipt_log.data = json_dict.get('data', None)
        receipt_log.topics = json_dict.get('topics', None)

        return receipt_log
예제 #2
0
파일: proxy.py 프로젝트: deep2cv/pyrpc
    def up_getUncleCountByBlockHash(self, block_hash):
        '''
        https://github.com/ethereum/wiki/wiki/JSON-RPC#up_getunclecountbyblockhash

        TESTED
        '''
        return hex_to_dec(self._call('up_getUncleCountByBlockHash', [block_hash]))
예제 #3
0
파일: proxy.py 프로젝트: deep2cv/pyrpc
    def up_getBlockTransactionCountByHash(self, block_hash):
        '''
        https://github.com/ethereum/wiki/wiki/JSON-RPC#up_getblocktransactioncountbyhash

        TESTED
        '''
        return hex_to_dec(self._call('up_getBlockTransactionCountByHash', [block_hash]))
    def extract_suicide(cls, trace_entry):
        transfer = EtherTransfer()
        transfer.value = hex_to_dec(trace_entry['action']['balance'])
        transfer.to_address = trace_entry['action']['refundAddress']
        transfer.from_address = trace_entry['action']['address']

        return transfer
예제 #5
0
    def eth_estimateGas(self,
                        to_address=None,
                        from_address=None,
                        gas=None,
                        gas_price=None,
                        value=None,
                        data=None,
                        default_block=BLOCK_TAG_LATEST):
        '''
        https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_estimategas

        NEEDS TESTING
        '''
        if isinstance(default_block, str):
            if default_block not in BLOCK_TAGS:
                raise ValueError
        obj = {}
        if to_address is not None:
            obj['to'] = to_address
        if from_address is not None:
            obj['from'] = from_address
        if gas is not None:
            obj['gas'] = hex(gas)
        if gas_price is not None:
            obj['gasPrice'] = clean_hex(gas_price)
        if value is not None:
            obj['value'] = value
        if data is not None:
            obj['data'] = data
        return hex_to_dec(self._call('eth_estimateGas', [obj, default_block]))
예제 #6
0
    def eth_gasPrice(self):
        '''
        https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gasprice

        TESTED
        '''
        return hex_to_dec(self._call('eth_gasPrice'))
예제 #7
0
    def eth_blockNumber(self):
        '''
        https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_blocknumber

        TESTED
        '''
        return hex_to_dec(self._call('eth_blockNumber'))
예제 #8
0
    def net_peerCount(self):
        '''
        https://github.com/ethereum/wiki/wiki/JSON-RPC#net_peercount

        TESTED
        '''
        return hex_to_dec(self._call('net_peerCount'))
예제 #9
0
    def eth_hashrate(self):
        '''
        https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_hashrate

        TESTED
        '''
        return hex_to_dec(self._call('eth_hashrate'))
    def extract_create(cls, trace_entry):
        transfer = EtherTransfer()
        transfer.value = hex_to_dec(trace_entry['action']['value'])
        transfer.to_address = trace_entry['result']['address']
        transfer.from_address = trace_entry['action']['from']

        return transfer
예제 #11
0
파일: proxy.py 프로젝트: deep2cv/pyrpc
    def up_getBlockTransactionCountByNumber(self, block=BLOCK_TAG_LATEST):
        '''
        https://github.com/ethereum/wiki/wiki/JSON-RPC#up_getblocktransactioncountbynumber

        TESTED
        '''
        block = validate_block(block)
        return hex_to_dec(self._call('up_getBlockTransactionCountByNumber', [block]))
예제 #12
0
파일: proxy.py 프로젝트: deep2cv/pyrpc
    def up_getTransactionCount(self, address, block=BLOCK_TAG_LATEST):
        '''
        https://github.com/ethereum/wiki/wiki/JSON-RPC#up_gettransactioncount

        TESTED
        '''
        block = validate_block(block)
        return hex_to_dec(self._call('up_getTransactionCount', [address, block]))
예제 #13
0
파일: proxy.py 프로젝트: deep2cv/pyrpc
    def up_getUncleCountByBlockNumber(self, block=BLOCK_TAG_LATEST):
        '''
        https://github.com/ethereum/wiki/wiki/JSON-RPC#up_getunclecountbyblocknumber

        TESTED
        '''
        block = validate_block(block)
        return hex_to_dec(self._call('up_getUncleCountByBlockNumber', [block]))
예제 #14
0
파일: proxy.py 프로젝트: deep2cv/pyrpc
    def up_getBalance(self, address=None, block=BLOCK_TAG_LATEST):
        '''
        https://github.com/ethereum/wiki/wiki/JSON-RPC#up_getbalance

        TESTED
        '''
        address = address or self.up_coinbase()
        block = validate_block(block)
        return hex_to_dec(self._call('up_getBalance', [address, block]))
예제 #15
0
    def eth_getBalance(self, address=None, block=BLOCK_TAG_LATEST):
        '''
        https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getbalance

        TESTED
        '''
        address = address
        block = validate_block(block)
        #print(block)
        return hex_to_dec(self._call('eth_getBalance', [address, block]))
예제 #16
0
    def __get_another_block(self, step: int):
        # logger.error(e, exc_info=True, extra={"txid": transaction['hash']})

        while True:
            print("\tReading {0} block".format(self.current_block))
            block = self.rpc_client.eth_getBlockByNumber(self.current_block)

            if block is None:
                time.sleep(1)
                self.logger.info("Sleeping on ", extra={"number": self.current_block})
                continue

            self.current_block = hex_to_dec(block['number']) + step
            self.logger.info("\tFetched new block", extra={"number": self.current_block - 1})

            return block
 def json_dict_to_transaction(self, json_dict):
     transaction = Transaction()
     transaction.hash = json_dict.get('hash', None)
     transaction.nonce = hex_to_dec(json_dict.get('nonce', None))
     transaction.block_hash = json_dict.get('blockHash', None)
     transaction.block_number = hex_to_dec(json_dict.get('blockNumber', None))
     transaction.transaction_index = hex_to_dec(json_dict.get('transactionIndex', None))
     transaction.from_address = to_normalized_address(json_dict.get('from', None))
     transaction.to_address = to_normalized_address(json_dict.get('to', None))
     transaction.value = hex_to_dec(json_dict.get('value', None))
     transaction.gas = hex_to_dec(json_dict.get('gas', None))
     transaction.gas_price = hex_to_dec(json_dict.get('gasPrice', None))
     transaction.input = json_dict.get('input', None)
     return transaction
    def extract(self, tx: Transaction):
        cl = inject.instance(ParityEthJsonRpc)

        tx._reciept = cl.eth_getTransactionReceipt(tx.hash)

        mapper = TxReceiptLogMapper()

        for log_dict in tx._reciept['logs']:
            receipt_log = mapper.dict_to_receipt_log(log_dict)

            topics = receipt_log.topics
            if topics is None or len(topics) < 1:
                logger.warning(
                    "Topics are empty in log {} of transaction {}".format(
                        receipt_log.log_index, receipt_log.transaction_hash))
                continue

            if topics[0] == TRANSFER_EVENT_TOPIC:
                topics_with_data = topics + split_to_words(receipt_log.data)
                if len(topics_with_data) != 4:
                    logger.warning(
                        "The number of topics and data parts is not equal to 4 in log {} of transaction {}"
                        .format(receipt_log.log_index,
                                receipt_log.transaction_hash))
                    continue

                token_transfer = TokenTransfer()
                token_transfer.value_id = to_normalized_address(
                    receipt_log.address)
                token_transfer.from_address = word_to_address(
                    topics_with_data[1])
                token_transfer.to_address = word_to_address(
                    topics_with_data[2])
                token_transfer.value = hex_to_dec(topics_with_data[3])
                token_transfer.transaction_hash = receipt_log.transaction_hash
                token_transfer.block_number = tx.block_number
                token_transfer.transaction_hash = tx.hash

                yield token_transfer
예제 #19
0
    def collect_net_tcp(self, ret_format):
        """
        Method to collect all data from /proc/net/tcp

        Arguments:
        ret_format -- Return data as hexadecimal or "human being" format ;-)
                      Use as: ret_format="hex" or ret_format="human_being"

        Returns:
        Return the /proc/net/tcp fields as list of dict
        """

        # Creates a List of dictionaries
        netdata = {}
        list_netdata = []

        data = ""
        with open("/proc/net/tcp", "r") as fd:
            #with open("/proc/net/tcp6", "r") as fd:
            for i, line in enumerate(fd):
                # Jumping header output
                if i == 0:
                    continue

                index_netstat_fields = 0
                for char in line:
                    if " " in char:
                        if data == "" or data == " " or data == "\n":
                            continue

                        data = data.strip("\n")
                        netdata['proto'] = "tcp"
                        if index_netstat_fields == 0:
                            netdata['sl'] = data

                        if index_netstat_fields == 1:
                            if ret_format == "human_being":
                                ip_address, port = data.split(":")
                                # Convert from little endian to big endian
                                ip_address = socket.inet_ntoa(
                                    struct.pack("<L", int(ip_address, 16)))
                                netdata['local_address'] = ip_address
                                netdata['local_address'] += ":" + \
                                    str(utils.hex_to_dec(port))
                            else:
                                netdata['local_address'] = data

                        if index_netstat_fields == 2:
                            if ret_format == "human_being":
                                ip_address, port = data.split(":")
                                # Convert from little endian to big endian
                                ip_address = socket.inet_ntoa(
                                    struct.pack("<L", int(ip_address, 16)))
                                netdata['rem_address'] = ip_address
                                netdata['rem_address'] += ":" + \
                                    str(utils.hex_to_dec(port))

                                if "0.0.0.0:0" in netdata['rem_address']:
                                    netdata['rem_address'] = "0.0.0.0:*"
                            else:
                                netdata['rem_address'] = data

                        if index_netstat_fields == 3:
                            if ret_format == "human_being":
                                netdata['st'] = self.conn_status[str(
                                    utils.hex_to_dec(data))]
                            else:
                                netdata['st'] = data

                        if index_netstat_fields == 4:
                            if ret_format == "human_being":
                                tx, rx = data.split(':')
                                netdata['tx_queue_rx_queue'] = str(
                                    utils.hex_to_dec(rx))
                                netdata['tx_queue_rx_queue'] += ":" + \
                                    str(utils.hex_to_dec(tx))
                            else:
                                netdata['tx_queue_rx_queue'] = data

                        if index_netstat_fields == 5:
                            netdata['tr_tm_when'] = data

                        if index_netstat_fields == 6:
                            netdata['retrnsmt'] = data

                        if index_netstat_fields == 7:
                            if ret_format == "human_being":
                                netdata['uid'] = pwd.getpwuid(int(data))[0]
                            else:
                                netdata['uid'] = data

                        if index_netstat_fields == 8:
                            netdata['timeout'] = data

                        if index_netstat_fields == 9:
                            netdata['inode'] = data

                        if index_netstat_fields > 9:
                            netdata['inode'] += " " + data

                        data = ""
                        index_netstat_fields += 1
                        continue

                    data += char
                list_netdata.append(netdata.copy())

            return list_netdata