From 923013628b8445268b30bef92efac651d3c80e43 Mon Sep 17 00:00:00 2001 From: Maciej Hirsz <1096222+maciejhirsz@users.noreply.github.com> Date: Thu, 19 Dec 2019 17:58:08 +0100 Subject: [PATCH] Add a method to fetch current finalized head hash (#57) * chore: Update to latest substrate master renames * feat: Introduce Client::finalized_head --- src/lib.rs | 6 ++++++ src/rpc.rs | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 7c6eaf51cc..000cfbe0f3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -207,6 +207,12 @@ impl Client { .and_then(|rpc| rpc.block_hash(hash.map(|h| h))) } + /// Get a block hash of the latest finalized block + pub fn finalized_head(&self) -> impl Future { + self.connect() + .and_then(|rpc| rpc.finalized_head()) + } + /// Get a block pub fn block( &self, diff --git a/src/rpc.rs b/src/rpc.rs index 33f506a45e..808ebd98f1 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -168,6 +168,13 @@ impl Rpc { }) } + /// Get a block hash of the latest finalized block + pub fn finalized_head(&self) -> impl Future { + self.chain + .finalized_head() + .map_err(Into::into) + } + /// Get a Block pub fn block( &self, @@ -286,7 +293,7 @@ impl Rpc { TransactionStatus::Future | TransactionStatus::Ready | TransactionStatus::Broadcast(_) => None, - TransactionStatus::Finalized(block_hash) => { + TransactionStatus::InBlock(block_hash) => { Some(Ok(block_hash)) } TransactionStatus::Usurped(_) => {