def __init__(self, lognote: LogNote): assert isinstance(lognote, LogNote) self.ilk = str(Web3.toText(lognote.arg1)).replace('\x00', '') self.urn = Address(Web3.toHex(lognote.arg2)[26:]) self.collateral_owner = Address(Web3.toHex(lognote.arg3)[26:]) self.dai_recipient = Address(Web3.toHex(lognote.get_bytes_at_index(3))[26:]) self.dink = Wad(int.from_bytes(lognote.get_bytes_at_index(4), byteorder="big", signed=True)) self.dart = Wad(int.from_bytes(lognote.get_bytes_at_index(5), byteorder="big", signed=True)) self.block = lognote.block self.tx_hash = lognote.tx_hash
def __init__(self, lognote: LogNote): self.guy = Address(lognote.usr) self.id = Web3.toInt(lognote.arg1) self.lot = Wad(Web3.toInt(lognote.arg2)) self.bid = Rad(Web3.toInt(lognote.get_bytes_at_index(2))) self.block = lognote.block self.tx_hash = lognote.tx_hash
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
def __init__(self, lognote: LogNote): assert isinstance(lognote, LogNote) self.src = Address(Web3.toHex(lognote.arg1)[26:]) self.dst = Address(Web3.toHex(lognote.arg2)[26:]) self.dart = Rad(int.from_bytes(lognote.get_bytes_at_index(2), byteorder="big", signed=True)) self.block = lognote.block self.tx_hash = lognote.tx_hash
def parse_event(self, event): signature = Web3.toHex(event['topics'][0]) codec = ABICodec(default_registry) if signature == "0x7e8881001566f9f89aedb9c5dc3d856a2b81e5235a8196413ed484be91cc0df6": event_data = get_event_data(codec, self.kick_abi, event) return Flopper.KickLog(event_data) else: event_data = get_event_data(codec, self.log_note_abi, event) return LogNote(event_data)
def parse_event(self, event): signature = Web3.toHex(event['topics'][0]) codec = ABICodec(default_registry) if signature == "0xe6dde59cbc017becba89714a037778d234a84ce7f0a137487142a007e580d609": event_data = get_event_data(codec, self.kick_abi, event) return Flapper.KickLog(event_data) else: event_data = get_event_data(codec, self.log_note_abi, event) return LogNote(event_data)
def parse_event(self, event): signature = Web3.toHex(event['topics'][0]) codec = ABICodec(default_registry) if signature == "0xc84ce3a1172f0dec3173f04caaa6005151a4bfe40d4c9f3ea28dba5f719b2a7a": event_data = get_event_data(codec, self.kick_abi, event) return Flipper.KickLog(event_data) else: event_data = get_event_data(codec, self.log_note_abi, event) return LogNote(event_data)
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
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