Skip to content

Commit e059813

Browse files
committed
allow None secret in SDKInstance init, in order to execute only query
1 parent c6947a9 commit e059813

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/sentinel_sdk/sdk.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,15 @@ def __init__(self, grpcaddr: str, grpcport: int, secret: str = None, ssl: bool =
2626
self.__create_and_verify_channel(grpcaddr, grpcport, ssl=ssl)
2727
except grpc._channel._InactiveRpcError:
2828
raise ConnectionError("gRPC endpoint is invalid or not responding")
29-
30-
self.__setup_account_and_client(grpcaddr, grpcport, secret, ssl)
29+
30+
self._client = None
31+
self._account = None
32+
33+
if secret is not None:
34+
self.__setup_account_and_client(grpcaddr, grpcport, secret, ssl)
35+
3136
self.__load_modules()
32-
37+
3338

3439
def __create_and_verify_channel(
3540
self, grpcaddr: str, grpcport: int, ssl: bool = False
@@ -63,7 +68,7 @@ def __setup_account_and_client(self, grpcaddr: str, grpcport: int, secret: str,
6368
bip44_def_ctx = Bip44.FromPrivateKey(bytes.fromhex(secret), Bip44Coins.COSMOS)
6469
except:
6570
raise ValueError("Unrecognized secret either as a mnemonic or hex private key")
66-
71+
6772
sha_key = SHA256.new()
6873
ripemd_key = RIPEMD160.new()
6974
sha_key.update(bip44_def_ctx.PublicKey().RawCompressed().m_data_bytes)
@@ -106,4 +111,3 @@ def __load_modules(self):
106111
self.swaps = SwapModule(self._channel, self._account, self._client)
107112

108113

109-

src/sentinel_sdk/transactor/transactor.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ def __init__(
1919
# We need to find a good way to this. **The method could return only the MsgRequest and type_url**
2020
# Who wants to submit the tx, can call transaction (we should also implement multi-add_raw_msg), one tx with multiple msg
2121

22-
def PrepareOrTransactMsg( self,
23-
msg: Any,
22+
def PrepareOrTransactMsg( self,
23+
msg: Any,
2424
transact: bool = False,
2525
tx_params : TxParams = TxParams(),
2626
**kwargs):
2727
msg_args = {
2828
k: kwargs[k] for k in kwargs if k in ["address", "node_address", "id", "gigabytes", "hours", "rating", "denom"]
2929
}
30-
30+
3131
msg_args['frm'] = self.__account.address
3232
prepared_msg = msg(**msg_args)
3333

@@ -39,6 +39,9 @@ def transaction(
3939
messages: list,
4040
tx_params: TxParams = TxParams(),
4141
) -> dict:
42+
if self._account is None or self._client is None:
43+
raise ValueError("Transactor was not initialized due missing secret, unable to transact")
44+
4245
tx = Transaction(
4346
account=self._account,
4447
fee=Coin(denom=tx_params.denom, amount=f"{tx_params.fee_amount}"),
@@ -70,6 +73,9 @@ def transaction(
7073
def wait_transaction(
7174
self, tx_hash: str, timeout: float = 120, pool_period: float = 10
7275
):
76+
if self._account is None or self._client is None:
77+
raise ValueError("Transactor was not initialized due missing secret, unable to wait transaction")
78+
7379
start = time.time()
7480
while 1:
7581
try:

0 commit comments

Comments
 (0)