mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 22:07:58 +00:00
chain-api subsystem: implement BlockHeader messsage (#1778)
* chain-api subsystem: implement BlockHeader messsage * update the guide
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
//!
|
||||
//! Supported requests:
|
||||
//! * Block hash to number
|
||||
//! * Block hash to header
|
||||
//! * Finalized block number to hash
|
||||
//! * Last finalized block number
|
||||
//! * Ancestors
|
||||
@@ -85,6 +86,13 @@ where
|
||||
subsystem.metrics.on_request(result.is_ok());
|
||||
let _ = response_channel.send(result);
|
||||
},
|
||||
ChainApiMessage::BlockHeader(hash, response_channel) => {
|
||||
let result = subsystem.client
|
||||
.header(BlockId::Hash(hash))
|
||||
.map_err(|e| e.to_string().into());
|
||||
subsystem.metrics.on_request(result.is_ok());
|
||||
let _ = response_channel.send(result);
|
||||
},
|
||||
ChainApiMessage::FinalizedBlockHash(number, response_channel) => {
|
||||
// Note: we don't verify it's finalized
|
||||
let result = subsystem.client.hash(number).map_err(|e| e.to_string().into());
|
||||
@@ -319,6 +327,30 @@ mod tests {
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn request_block_header() {
|
||||
test_harness(|client, mut sender| {
|
||||
async move {
|
||||
const NOT_HERE: Hash = Hash::repeat_byte(0x5);
|
||||
let test_cases = [
|
||||
(TWO, client.header(BlockId::Hash(TWO)).unwrap()),
|
||||
(NOT_HERE, client.header(BlockId::Hash(NOT_HERE)).unwrap()),
|
||||
];
|
||||
for (hash, expected) in &test_cases {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
|
||||
sender.send(FromOverseer::Communication {
|
||||
msg: ChainApiMessage::BlockHeader(*hash, tx),
|
||||
}).await;
|
||||
|
||||
assert_eq!(rx.await.unwrap().unwrap(), *expected);
|
||||
}
|
||||
|
||||
sender.send(FromOverseer::Signal(OverseerSignal::Conclude)).await;
|
||||
}.boxed()
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn request_finalized_hash() {
|
||||
test_harness(|client, mut sender| {
|
||||
|
||||
Reference in New Issue
Block a user