@@ -25,7 +25,7 @@ use scale_codec::{Decode, Encode};
2525// Substrate
2626use sc_client_api:: backend:: { Backend , StorageProvider } ;
2727use sc_transaction_pool:: { ChainApi , RCGroup } ;
28- use sp_api:: { ApiExt , CallApiAt , CallApiAtParams , ProvideRuntimeApi , StorageTransactionCache } ;
28+ use sp_api:: { ApiExt , BlockId , CallApiAt , CallApiAtParams , ProvideRuntimeApi , StorageTransactionCache } ;
2929use sp_block_builder:: BlockBuilder as BlockBuilderApi ;
3030use sp_blockchain:: HeaderBackend ;
3131use sp_core:: ExecutionContext ;
@@ -103,7 +103,7 @@ where
103103 )
104104 } ;
105105
106- let ( substrate_hash, api) = match frontier_backend_client:: native_block_id :: < B , C > (
106+ let ( substrate_hash, substrate_block_num , api) = match frontier_backend_client:: native_block_id :: < B , C > (
107107 self . client . as_ref ( ) ,
108108 self . backend . as_ref ( ) ,
109109 number,
@@ -115,13 +115,21 @@ where
115115 . client
116116 . expect_block_hash_from_id ( & id)
117117 . map_err ( |_| crate :: err ( JSON_RPC_ERROR_DEFAULT , "header not found" , None ) ) ?;
118- ( hash, self . client . runtime_api ( ) )
118+ let num = match id {
119+ BlockId :: Hash ( hash) => {
120+ self . client . number ( hash) . map_err ( |e| crate :: err ( JSON_RPC_ERROR_DEFAULT , e. to_string ( ) , None ) ) ?
121+ . ok_or ( crate :: err ( JSON_RPC_ERROR_DEFAULT , "Block number not found" , None ) ) ?
122+ } ,
123+ BlockId :: Number ( num) => num,
124+ } ;
125+ ( hash, num, self . client . runtime_api ( ) )
119126 }
120127 None => {
121128 // Not mapped in the db, assume pending.
122129 let hash = self . client . info ( ) . best_hash ;
130+ let num = self . client . info ( ) . best_number ;
123131 let api = pending_runtime_api ( self . client . as_ref ( ) , self . graph . as_ref ( ) ) ?;
124- ( hash, api)
132+ ( hash, num , api)
125133 }
126134 } ;
127135
@@ -134,7 +142,7 @@ where
134142 } ;
135143
136144 let block = if api_version > 1 {
137- api. current_block ( substrate_hash)
145+ api. current_block ( substrate_hash, substrate_block_num . saturated_into :: < u128 > ( ) . into ( ) )
138146 . map_err ( |err| internal_err ( format ! ( "runtime error: {:?}" , err) ) ) ?
139147 } else {
140148 #[ allow( deprecated) ]
0 commit comments