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
6 changes: 3 additions & 3 deletions 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.0.5"
version = "0.1.3"
description = "A Sentinel SDK Written in Python"
authors = [
{ name = "NAST0R" },
Expand All @@ -13,7 +13,7 @@ authors = [
]
readme = "README.md"
requires-python = ">=3.10"
keywords = ["sentinel_sdk", "mospy", "sentinel", "cosmos", "protobuf", "sentinel_protobuf"]
keywords = ["sentinel_sdk", "mospy", "sentinel", "dvpn", "cosmos", "protobuf", "sentinel_protobuf"]
license = {text = "GPL-3.0 license"}
classifiers = [
"Development Status :: 3 - Alpha",
Expand All @@ -22,7 +22,7 @@ classifiers = [
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
]
dependencies = [
"sentinel-protobuf==0.3.3",
"sentinel-protobuf==0.5.1",
"grpcio>=1.51.1",
"bip-utils==2.9.0",
"mospy-wallet==0.6.0",
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sentinel-protobuf==0.3.3
sentinel-protobuf==0.4.3
grpcio>=1.51.1
bip-utils==2.9.0
mospy-wallet @ git+https://github.com/Tkd-Alex/mospy.git@development
mospy-wallet==0.6.0
65 changes: 65 additions & 0 deletions src/sentinel_sdk/modules/lease.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

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.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

from sentinel_sdk.querier.querier import Querier
from sentinel_sdk.transactor.transactor import Transactor
from sentinel_sdk.types import PageRequest, TxParams

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

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

return self.transaction([msg], tx_params)

def RenewLease(self, subscription_id: int, hours: int, max_price: Price = Price, tx_params: TxParams = TxParams()):
msg = msg_pb2.MsgRenewLeaseRequest(
frm = self._provider_account.address,
id = subscription_id,
hours = hours,
max_price = max_price,
)

return self.transaction([msg], tx_params)

def StartLease(self, node: str, hours: int, max_price: Price, renewal: int = RenewalPricePolicy.RENEWAL_PRICE_POLICY_IF_LESSER_OR_EQUAL, tx_params: TxParams = TxParams()):
msg = msg_pb2.MsgStartLeaseRequest(
frm = self._provider_account.address,
node_address = node,
hours = hours,
max_price = max_price,
renewal_price_policy = renewal,
)

return self.transaction([msg], tx_params)

def UpdateLease(self, subscription_id: int, renewal: int = RenewalPricePolicy.RENEWAL_PRICE_POLICY_IF_LESSER_OR_EQUAL, tx_params: TxParams = TxParams()):
msg = msg_pb2.MsgUpdateLeaseRequest(
frm = self._provider_account.address,
id = subscription_id,
renewal_price_policy = renewal,
)

return self.transaction([msg], tx_params)





64 changes: 44 additions & 20 deletions src/sentinel_sdk/modules/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import hashlib
import ecdsa
import grpc
import sentinel_protobuf.sentinel.node.v2.node_pb2 as node_pb2
import sentinel_protobuf.sentinel.node.v2.querier_pb2 as sentinel_node_v2_querier_pb2
import sentinel_protobuf.sentinel.node.v2.querier_pb2_grpc as sentinel_node_v2_querier_pb2_grpc
import sentinel_protobuf.sentinel.node.v3.node_pb2 as node_pb2
import sentinel_protobuf.sentinel.node.v3.querier_pb2 as sentinel_node_v3_querier_pb2
import sentinel_protobuf.sentinel.node.v3.querier_pb2_grpc as sentinel_node_v3_querier_pb2_grpc
import sentinel_protobuf.sentinel.node.v2.msg_pb2 as msg_pb2
import sentinel_protobuf.sentinel.node.v3.msg_pb2 as msg_pb2_3
from sentinel_protobuf.sentinel.types.v1.price_pb2 import Price

from sentinel_sdk.querier.querier import Querier
from sentinel_sdk.transactor.transactor import Transactor
Expand All @@ -25,7 +27,7 @@
class NodeModule(Querier, Transactor):
def __init__(self, channel: grpc.Channel, node_timeout: int, account, client):
self.node_timeout = node_timeout
self.__stub = sentinel_node_v2_querier_pb2_grpc.QueryServiceStub(channel)
self.__stub = sentinel_node_v3_querier_pb2_grpc.QueryServiceStub(channel)

# Disable SSL verification
self.__ssl_ctx = ssl.create_default_context()
Expand All @@ -36,48 +38,71 @@ def __init__(self, channel: grpc.Channel, node_timeout: int, account, client):
self._client = client

self.__nodes_status_cache = {}

def QueryParams(self) -> Any:
return self.__stub.QueryParams(sentinel_node_v2_querier_pb2.QueryParamsRequest()).params

return self.__stub.QueryParams(sentinel_node_v3_querier_pb2.QueryParamsRequest()).params
def QueryNode(self, address: str) -> Any:
r = self.__stub.QueryNode(
sentinel_node_v2_querier_pb2.QueryNodeRequest(address=address)
sentinel_node_v3_querier_pb2.QueryNodeRequest(address=address)
)
return r.node

def QueryNodes(self, status: int, pagination: PageRequest = None) -> list:
return self.QueryAll(
query=self.__stub.QueryNodes,
request=sentinel_node_v2_querier_pb2.QueryNodesRequest,
request=sentinel_node_v3_querier_pb2.QueryNodesRequest,
attribute="nodes",
status=status.value,
pagination=pagination,
)

def QueryNumOfNodesWithStatus(self, status: int) -> int:
r = self.__stub.QueryNodes(
sentinel_node_v2_querier_pb2.QueryNodesRequest(status=status.value)
sentinel_node_v3_querier_pb2.QueryNodesRequest(status=status.value)
)
return r.pagination.total

def QueryNodeStatus(self, node: node_pb2.Node, is_in_thread: bool = False) -> str:
node_endpoint = node.remote_url
node_endpoint = "https://" + node.remote_addrs[0]
gb_price = ""
hr_price = ""
if node.gigabyte_prices:
for prices in node.gigabyte_prices:
gb_price = gb_price + prices.quote_value + prices.denom + ','
else:
gb_price = "0udvpn"
if node.hourly_prices:
for prices in node.hourly_prices:
hr_price = hr_price + prices.quote_value + prices.denom + ','
else:
hr_price = "0udvpn"

gb_price = gb_price.rstrip(',')
hr_price = hr_price.rstrip(',')
print(f"GB Prices: {gb_price}\n Hourly Prices: {hr_price}")
print(f"Node Endpoint: {node_endpoint}")
try:
contents = urllib.request.urlopen(
f"{node_endpoint}/status",
f"{node_endpoint}",
context=self.__ssl_ctx,
timeout=self.node_timeout,
).read()
contents = contents.decode("utf-8")
except urllib.error.URLError:
except urllib.error.URLError as E:
print(str(E))
contents = '{"success":false,"urllib-error":"URLError encountered"}'
except TimeoutError:
contents = '{"success":false,"urllib-error":"Data reading timed out"}'
except http.client.RemoteDisconnected:
contents = '{"success":false,"http-error":"Remote endpoint closed connection"}'
except:
contents = '{"success":false,"error":"Unrecognizable error encountered"}'
contents = json.loads(contents)
contents['gigabyte_prices'] = gb_price
contents['hourly_prices'] = hr_price
contents = json.dumps(contents)

if is_in_thread:
self.__nodes_status_cache[node.address] = contents
else:
Expand All @@ -103,7 +128,7 @@ def QueryNodesForPlan(
) -> list:
return self.QueryAll(
query=self.__stub.QueryNodesForPlan,
request=sentinel_node_v2_querier_pb2.QueryNodesForPlanRequest,
request=sentinel_node_v3_querier_pb2.QueryNodesForPlanRequest,
attribute="nodes",
status=status.value,
id=plan_id,
Expand All @@ -128,17 +153,16 @@ def RegisterNode(self, gigabyte_prices: int, hourly_prices: int, remote_url: str
remote_url=remote_url,
)
return self.transaction([msg], tx_params)

def SubscribeToNode(self, node_address: str, gigabytes: int = 0, hours: int = 0, denom: str = "udvpn", tx_params: TxParams = TxParams()):
msg = msg_pb2.MsgSubscribeRequest(
def SubscribeToNode(self, node_address: str, price: Price, gigabytes: int = 0, hours: int = 0, next_sequence: bool = False, tx_params: TxParams = TxParams()):
msg = msg_pb2_3.MsgStartSessionRequest(
frm = self._account.address,
denom = denom,
gigabytes = gigabytes,
hours = hours,
node_address = node_address,
max_price = price,
)
return self.transaction([msg], tx_params)

return self.transaction([msg], tx_params, next_sequence)
def UpdateNodeDetails(self, gigabyte_prices: int, hourly_prices: int, remote_url: str, tx_params: TxParams = TxParams()):
msg = msg_pb2.MsgUpdateDetailsRequest(
frm = self._account.address,
Expand Down
9 changes: 6 additions & 3 deletions src/sentinel_sdk/modules/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sentinel_protobuf.sentinel.plan.v2.querier_pb2 as sentinel_plan_v2_querier_pb2
import sentinel_protobuf.sentinel.plan.v2.querier_pb2_grpc as sentinel_plan_v2_querier_pb2_grpc
import sentinel_protobuf.sentinel.plan.v2.msg_pb2 as msg_pb2
import sentinel_protobuf.sentinel.plan.v3.msg_pb2 as msg_pb2_3

from sentinel_sdk.querier.querier import Querier
from sentinel_sdk.transactor.transactor import Transactor
Expand Down Expand Up @@ -59,23 +60,25 @@ def Create(self, duration: int, gigabytes: int, prices: int, tx_params: TxParams
return self.transaction([msg], tx_params)

def LinkNode(self, plan_id: int, node_address: str, tx_params: TxParams = TxParams()):
msg = msg_pb2.MsgLinkNodeRequest(
msg = msg_pb2_3.MsgLinkNodeRequest(
frm = self._provider_account.address,
id = plan_id,
node_address = node_address,
)
return self.transaction([msg], tx_params)


'''
def Subscribe(self, denom: str, plan_id: int, tx_params: TxParams = TxParams()):
msg = msg_pb2.MsgSubscribeRequest(
frm = self._account.address,
id = plan_id,
denom = denom,
)
return self.transaction([msg], tx_params)
'''

def UnlinkNode(self, plan_id: int, node_address: str, tx_params: TxParams = TxParams()):
msg = msg_pb2.MsgUnlinkNodeRequest(
msg = msg_pb2_3.MsgUnlinkNodeRequest(
frm = self._provider_account.address,
id = plan_id,
node_address = node_address,
Expand Down
Loading