mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-19 22:51:03 +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:
|
// Create a client to use:
|
||||||
let api = OnlineClient::<PolkadotConfig>::new().await?;
|
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?;
|
let mut follow_sub = api.blocks().subscribe_chainhead_finalized(true).await?;
|
||||||
// Handle all subscriptions from the `chainHead_follow`.
|
// Handle all subscriptions from the `chainHead_follow`.
|
||||||
while let Some(block) = follow_sub.next().await {
|
while let Some(block) = follow_sub.next().await {
|
||||||
|
|||||||
@@ -81,8 +81,6 @@ where
|
|||||||
if let Some(event) = sub.next().await {
|
if let Some(event) = sub.next().await {
|
||||||
let event = event?;
|
let event = event?;
|
||||||
|
|
||||||
println!("Got event: {:?}", event);
|
|
||||||
|
|
||||||
return match event {
|
return match event {
|
||||||
ChainHeadEvent::Done(ChainHeadResult { result }) => {
|
ChainHeadEvent::Done(ChainHeadResult { result }) => {
|
||||||
let bytes = hex::decode(result.trim_start_matches("0x"))
|
let bytes = hex::decode(result.trim_start_matches("0x"))
|
||||||
@@ -148,8 +146,6 @@ where
|
|||||||
if let Some(event) = sub.next().await {
|
if let Some(event) = sub.next().await {
|
||||||
let event = event?;
|
let event = event?;
|
||||||
|
|
||||||
println!("Got event: {:?}", event);
|
|
||||||
|
|
||||||
return match event {
|
return match event {
|
||||||
ChainHeadEvent::Done(ChainHeadResult { result }) => {
|
ChainHeadEvent::Done(ChainHeadResult { result }) => {
|
||||||
let result = match result {
|
let result = match result {
|
||||||
@@ -195,8 +191,6 @@ where
|
|||||||
if let Some(event) = sub.next().await {
|
if let Some(event) = sub.next().await {
|
||||||
let event = event?;
|
let event = event?;
|
||||||
|
|
||||||
println!("Got event: {:?}", event);
|
|
||||||
|
|
||||||
return match event {
|
return match event {
|
||||||
ChainHeadEvent::Done(ChainHeadResult { result }) => {
|
ChainHeadEvent::Done(ChainHeadResult { result }) => {
|
||||||
let bytes = hex::decode(result.trim_start_matches("0x"))
|
let bytes = hex::decode(result.trim_start_matches("0x"))
|
||||||
|
|||||||
@@ -662,6 +662,21 @@ impl<T: Config> Rpc<T> {
|
|||||||
Ok(header)
|
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.
|
/// Subscribe to the chain head storage.
|
||||||
pub async fn subscribe_chainhead_storage(
|
pub async fn subscribe_chainhead_storage(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
Reference in New Issue
Block a user