Skip to content

Commit dcddc90

Browse files
committed
Created _provider_account. Edit PlanModule to handle sentprov... from _provider_account
1 parent 311e6f2 commit dcddc90

File tree

5 files changed

+56
-6
lines changed

5 files changed

+56
-6
lines changed

.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>sentinel-python-sdk</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.python.pydev.PyDevBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.python.pydev.pythonNature</nature>
16+
</natures>
17+
</projectDescription>

.pydevproject

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<?eclipse-pydev version="1.0"?><pydev_project>
3+
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
4+
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property>
5+
</pydev_project>

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "sentinel_sdk"
7-
version = "0.0.1"
7+
version = "0.0.2"
88
description = "A Sentinel SDK Written in Python"
99
authors = [
1010
{ name = "NAST0R" },

src/sentinel_sdk/modules/plan.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212

1313
class PlanModule(Querier, Transactor):
14-
def __init__(self, channel: grpc.Channel, account, client):
14+
def __init__(self, channel: grpc.Channel, account, provider_account, client):
1515
self.__stub = sentinel_plan_v2_querier_pb2_grpc.QueryServiceStub(channel)
1616
self._account = account
17+
self._provider_account = provider_account
1718
self._client = client
1819

1920
def QueryPlan(self, plan_id: int) -> Any:
@@ -59,7 +60,7 @@ def Create(self, duration: int, gigabytes: int, prices: int, tx_params: TxParams
5960

6061
def LinkNode(self, plan_id: int, node_address: str, tx_params: TxParams = TxParams()):
6162
msg = msg_pb2.MsgLinkNodeRequest(
62-
frm = self._account.address,
63+
frm = self._provider_account.address,
6364
id = plan_id,
6465
node_address = node_address,
6566
)
@@ -75,15 +76,15 @@ def Subscribe(self, denom: str, plan_id: int, tx_params: TxParams = TxParams()):
7576

7677
def UnlinkNode(self, plan_id: int, node_address: str, tx_params: TxParams = TxParams()):
7778
msg = msg_pb2.MsgUnlinkNodeRequest(
78-
frm = self._account.address,
79+
frm = self._provider_account.address,
7980
id = plan_id,
8081
node_address = node_address,
8182
)
8283
return self.transaction([msg], tx_params)
8384

8485
def UpdateStatus(self, plan_id: int, status: int, tx_params: TxParams = TxParams()):
8586
msg = msg_pb2.MsgUpdateStatusRequest(
86-
frm = self._account.address,
87+
frm = self._provider_account.address,
8788
id = plan_id,
8889
status = status,
8990
)

src/sentinel_sdk/sdk.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def __create_and_verify_channel(
5959

6060
def __setup_account_and_client(self, grpcaddr: str, grpcport: int, secret: str, use_ssl: bool = False):
6161
self._account = self.__create_account(secret)
62+
self._provider_account = self.__create_provider_account(secret)
6263
self._client = self.__create_client(grpcaddr, grpcport, use_ssl)
6364
self._client.load_account_data(account=self._account)
6465

@@ -87,6 +88,32 @@ def __create_account(self, secret: str):
8788
protobuf="sentinel",
8889
)
8990
return account
91+
92+
def __create_provider_account(self, secret: str):
93+
try:
94+
Bip39MnemonicValidator().Validate(secret)
95+
seed_bytes = Bip39SeedGenerator(secret).Generate()
96+
bip44_def_ctx = Bip44.FromSeed(seed_bytes, Bip44Coins.COSMOS).DeriveDefaultPath()
97+
except:
98+
try:
99+
int(secret, 16)
100+
bip44_def_ctx = Bip44.FromPrivateKey(bytes.fromhex(secret), Bip44Coins.COSMOS)
101+
except:
102+
raise ValueError("Unrecognized secret either as a mnemonic or hex private key")
103+
104+
sha_key = SHA256.new()
105+
ripemd_key = RIPEMD160.new()
106+
sha_key.update(bip44_def_ctx.PublicKey().RawCompressed().m_data_bytes)
107+
ripemd_key.update(sha_key.digest())
108+
bech32_pub = Bech32Encoder.Encode("sent", ripemd_key.digest())
109+
account_num = self.__get_account_number(bech32_pub)
110+
account = Account(
111+
private_key=bip44_def_ctx.PrivateKey().Raw().ToHex(),
112+
hrp="sentprov",
113+
account_number=account_num,
114+
protobuf="sentinel",
115+
)
116+
return account
90117

91118
def __create_client(self, grpcaddr: str, grpcport: int, use_ssl: bool = False):
92119
client = GRPCClient(
@@ -109,7 +136,7 @@ def __get_account_number(self, address: str):
109136
def __load_modules(self):
110137
self.nodes = NodeModule(self._channel, 10, self._account, self._client)
111138
self.deposits = DepositModule(self._channel)
112-
self.plans = PlanModule(self._channel, self._account, self._client)
139+
self.plans = PlanModule(self._channel, self._account, self._provider_account, self._client)
113140
self.providers = ProviderModule(self._channel, self._account, self._client)
114141
self.sessions = SessionModule(self._channel, self._account, self._client)
115142
self.subscriptions = SubscriptionModule(self._channel, self._account, self._client)

0 commit comments

Comments
 (0)