Skip to content

Commit

Permalink
✨ Implement Sake getAbi without proxy method
Browse files Browse the repository at this point in the history
  • Loading branch information
michprev committed Nov 12, 2024
1 parent a6261c1 commit d79b322
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions wake/lsp/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,4 @@ class RequestMethodEnum(StrEnum):
SAKE_GET_BALANCES = "wake/sake/getBalances"
SAKE_SET_BALANCES = "wake/sake/setBalances"
SAKE_GET_ABI = "wake/sake/getAbi"
SAKE_GET_ABI_WITH_PROXY = "wake/sake/getAbiWithProxy"
46 changes: 43 additions & 3 deletions wake/lsp/sake.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,21 @@ class SakeLoadStateParams(SakeParams):

class SakeGetAbiParams(SakeParams):
address: str
chain_id: int


class SakeGetAbiResult(SakeResult):
name: str
abi: List


class SakeGetAbiWithProxyParams(SakeParams):
address: str


class SakeGetAbiWithProxyResult(SakeResult):
name: str
abi: List
proxy_name: Optional[str]
proxy_abi: Optional[List]
implementation_address: Optional[str]
Expand Down Expand Up @@ -788,8 +798,38 @@ async def set_label(self, params: SakeSetLabelParams) -> SakeResult:
except Exception as e:
raise LspError(ErrorCodes.InternalError, str(e)) from None

@chain_connected
async def get_abi(self, params: SakeGetAbiParams) -> SakeGetAbiResult:
try:
try:
name, abi = get_name_abi_from_explorer(params.address, params.chain_id)
return SakeGetAbiResult(success=True, name=name, abi=abi)
except AbiNotFound as e:
if e.api_key_name is not None:
raise LspError(
ErrorCodes.AbiNotFound,
f"ABI not found for {params.address}",
{
"apiKeyName": e.api_key_name,
"tomlUsed": self.lsp_context.use_toml
and self.lsp_context.toml_path.is_file(),
"configPath": str(
self.lsp_context.config.global_config_path
),
},
)
else:
raise LspError(
ErrorCodes.AbiNotFound,
f"ABI not found for {params.address}",
{},
)
except Exception as e:
raise LspError(ErrorCodes.InternalError, str(e)) from None

@chain_connected
async def get_abi_with_proxy(
self, params: SakeGetAbiWithProxyParams
) -> SakeGetAbiWithProxyResult:
def info_from_address(address: str) -> Tuple[str, List]:
fqn = get_fqn_from_address(logic_contract.address, "latest", chain)
if fqn is not None:
Expand Down Expand Up @@ -837,7 +877,7 @@ def info_from_address(address: str) -> Tuple[str, List]:
name, abi = info_from_address(str(logic_contract.address))

if contract != logic_contract:
return SakeGetAbiResult(
return SakeGetAbiWithProxyResult(
success=True,
name=name,
abi=abi,
Expand All @@ -848,7 +888,7 @@ def info_from_address(address: str) -> Tuple[str, List]:
else:
proxy_name, proxy_abi = info_from_address(params.address)

return SakeGetAbiResult(
return SakeGetAbiWithProxyResult(
success=True,
name=name,
abi=abi,
Expand Down
8 changes: 8 additions & 0 deletions wake/lsp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,14 @@ def __init__(
),
SakeGetAbiParams,
),
RequestMethodEnum.SAKE_GET_ABI_WITH_PROXY: (
lambda params: (
self.__sake_context.get_abi_with_proxy( # pyright: ignore reportAttributeAccessIssue
params,
)
),
SakeGetAbiParams,
),
}

self.__notification_mapping = {
Expand Down

0 comments on commit d79b322

Please sign in to comment.