예제 #1
0
파일: dss.py 프로젝트: pcatana/keeper
    def past_frob(self, number_of_past_blocks: int, ilk=None) -> List[LogFrob]:
        """Synchronously retrieve a list showing which ilks and urns have been frobbed.
         Args:
            number_of_past_blocks: Number of past Ethereum blocks to retrieve the events from.
            ilk: Optionally filter frobs by ilk.name
         Returns:
            List of past `LogFrob` events represented as :py:class:`pymaker.dss.Vat.LogFrob` class.
        """
        assert isinstance(number_of_past_blocks, int)
        assert isinstance(ilk, Ilk) or ilk is None

        block_number = self._contract.web3.eth.blockNumber
        filter_params = {
            'address': self.address.address,
            'fromBlock': max(block_number-number_of_past_blocks, 0),
            'toBlock': block_number
        }

        logs = self.web3.eth.getLogs(filter_params)

        lognotes = list(map(lambda l: LogNote.from_event(l, Vat.abi), logs))
        # '0x7cdd3fde' is Vat.slip (from GemJoin.join) and '0x76088703' is Vat.frob
        logfrobs = list(filter(lambda l: l.sig == '0x76088703', lognotes))
        logfrobs = list(map(lambda l: Vat.LogFrob(l), logfrobs))

        if ilk is not None:
            logfrobs = list(filter(lambda l: l.ilk == ilk.name, logfrobs))

        return logfrobs
예제 #2
0
    def past_logs(self, from_block: int, to_block: int = None, ilk: Ilk = None,
                   include_forks=True, include_moves=True, chunk_size=20000) -> List[object]:
        """Synchronously retrieve a unordered list of vat activity, optionally filtered by collateral type.
        Args:
            from_block: Oldest Ethereum block to retrieve the events from.
            to_block: Optional newest Ethereum block to retrieve the events from, defaults to current block
            ilk: Optionally filter frobs by ilk.name
            chunk_size: Number of blocks to fetch from chain at one time, for performance tuning
        Returns:
            Unordered list of past `LogFork`, `LogFrob`, and `LogMove` events.
        """
        current_block = self._contract.web3.eth.blockNumber
        assert isinstance(from_block, int)
        assert from_block <= current_block
        if to_block is None:
            to_block = current_block
        else:
            assert isinstance(to_block, int)
            assert to_block >= from_block
            assert to_block <= current_block
        assert isinstance(ilk, Ilk) or ilk is None
        assert chunk_size > 0

        logger.debug(f"Consumer requested frob data from block {from_block} to {to_block}")
        start = from_block
        end = None
        chunks_queried = 0
        retval = []
        while end is None or start <= to_block:
            chunks_queried += 1
            end = min(to_block, start+chunk_size)

            filter_params = {
                'address': self.address.address,
                'fromBlock': start,
                'toBlock': end
            }
            logger.debug(f"Querying logs from block {start} to {end} ({end-start} blocks); "
                         f"accumulated {len(retval)} logs in {chunks_queried-1} requests")

            logs = self.web3.eth.getLogs(filter_params)

            lognotes = list(map(lambda l: LogNote.from_event(l, Vat.abi), logs))

            # '0x7cdd3fde' is Vat.slip (from GemJoin.join) and '0x76088703' is Vat.frob
            logfrobs = list(filter(lambda l: l.sig == '0x76088703', lognotes))
            logfrobs = list(map(lambda l: Vat.LogFrob(l), logfrobs))
            if ilk is not None:
                logfrobs = list(filter(lambda l: l.ilk == ilk.name, logfrobs))
            retval.extend(logfrobs)

            # '0xbb35783b' is Vat.move
            if include_moves:
                logmoves = list(filter(lambda l: l.sig == '0xbb35783b', lognotes))
                logmoves = list(map(lambda l: Vat.LogMove(l), logmoves))
                retval.extend(logmoves)

            # '0x870c616d' is Vat.fork
            if include_forks:
                logforks = list(filter(lambda l: l.sig == '0x870c616d', lognotes))
                logforks = list(map(lambda l: Vat.LogFork(l), logforks))
                if ilk is not None:
                    logforks = list(filter(lambda l: l.ilk == ilk.name, logforks))
                retval.extend(logforks)

            start += chunk_size

        logger.debug(f"Found {len(retval)} logs in {chunks_queried} requests")
        return retval
예제 #3
0
파일: dss.py 프로젝트: w1r2p1/pymaker
    def past_frobs(self,
                   from_block: int,
                   to_block: int = None,
                   ilk: Ilk = None,
                   chunk_size=20000) -> List[LogFrob]:
        """Synchronously retrieve a list showing which ilks and urns have been frobbed.
         Args:
            from_block: Oldest Ethereum block to retrieve the events from.
            to_block: Optional newest Ethereum block to retrieve the events from, defaults to current block
            ilk: Optionally filter frobs by ilk.name
            chunk_size: Number of blocks to fetch from chain at one time, for performance tuning
         Returns:
            List of past `LogFrob` events represented as :py:class:`pymaker.dss.Vat.LogFrob` class.
        """
        current_block = self._contract.web3.eth.blockNumber
        assert isinstance(from_block, int)
        assert from_block < current_block
        if to_block is None:
            to_block = current_block
        else:
            assert isinstance(to_block, int)
            assert to_block >= from_block
            assert to_block <= current_block
        assert isinstance(ilk, Ilk) or ilk is None
        assert chunk_size > 0

        logger.debug(
            f"Consumer requested frob data from block {from_block} to {to_block}"
        )
        start = from_block
        end = None
        chunks_queried = 0
        retval = []
        while end is None or start <= to_block:
            chunks_queried += 1
            end = min(to_block, start + chunk_size)

            filter_params = {
                'address': self.address.address,
                'fromBlock': start,
                'toBlock': end
            }
            logger.debug(
                f"Querying frobs from block {start} to {end} ({end-start} blocks); "
                f"accumulated {len(retval)} frobs in {chunks_queried-1} requests"
            )

            logs = self.web3.eth.getLogs(filter_params)

            lognotes = list(map(lambda l: LogNote.from_event(l, Vat.abi),
                                logs))
            # '0x7cdd3fde' is Vat.slip (from GemJoin.join) and '0x76088703' is Vat.frob
            logfrobs = list(filter(lambda l: l.sig == '0x76088703', lognotes))
            logfrobs = list(map(lambda l: Vat.LogFrob(l), logfrobs))
            if ilk is not None:
                logfrobs = list(filter(lambda l: l.ilk == ilk.name, logfrobs))

            retval.extend(logfrobs)
            start += chunk_size

        logger.debug(f"Found {len(retval)} frobs in {chunks_queried} requests")
        return retval