Skip to content

Commit 58d8379

Browse files
committed
Update node module for v3. Comment out v2 code
1 parent a772f3f commit 58d8379

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

src/sentinel_sdk/modules/node.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import hashlib
1111
import ecdsa
1212
import grpc
13-
import sentinel_protobuf.sentinel.node.v2.node_pb2 as node_pb2
14-
import sentinel_protobuf.sentinel.node.v2.querier_pb2 as sentinel_node_v2_querier_pb2
15-
import sentinel_protobuf.sentinel.node.v2.querier_pb2_grpc as sentinel_node_v2_querier_pb2_grpc
13+
import sentinel_protobuf.sentinel.node.v3.node_pb2 as node_pb2
14+
import sentinel_protobuf.sentinel.node.v3.querier_pb2 as sentinel_node_v3_querier_pb2
15+
import sentinel_protobuf.sentinel.node.v3.querier_pb2_grpc as sentinel_node_v3_querier_pb2_grpc
1616
import sentinel_protobuf.sentinel.node.v2.msg_pb2 as msg_pb2
1717
import sentinel_protobuf.sentinel.node.v3.msg_pb2 as msg_pb2_3
1818

@@ -26,7 +26,7 @@
2626
class NodeModule(Querier, Transactor):
2727
def __init__(self, channel: grpc.Channel, node_timeout: int, account, client):
2828
self.node_timeout = node_timeout
29-
self.__stub = sentinel_node_v2_querier_pb2_grpc.QueryServiceStub(channel)
29+
self.__stub = sentinel_node_v3_querier_pb2_grpc.QueryServiceStub(channel)
3030

3131
# Disable SSL verification
3232
self.__ssl_ctx = ssl.create_default_context()
@@ -39,26 +39,26 @@ def __init__(self, channel: grpc.Channel, node_timeout: int, account, client):
3939
self.__nodes_status_cache = {}
4040

4141
def QueryParams(self) -> Any:
42-
return self.__stub.QueryParams(sentinel_node_v2_querier_pb2.QueryParamsRequest()).params
42+
return self.__stub.QueryParams(sentinel_node_v3_querier_pb2.QueryParamsRequest()).params
4343

4444
def QueryNode(self, address: str) -> Any:
4545
r = self.__stub.QueryNode(
46-
sentinel_node_v2_querier_pb2.QueryNodeRequest(address=address)
46+
sentinel_node_v3_querier_pb2.QueryNodeRequest(address=address)
4747
)
4848
return r.node
4949

5050
def QueryNodes(self, status: int, pagination: PageRequest = None) -> list:
5151
return self.QueryAll(
5252
query=self.__stub.QueryNodes,
53-
request=sentinel_node_v2_querier_pb2.QueryNodesRequest,
53+
request=sentinel_node_v3_querier_pb2.QueryNodesRequest,
5454
attribute="nodes",
5555
status=status.value,
5656
pagination=pagination,
5757
)
5858

5959
def QueryNumOfNodesWithStatus(self, status: int) -> int:
6060
r = self.__stub.QueryNodes(
61-
sentinel_node_v2_querier_pb2.QueryNodesRequest(status=status.value)
61+
sentinel_node_v3_querier_pb2.QueryNodesRequest(status=status.value)
6262
)
6363
return r.pagination.total
6464

@@ -104,7 +104,7 @@ def QueryNodesForPlan(
104104
) -> list:
105105
return self.QueryAll(
106106
query=self.__stub.QueryNodesForPlan,
107-
request=sentinel_node_v2_querier_pb2.QueryNodesForPlanRequest,
107+
request=sentinel_node_v3_querier_pb2.QueryNodesForPlanRequest,
108108
attribute="nodes",
109109
status=status.value,
110110
id=plan_id,

src/sentinel_sdk/modules/plan.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,16 @@ def LinkNode(self, plan_id: int, node_address: str, tx_params: TxParams = TxPara
6666
node_address = node_address,
6767
)
6868
return self.transaction([msg], tx_params)
69-
69+
70+
'''
7071
def Subscribe(self, denom: str, plan_id: int, tx_params: TxParams = TxParams()):
7172
msg = msg_pb2.MsgSubscribeRequest(
7273
frm = self._account.address,
7374
id = plan_id,
7475
denom = denom,
7576
)
7677
return self.transaction([msg], tx_params)
78+
'''
7779

7880
def UnlinkNode(self, plan_id: int, node_address: str, tx_params: TxParams = TxParams()):
7981
msg = msg_pb2_3.MsgUnlinkNodeRequest(

src/sentinel_sdk/modules/subscription.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ def QuerySubscriptionsForPlan(
152152
self.__ConvertAnyToPlanSubscription(subscription.value)
153153
for subscription in subscriptions
154154
]
155-
155+
156+
# not in use anymore
157+
'''
156158
def Allocate(self, address: str, bytes: str, id: int, tx_params: TxParams = TxParams()):
157159
msg = msg_pb2.MsgAllocateRequest(
158160
frm = self._account.address,
@@ -162,7 +164,7 @@ def Allocate(self, address: str, bytes: str, id: int, tx_params: TxParams = TxPa
162164
)
163165
return self.transaction([msg], tx_params)
164166
165-
'''
167+
166168
def Cancel(self, id: int, tx_params: TxParams = TxParams()):
167169
msg = msg_pb2.MsgCancelRequest(
168170
frm = self._account.address,
@@ -171,19 +173,19 @@ def Cancel(self, id: int, tx_params: TxParams = TxParams()):
171173
return self.transaction([msg], tx_params)
172174
'''
173175

176+
# id is subscription id
174177
def Cancel(self, id: int, tx_params: TxParams = TxParams()):
175178
msg = msg_pb2_3.MsgCancelSubscriptionRequest(
176179
frm = self._account.address,
177180
id = id,
178181
)
179182
return self.transaction([msg], tx_params)
180183

181-
# Used for plan subs
182-
def StartSession(self, address: str, subscription_id: int, tx_params: TxParams = TxParams()):
183-
msg = msg_pb2_3.MsgStartSessionRequest(
184+
def RenewSubscription(self, subscription_id: int, denom: str, tx_params: TxParams = TxParams()):
185+
msg = msg_pb2_3.MsgRenewSubscriptionRequest(
184186
frm = self._account.address,
185187
id = subscription_id,
186-
node_address = address
188+
denom = denom,
187189
)
188190
return self.transaction([msg], tx_params)
189191

@@ -196,16 +198,7 @@ def ShareSubscription(self, subscription_id: int, wallet_address: str, bytes: st
196198
)
197199
return self.transaction([msg], tx_params)
198200

199-
def RenewSubscription(self, subscription_id: int, denom: str, tx_params: TxParams = TxParams()):
200-
msg = msg_pb2_3.MsgRenewSubscriptionRequest(
201-
frm = self._account.address,
202-
id = subscription_id,
203-
denom = denom,
204-
)
205-
return self.transaction([msg], tx_params)
206-
207201
# id is plan_id
208-
209202
def StartSubscription(self, plan_id: int, denom: str, renewal: int = RenewalPricePolicy.RENEWAL_PRICE_POLICY_IF_LESSER_OR_EQUAL, tx_params: TxParams = TxParams()):
210203
msg = msg_pb2_3.MsgStartSubscriptionRequest(
211204
frm = self._account.address,
@@ -222,6 +215,16 @@ def UpdateSubscription(self, subscription_id: int, renewal: int = RenewalPriceP
222215
renewal_price_policy = renewal,
223216
)
224217
return self.transaction([msg], tx_params)
218+
219+
# Used for plan subs
220+
def StartSession(self, address: str, subscription_id: int, tx_params: TxParams = TxParams()):
221+
msg = msg_pb2_3.MsgStartSessionRequest(
222+
frm = self._account.address,
223+
id = subscription_id,
224+
node_address = address
225+
)
226+
return self.transaction([msg], tx_params)
227+
225228
# Node subscriptions are returned by grpc querier in google's 'Any' type and need to be converted into desired protobuf type
226229
#
227230
#

0 commit comments

Comments
 (0)