Skip to content

Commit 9fafff2

Browse files
committed
feat: adding relayer function calls in python-sdk client object
1 parent 8bfef8c commit 9fafff2

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

sdk/python/src/rrelayer/client.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
from typing import Any
12
from pydantic import BaseModel, validate_call, ConfigDict, PrivateAttr
23
from rrelayer.api import API
34

45

56
class Client(BaseModel):
6-
_serverURL: str = PrivateAttr()
7-
_auth_username: str = PrivateAttr()
8-
_auth_password: str = PrivateAttr()
7+
_apiBaseConfig: dict[str, str] = PrivateAttr()
8+
99
_api: API = PrivateAttr()
1010

11-
relayer: "Client.Relayer" = None
11+
relayer: "Client.Relayer | None" = None
1212
network: "Client.Network | None" = None
1313
transaction: "Client.Transaction | None" = None
1414
allowlist: "Client.AllowList | None" = None
@@ -18,9 +18,11 @@ class Client(BaseModel):
1818
def __init__(self, serverURL: str, auth_username: str, auth_password: str, **data):
1919
super().__init__(**data)
2020

21-
self._serverURL = serverURL
22-
self._auth_username = auth_username
23-
self._auth_password = auth_password
21+
self._apiBaseConfig = {
22+
"serverURL": serverURL,
23+
"username": auth_username,
24+
"password": auth_password,
25+
}
2426

2527
self._api = API()
2628

@@ -35,28 +37,35 @@ def __init__(self, client: "Client"):
3537

3638
@validate_call
3739
async def create(self, chainId: int, name: str):
38-
pass
40+
return await self._client._api.postApi(
41+
self._client._apiBaseConfig, f"relayers/{chainId}/new", {"name": name}
42+
)
3943

4044
@validate_call
4145
async def clone(self, relayerId: str, chainId: int, name: str):
42-
pass
46+
return await self._client._api.postApi(
47+
self._client._apiBaseConfig,
48+
f"relayers/{relayerId}/clone",
49+
{"newRelayerName": name, "chainId": chainId},
50+
)
4351

4452
@validate_call
4553
async def delete(self, id: str):
46-
pass
54+
_ = await self._client._api.deleteApi(
55+
self._client._apiBaseConfig, f"relayers/{id}"
56+
)
4757

4858
@validate_call
49-
async def get(self, id: str):
50-
pass
59+
async def get(self, id: str) -> dict[str, Any]:
60+
return await self._client._api.getApi(
61+
self._client._apiBaseConfig,
62+
f"relayers/{id}",
63+
)
5164

5265
@validate_call
5366
async def getAll(self):
5467
pass
5568

56-
def printValues(self):
57-
print("Print Values")
58-
print(self._client._auth_username)
59-
6069
class Network:
6170
def __init__(self, client: "Client"):
6271
self._client: "Client" = client

sdk/python/src/rrelayer/relayer.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
from pydantic import BaseModel, ConfigDict, PrivateAttr
2-
from asyncinit import asyncinit
32
from web3 import AsyncWeb3
43

54

6-
@asyncinit
75
class Relayer(BaseModel):
86
_id: str = PrivateAttr()
97

10-
_apiBaseConfig: dict = PrivateAttr()
8+
_apiBaseConfig: dict[str, str] = PrivateAttr()
9+
_ethereumProvider: AsyncWeb3 | None = PrivateAttr(None)
10+
1111
model_config = ConfigDict(arbitrary_types_allowed=True)
12-
_ethereumProvider: AsyncWeb3 | None = None
1312

1413
def __init__(
1514
self,
@@ -23,9 +22,7 @@ def __init__(
2322

2423
self._id = relayerId
2524

26-
self._ethereumProvider = await AsyncWeb3(
27-
AsyncWeb3.AsyncHTTPProvider(providerUrl)
28-
)
25+
self._ethereumProvider = AsyncWeb3(AsyncWeb3.AsyncHTTPProvider(providerUrl))
2926

3027
if "apiKey" in auth:
3128
self._apiBaseConfig = {"apiKey": auth["apiKey"], "serverURL": serverURL}

0 commit comments

Comments
 (0)