agents/marketing/onchain/censura_client.py · 41 lines · 1.0 KB · Python source
1"""
2censura_client — read agent reputation, decide if faded.
3"""
4
5from __future__ import annotations
6
7from dataclasses import dataclass
8from typing import Any, Optional
9
10
11@dataclass
12class CensuraVerdict:
13 score: int
14 floor: int
15 faded: bool
16
17
18class CensuraClient:
19 def __init__(
20 self,
21 contract_address: str,
22 chain_id: int,
23 floor: int = 50,
24 web3_view: Any = None,
25 ) -> None:
26 self.contract_address = contract_address
27 self.chain_id = int(chain_id)
28 self.floor = int(floor)
29 self.web3_view = web3_view
30
31 async def evaluate(self, address: str) -> CensuraVerdict:
32 if self.web3_view is None:
33 return CensuraVerdict(score=255, floor=self.floor, faded=False)
34 try:
35 score = int(await self.web3_view.read_uint("score", address))
36 except Exception:
37 score = 0
38 return CensuraVerdict(score=score, floor=self.floor, faded=score < self.floor)
39
40
41__all__ = ["CensuraClient", "CensuraVerdict"]