@@ -168,7 +168,9 @@ struct ChainProperties {
168168
169169/// Get the SS58 prefix from the chain
170170pub async fn get_ss58_prefix ( client : & Client ) -> Result < u16 , Error > {
171- match crate :: dynamic:: pallet_api:: system:: constants:: SS58_PREFIX . fetch ( client. chain_api ( ) ) {
171+ match crate :: dynamic:: pallet_api:: system:: constants:: SS58_PREFIX
172+ . fetch ( & * client. chain_api ( ) . await )
173+ {
172174 Ok ( ss58_prefix) => Ok ( ss58_prefix) ,
173175 Err ( e) => {
174176 log:: warn!( target: LOG_TARGET , "Failed to fetch SS58 prefix: {e}" ) ;
@@ -180,56 +182,38 @@ pub async fn get_ss58_prefix(client: &Client) -> Result<u16, Error> {
180182
181183/// Get block hash from block number using RPC
182184pub async fn get_block_hash ( client : & Client , block_number : u32 ) -> Result < Hash , Error > {
183- use serde_json :: { json , value :: to_raw_value } ;
185+ use subxt_rpcs :: { RpcClient , client :: RpcParams } ;
184186
185- // Convert block number to JSON raw value
186- let params = to_raw_value ( & json ! ( [ block_number] ) )
187+ let mut params = RpcParams :: new ( ) ;
188+ params
189+ . push ( block_number)
187190 . map_err ( |e| Error :: Other ( format ! ( "Failed to serialize block number: {e}" ) ) ) ?;
188191
189- // Make RPC request - params is already Box<RawValue>
190- let response = client
191- . rpc ( )
192- . request ( "chain_getBlockHash" . to_string ( ) , Some ( params) )
193- . await
194- . map_err ( |e| {
192+ let endpoint = client. current_endpoint ( ) . await ;
193+ let rpc_client = RpcClient :: from_url ( endpoint) . await ?;
194+
195+ let block_hash: Option < Hash > =
196+ rpc_client. request ( "chain_getBlockHash" , params) . await . map_err ( |e| {
195197 Error :: Other ( format ! ( "Failed to get block hash for block {block_number}: {e}" ) )
196198 } ) ?;
197199
198- // Parse response - it can be null if block doesn't exist
199- let response_str = response. get ( ) ;
200- if response_str == "null" {
201- return Err ( Error :: Other ( format ! (
202- "Block {block_number} not found (may be pruned or invalid)"
203- ) ) ) ;
204- }
205-
206- // Deserialize the hash
207- let block_hash: Option < Hash > = serde_json:: from_str ( response_str)
208- . map_err ( |e| Error :: Other ( format ! ( "Failed to parse block hash response: {e}" ) ) ) ?;
209-
210200 block_hash. ok_or_else ( || {
211201 Error :: Other ( format ! ( "Block {block_number} not found (may be pruned or invalid)" ) )
212202 } )
213203}
214204
215205/// Get chain properties (ss58 prefix, token decimals and symbol) from system_properties RPC
216206pub async fn get_chain_properties ( client : Client ) -> Result < ( u16 , u8 , String ) , Error > {
217- use serde_json :: { json , value :: to_raw_value } ;
207+ use subxt_rpcs :: { RpcClient , client :: RpcParams } ;
218208
219- // Call system_properties RPC method using the client's RPC
220- let params = to_raw_value ( & json ! ( [ ] ) )
221- . map_err ( |e| Error :: Other ( format ! ( "Failed to serialize RPC params: {e}" ) ) ) ?;
209+ let endpoint = client. current_endpoint ( ) . await ;
210+ let rpc_client = RpcClient :: from_url ( endpoint) . await ?;
222211
223- let response_raw = client
224- . rpc ( )
225- . request ( "system_properties" . to_string ( ) , Some ( params) )
212+ let response: ChainProperties = rpc_client
213+ . request ( "system_properties" , RpcParams :: new ( ) )
226214 . await
227215 . map_err ( |e| Error :: Other ( format ! ( "Failed to call system_properties RPC: {e}" ) ) ) ?;
228216
229- // Deserialize the response
230- let response: ChainProperties = serde_json:: from_str ( response_raw. get ( ) )
231- . map_err ( |e| Error :: Other ( format ! ( "Failed to parse system_properties response: {e}" ) ) ) ?;
232-
233217 // Extract token decimals
234218 let decimals = response. token_decimals . unwrap_or ( 10 ) ; // Default to 10 for most Substrate chains
235219
0 commit comments