Skip to content

Commit

Permalink
Merge pull request #5 from LedgerHQ/doc
Browse files Browse the repository at this point in the history
chore: classifier doc/cleanup
  • Loading branch information
ckorchane-ledger authored Sep 20, 2024
2 parents 9ac28cd + 1b8dc1c commit 9afdbf2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ def _fields_contain(word: str, fields: set[str]) -> bool:


class DisplayFormatChecker:
"""
Given a transaction class and a display formats, check if all the required fields of a given
transaction class are being displayed.
If a field is missing emit an error.
"""

def __init__(self, c: TxClass, d: Display):
self.c = c
self.d = d
Expand Down
5 changes: 5 additions & 0 deletions src/erc7730/linter/classifier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class TxClass(StrEnum):


class Classifier(ABC, Generic[Schema]):
"""
Given a schema (which is an EIP712 schema or an ABI schema), classify the transaction type
with some predefined ruleset.
"""

@abstractmethod
def classify(self, schema: Schema) -> TxClass | None:
raise NotImplementedError()
5 changes: 5 additions & 0 deletions src/erc7730/linter/classifier/abi_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@


class ABIClassifier(Classifier[AbiJsonSchema]):
"""
Given an EIP712 schema, classify the transaction type with some predefined ruleset.
(not implemented)
"""

@override
def classify(self, schema: AbiJsonSchema) -> TxClass | None:
pass
5 changes: 5 additions & 0 deletions src/erc7730/linter/classifier/eip712_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@


class EIP712Classifier(Classifier[EIP712JsonSchema]):
"""
Given an EIP712 schema, classify the transaction type with some predefined ruleset.
(implemented a basic detection of a permit)
"""

@override
def classify(self, schema: EIP712JsonSchema) -> TxClass | None:
if "permit" in schema.primaryType.lower():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from erc7730.linter.classifier.abi_classifier import ABIClassifier
from erc7730.linter.classifier.eip712_classifier import EIP712Classifier
from erc7730.linter.common.display_format_checker import DisplayFormatChecker
from erc7730.display_format_checker import DisplayFormatChecker
from erc7730.linter import ERC7730Linter
from erc7730.model.context import EIP712Context, ContractContext, EIP712JsonSchema
from erc7730.model.display import Display
Expand Down

0 comments on commit 9afdbf2

Please sign in to comment.