feat(network): add an extra ergonomic method for n2c chainsync (#439)
This commit is contained in:
parent
9e7cafbcac
commit
a1e18833d6
2 changed files with 15 additions and 1 deletions
|
|
@ -96,7 +96,7 @@ async fn do_chainsync(client: &mut NodeClient) {
|
||||||
info!("intersected point is {:?}", point);
|
info!("intersected point is {:?}", point);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let next = client.chainsync().request_next().await.unwrap();
|
let next = client.chainsync().request_or_await_next().await.unwrap();
|
||||||
match next {
|
match next {
|
||||||
chainsync::NextResponse::RollForward(h, _) => {
|
chainsync::NextResponse::RollForward(h, _) => {
|
||||||
let block_number = MultiEraBlock::decode(&h).unwrap().number();
|
let block_number = MultiEraBlock::decode(&h).unwrap().number();
|
||||||
|
|
|
||||||
|
|
@ -280,6 +280,20 @@ where
|
||||||
self.recv_while_can_await().await
|
self.recv_while_can_await().await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Either requests the next block, or waits for one to become available.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// Returns an error if the message cannot be sent, or if the inbound
|
||||||
|
/// message is invalid
|
||||||
|
pub async fn request_or_await_next(&mut self) -> Result<NextResponse<O>, ClientError> {
|
||||||
|
if self.has_agency() {
|
||||||
|
self.request_next().await
|
||||||
|
} else {
|
||||||
|
self.recv_while_must_reply().await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Attempt to intersect the chain at its origin (genesis block)
|
/// Attempt to intersect the chain at its origin (genesis block)
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue