44import bech32
55import aiohttp
66import json
7+ import requests
78from typing import Tuple
89from bech32 import bech32_encode , bech32_decode , convertbits
910from bip32 import BIP32
@@ -262,7 +263,7 @@ def get_subaccount_id(self, index: int) -> str:
262263 id = index .to_bytes (12 , byteorder = 'big' ).hex ()
263264 return '0x' + self .addr .hex () + id
264265
265- async def init_num_seq (self , lcd_endpoint : str ) -> "Address" :
266+ async def async_init_num_seq (self , lcd_endpoint : str ) -> "Address" :
266267 async with aiohttp .ClientSession () as session :
267268 async with session .request (
268269 'GET' , lcd_endpoint + '/cosmos/auth/v1beta1/accounts/' + self .to_acc_bech32 (),
@@ -278,6 +279,17 @@ async def init_num_seq(self, lcd_endpoint: str) -> "Address":
278279 self .sequence = int (acc ['sequence' ])
279280 return self
280281
282+ def init_num_seq (self , lcd_endpoint : str )-> "Address" :
283+ response = requests .get (f"{ lcd_endpoint } /cosmos/auth/v1beta1/accounts/{ self .to_acc_bech32 ()} " ,
284+ headers = {'Accept-Encoding' : 'application/json' })
285+ if response .status_code != 200 :
286+ raise ValueError ("HTTP response status" , response .status_code )
287+ resp = json .loads (response .text )
288+ acc = resp ['account' ]['base_account' ]
289+ self .number = int (acc ['account_number' ])
290+ self .sequence = int (acc ['sequence' ])
291+ return self
292+
281293 def get_sequence (self ):
282294 current_seq = self .sequence
283295 self .sequence += 1
0 commit comments