@@ -142,7 +142,22 @@ impl<Block: BlockT + DeserializeOwned> Blockchain<Block> {
142
142
pub fn id ( & self , id : BlockId < Block > ) -> Option < Block :: Hash > {
143
143
match id {
144
144
BlockId :: Hash ( h) => Some ( h) ,
145
- BlockId :: Number ( n) => self . storage . read ( ) . hashes . get ( & n) . cloned ( ) ,
145
+ BlockId :: Number ( n) => {
146
+ let block_hash = self . storage . read ( ) . hashes . get ( & n) . cloned ( ) ;
147
+ match block_hash {
148
+ None => {
149
+ let block_hash =
150
+ self . rpc_client . block_hash :: < Block > ( Some ( n) ) . ok ( ) . flatten ( ) ;
151
+
152
+ block_hash. clone ( ) . map ( |h| {
153
+ self . storage . write ( ) . hashes . insert ( n, h) ;
154
+ } ) ;
155
+
156
+ block_hash
157
+ }
158
+ block_hash => block_hash,
159
+ }
160
+ }
146
161
}
147
162
}
148
163
@@ -1506,17 +1521,17 @@ impl RPC {
1506
1521
1507
1522
pub fn block_hash < Block : BlockT + DeserializeOwned > (
1508
1523
& self ,
1509
- block_number : Option < BlockNumber > ,
1524
+ block_number : Option < < Block :: Header as HeaderT > :: Number > ,
1510
1525
) -> Result < Option < Block :: Hash > , jsonrpsee:: core:: ClientError > {
1511
1526
let request = & || {
1512
1527
substrate_rpc_client:: ChainApi :: <
1513
- BlockNumber ,
1528
+ < Block :: Header as HeaderT > :: Number ,
1514
1529
Block :: Hash ,
1515
1530
Block :: Header ,
1516
1531
SignedBlock < Block > ,
1517
1532
> :: block_hash (
1518
1533
& self . http_client ,
1519
- block_number. map ( |n| ListOrValue :: Value ( NumberOrHex :: Number ( n. into ( ) ) ) ) ,
1534
+ block_number. map ( |n| ListOrValue :: Value ( NumberOrHex :: Hex ( n. into ( ) ) ) ) ,
1520
1535
)
1521
1536
} ;
1522
1537
0 commit comments