Skip to content

Commit 5cfd6bd

Browse files
authored
Implemented renewing account or grpc client at runtime;
sdk.renew_grpc and sdk.renew_account now allow to change account or client at runtime
1 parent 8ce3816 commit 5cfd6bd

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/sentinel_sdk/sdk.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ def __create_and_verify_channel(
5858
self._channel = channel
5959

6060
def __setup_account_and_client(self, grpcaddr: str, grpcport: int, secret: str, use_ssl: bool = False):
61+
self._account = self.__create_account(secret)
62+
self._client = self.__create_client(grpcaddr, grpcport, use_ssl)
63+
self._client.load_account_data(account=self._account)
64+
65+
def __create_account(self, secret: str):
6166
try:
6267
Bip39MnemonicValidator().Validate(secret)
6368
seed_bytes = Bip39SeedGenerator(secret).Generate()
@@ -75,19 +80,19 @@ def __setup_account_and_client(self, grpcaddr: str, grpcport: int, secret: str,
7580
ripemd_key.update(sha_key.digest())
7681
bech32_pub = Bech32Encoder.Encode("sent", ripemd_key.digest())
7782
account_num = self.__get_account_number(bech32_pub)
78-
79-
self._account = Account(
83+
account = Account(
8084
private_key=bip44_def_ctx.PrivateKey().Raw().ToHex(),
8185
hrp="sent",
8286
account_number=account_num,
8387
protobuf="sentinel",
8488
)
85-
self._client = GRPCClient(
89+
return account
90+
91+
def __create_client(self, grpcaddr: str, grpcport: int, use_ssl: bool = False):
92+
client = GRPCClient(
8693
host=grpcaddr, port=grpcport, ssl=use_ssl, protobuf="sentinel"
8794
)
88-
self._client.load_account_data(account=self._account)
89-
90-
95+
return client
9196

9297
def __get_account_number(self, address: str):
9398
tmp_stub = self._channel.unary_unary(
@@ -110,4 +115,18 @@ def __load_modules(self):
110115
self.subscriptions = SubscriptionModule(self._channel, self._account, self._client)
111116
self.swaps = SwapModule(self._channel, self._account, self._client)
112117

118+
def renew_account(self, secret: str):
119+
self._account = self.__create_account(secret)
120+
self._client.load_account_data(account=self._account)
121+
122+
def renew_grpc(self, grpcaddr: str, grpcport: int, use_ssl: bool = False):
123+
self._client = self.__create_client(grpcaddr, grpcport)
124+
self._client.load_account_data(account=self._account)
125+
126+
def get_grpc_host(self):
127+
return self._client._host
128+
129+
def get_grpc_port(self):
130+
return self._client._port
113131

132+

0 commit comments

Comments
 (0)