Skip to content

Commit 98818b3

Browse files
committed
Update plan, node, subscription modules. Create lease module. At renewal policy to types.
1 parent 7ddfa28 commit 98818b3

File tree

4 files changed

+125
-5
lines changed

4 files changed

+125
-5
lines changed

src/sentinel_sdk/modules/lease.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
import grpc
3+
import sentinel_protobuf.sentinel.leace.v1.lease_pb2 as lease_pb2
4+
import sentinel_protobuf.sentinel.lease.v1.querier_pb2 as sentinel_subscription_v2_querier_pb2
5+
import sentinel_protobuf.sentinel.lease.v1.querier_pb2_grpc as sentinel_subscription_v2_querier_pb2_grpc
6+
import sentinel_protobuf.sentinel.subscription.v2.subscription_pb2 as subscription_pb2
7+
import sentinel_protobuf.sentinel.lease.v1.msg_pb2 as msg_pb2
8+
9+
from sentinel_sdk.querier.querier import Querier
10+
from sentinel_sdk.transactor.transactor import Transactor
11+
from sentinel_sdk.types import PageRequest, TxParams, Price, RenewalPricePolicy
12+
13+
class LeaseModule(Querier, Transactor):
14+
def __init__(self, channel: grpc.Channel, account, provider_account, client):
15+
self.__stub = sentinel_subscription_v2_querier_pb2_grpc.QueryServiceStub(
16+
channel
17+
)
18+
self._account = account
19+
self._client = client
20+
self._provider_account = provider_account
21+
22+
def EndLease(self, subscription_id: int, tx_params: TxParams = TxParams()):
23+
msg = msg_pb2.MsgSubscribeRequest(
24+
frm = self._account.address,
25+
id = subscription_id,
26+
)
27+
28+
return self.transaction([msg], tx_params)
29+
30+
def RenewLease(self, subscription_id: int, hours: int, max_price: Price = Price(), tx_params: TxParams = TxParams()):
31+
msg = msg_pb2.MsgSubscribeRequest(
32+
frm = self._account.address,
33+
id = subscription_id,
34+
hours = hours,
35+
max_price = max_price,
36+
)
37+
38+
return self.transaction([msg], tx_params)
39+
40+
def StartLease(self, node: str, hours: int, max_price: Price = Price(), renewal: int = RenewalPricePolicy.RENEWAL_PRICE_POLICY_IF_LESSER_OR_EQUAL, tx_params: TxParams = TxParams()):
41+
msg = msg_pb2.MsgSubscribeRequest(
42+
frm = self._account.address,
43+
node_address = node,
44+
hours = hours,
45+
max_price = max_price,
46+
renewal_price_policy = renewal,
47+
)
48+
49+
return self.transaction([msg], tx_params)
50+
51+
def UpdateLease(self, subscription_id: int, renewal: int = RenewalPricePolicy.RENEWAL_PRICE_POLICY_IF_LESSER_OR_EQUAL, tx_params: TxParams = TxParams()):
52+
msg = msg_pb2.MsgSubscribeRequest(
53+
frm = self._account.address,
54+
id = subscription_id,
55+
renewal_price_policy = renewal,
56+
)
57+
58+
return self.transaction([msg], tx_params)
59+
60+
61+
62+
63+

src/sentinel_sdk/modules/plan.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sentinel_protobuf.sentinel.plan.v2.querier_pb2 as sentinel_plan_v2_querier_pb2
55
import sentinel_protobuf.sentinel.plan.v2.querier_pb2_grpc as sentinel_plan_v2_querier_pb2_grpc
66
import sentinel_protobuf.sentinel.plan.v2.msg_pb2 as msg_pb2
7+
import sentinel_protobuf.sentinel.plan.v3.msg_pb2 as msg_pb2_3
78

89
from sentinel_sdk.querier.querier import Querier
910
from sentinel_sdk.transactor.transactor import Transactor
@@ -59,7 +60,7 @@ def Create(self, duration: int, gigabytes: int, prices: int, tx_params: TxParams
5960
return self.transaction([msg], tx_params)
6061

6162
def LinkNode(self, plan_id: int, node_address: str, tx_params: TxParams = TxParams()):
62-
msg = msg_pb2.MsgLinkNodeRequest(
63+
msg = msg_pb2_3.MsgLinkNodeRequest(
6364
frm = self._provider_account.address,
6465
id = plan_id,
6566
node_address = node_address,
@@ -75,7 +76,7 @@ def Subscribe(self, denom: str, plan_id: int, tx_params: TxParams = TxParams()):
7576
return self.transaction([msg], tx_params)
7677

7778
def UnlinkNode(self, plan_id: int, node_address: str, tx_params: TxParams = TxParams()):
78-
msg = msg_pb2.MsgUnlinkNodeRequest(
79+
msg = msg_pb2_3.MsgUnlinkNodeRequest(
7980
frm = self._provider_account.address,
8081
id = plan_id,
8182
node_address = node_address,

src/sentinel_sdk/modules/subscription.py

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from sentinel_sdk.querier.querier import Querier
1111
from sentinel_sdk.transactor.transactor import Transactor
12-
from sentinel_sdk.types import PageRequest, TxParams
12+
from sentinel_sdk.types import PageRequest, TxParams, RenewalPricePolicy
1313

1414

1515
class SubscriptionModule(Querier, Transactor):
@@ -162,18 +162,64 @@ def Allocate(self, address: str, bytes: str, id: int, tx_params: TxParams = TxPa
162162
)
163163
return self.transaction([msg], tx_params)
164164

165+
'''
165166
def Cancel(self, id: int, tx_params: TxParams = TxParams()):
166167
msg = msg_pb2.MsgCancelRequest(
167168
frm = self._account.address,
168169
id = id,
169170
)
170171
return self.transaction([msg], tx_params)
171-
172+
'''
173+
174+
def Cancel(self, id: int, tx_params: TxParams = TxParams()):
175+
msg = msg_pb2_3.MsgCancelSubscriptionRequest(
176+
frm = self._account.address,
177+
id = id,
178+
)
179+
return self.transaction([msg], tx_params)
180+
181+
# Used for plan subs
172182
def StartSession(self, address: str, subscription_id: int, tx_params: TxParams = TxParams()):
173183
msg = msg_pb2_3.MsgStartSessionRequest(
174184
frm = self._account.address,
175185
id = subscription_id,
176-
address = address
186+
node_address = address
187+
)
188+
return self.transaction([msg], tx_params)
189+
190+
def ShareSubscription(self, subscription_id: int, wallet_address: str, bytes: str, tx_params: TxParams = TxParams()):
191+
msg = msg_pb2_3.MsgShareSubscriptionRequest(
192+
frm = self._account.address,
193+
id = subscription_id,
194+
acc_address = address,
195+
bytes = bytes,
196+
)
197+
return self.transaction([msg], tx_params)
198+
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+
207+
# id is plan_id
208+
209+
def StartSubscription(self, plan_id: int, denom: str, renewal: int = RenewalPricePolicy.RENEWAL_PRICE_POLICY_IF_LESSER_OR_EQUAL, tx_params: TxParams = TxParams()):
210+
msg = msg_pb2_3.MsgStartSubscriptionRequest(
211+
frm = self._account.address,
212+
id = plan_id,
213+
denom = denom,
214+
renewal_price_polilcy = renewal,
215+
)
216+
return self.transaction([msg], tx_params)
217+
218+
def UpdateSubscription(self, subscription_id: int, renewal: int = RenewalPricePolicy.RENEWAL_PRICE_POLICY_IF_LESSER_OR_EQUAL, tx_params: TxParams = TxParams()):
219+
msg = msg_pb2_3.MsgUpdateSubscriptionRequest(
220+
frm = self._account.address,
221+
id = id,
222+
renewal_price_policy = renewal,
177223
)
178224
return self.transaction([msg], tx_params)
179225
# Node subscriptions are returned by grpc querier in google's 'Any' type and need to be converted into desired protobuf type

src/sentinel_sdk/types.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ class NodeType(Enum):
1919
WIREGUARD = 1
2020
V2RAY = 2
2121

22+
class RenewalPricePolicy(Enum):
23+
RENEWAL_PRICE_POLICY_UNSPECIFIED = 0
24+
RENEWAL_PRICE_POLICY_IF_LESSER = 1
25+
RENEWAL_PRICE_POLICY_IF_LESSER_OR_EQUAL = 2
26+
RENEWAL_PRICE_POLICY_IF_EQUAL = 3
27+
RENEWAL_PRICE_POLICY_IF_NOT_EQUAL = 4
28+
RENEWAL_PRICE_POLICY_IF_GREATER = 5
29+
RENEWAL_PRICE_POLICY_IF_GREATER_OR_EQUAL = 6
30+
RENEWAL_PRICE_POLICY_ALWAYS = 7
31+
2232
@dataclass
2333
class TxParams:
2434
denom: str = "udvpn"

0 commit comments

Comments
 (0)