Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "sentinel_sdk"
version = "0.1.3"
version = "0.1.7"
description = "A Sentinel SDK Written in Python"
authors = [
{ name = "NAST0R" },
Expand Down
46 changes: 42 additions & 4 deletions src/sentinel_sdk/modules/lease.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Any

import grpc
import sentinel_protobuf.sentinel.lease.v1.lease_pb2 as lease_pb2
import sentinel_protobuf.sentinel.lease.v1.querier_pb2 as sentinel_subscription_v2_querier_pb2
import sentinel_protobuf.sentinel.lease.v1.querier_pb2_grpc as sentinel_subscription_v2_querier_pb2_grpc
import sentinel_protobuf.sentinel.subscription.v2.subscription_pb2 as subscription_pb2
import sentinel_protobuf.sentinel.lease.v1.querier_pb2 as sentinel_lease_v1_querier_pb2
import sentinel_protobuf.sentinel.lease.v1.querier_pb2_grpc as sentinel_lease_v1_querier_pb2_grpc
import sentinel_protobuf.sentinel.lease.v1.msg_pb2 as msg_pb2
from sentinel_protobuf.sentinel.types.v1.price_pb2 import Price
from sentinel_protobuf.sentinel.types.v1.renewal_pb2 import RenewalPricePolicy
Expand All @@ -14,13 +14,51 @@

class LeaseModule(Querier, Transactor):
def __init__(self, channel: grpc.Channel, account, provider_account, client):
self.__stub = sentinel_subscription_v2_querier_pb2_grpc.QueryServiceStub(
self.__stub = sentinel_lease_v1_querier_pb2_grpc.QueryServiceStub(
channel
)
self._account = account
self._client = client
self._provider_account = provider_account

def QueryLease(self, lease_id: int) -> Any:
try:
r = self.__stub.QuerySession(
sentinel_lease_v1_querier_pb2.QueryLeaseRequest(id=lease_id)
)
except grpc._channel._InactiveRpcError as e:
print(e)
return None

return r.session

def QueryLeases(self, pagination: PageRequest = None) -> list:
return self.QueryAll(
query=self.__stub.QueryLeases,
request=sentinel_lease_v1_querier_pb2.QueryLeasesRequest,
attribute="leases",
pagination=pagination,
)

def QueryNodeLeases(self, address: str, pagination: PageRequest = None) -> list:
return self.QueryAll(
query=self.__stub.QueryLeasesForNode,
request=sentinel_lease_v1_querier_pb2.QueryLeasesForNodeRequest,
attribute="leases",
address=address,
pagination=pagination,
)

def QueryProviderLeases(self, address: str, pagination: PageRequest = None) -> list:
return self.QueryAll(
query=self.__stub.QueryLeasesForProvider,
request=sentinel_lease_v1_querier_pb2.QueryLeasesForProviderRequest,
attribute="leases",
address=address,
pagination=pagination,
)


def EndLease(self, subscription_id: int, tx_params: TxParams = TxParams()):
msg = msg_pb2.MsgEndLeaseRequest(
frm = self._provider_account.address,
Expand Down