mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 19:01:08 +00:00
rpc: Fetch chainHead genesis hash
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
@@ -28,6 +28,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Create a client to use:
|
||||
let api = OnlineClient::<PolkadotConfig>::new().await?;
|
||||
|
||||
let genesis = api.rpc().get_chainhead_genesis_hash().await?;
|
||||
println!("Genesis: {:?}", genesis);
|
||||
|
||||
let mut follow_sub = api.blocks().subscribe_chainhead_finalized(true).await?;
|
||||
// Handle all subscriptions from the `chainHead_follow`.
|
||||
while let Some(block) = follow_sub.next().await {
|
||||
|
||||
@@ -81,8 +81,6 @@ where
|
||||
if let Some(event) = sub.next().await {
|
||||
let event = event?;
|
||||
|
||||
println!("Got event: {:?}", event);
|
||||
|
||||
return match event {
|
||||
ChainHeadEvent::Done(ChainHeadResult { result }) => {
|
||||
let bytes = hex::decode(result.trim_start_matches("0x"))
|
||||
@@ -148,8 +146,6 @@ where
|
||||
if let Some(event) = sub.next().await {
|
||||
let event = event?;
|
||||
|
||||
println!("Got event: {:?}", event);
|
||||
|
||||
return match event {
|
||||
ChainHeadEvent::Done(ChainHeadResult { result }) => {
|
||||
let result = match result {
|
||||
@@ -195,8 +191,6 @@ where
|
||||
if let Some(event) = sub.next().await {
|
||||
let event = event?;
|
||||
|
||||
println!("Got event: {:?}", event);
|
||||
|
||||
return match event {
|
||||
ChainHeadEvent::Done(ChainHeadResult { result }) => {
|
||||
let bytes = hex::decode(result.trim_start_matches("0x"))
|
||||
|
||||
@@ -662,6 +662,21 @@ impl<T: Config> Rpc<T> {
|
||||
Ok(header)
|
||||
}
|
||||
|
||||
/// Get the chain head genesis hash.
|
||||
pub async fn get_chainhead_genesis_hash(
|
||||
&self,
|
||||
) -> Result<T::Hash, Error> {
|
||||
let hash = self
|
||||
.client
|
||||
.request(
|
||||
"chainHead_unstable_genesisHash",
|
||||
rpc_params![],
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(hash)
|
||||
}
|
||||
|
||||
/// Subscribe to the chain head storage.
|
||||
pub async fn subscribe_chainhead_storage(
|
||||
&self,
|
||||
|
||||
Reference in New Issue
Block a user