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