I'm having trouble using subxt to query for an historical event. Not sure what manipulation is necessary to filter for the specific events I want.
In my case, I want to query for a BasicOutboundChannel.Committed
event at block X.
None of the examples in the subxt repo show how to do this, as they only read events emitted by subscriptions (a different code path).
My client code so far:
#[subxt::subxt(runtime_metadata_path = "metadata.scale")]
pub mod runtime { }
use subxt::{ClientBuilder, DefaultConfig, SubstrateExtrinsicParams};
use subxt::sp_core::H256;
use hex_literal::hex;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api = ClientBuilder::new()
.set_url("ws://localhost:11144")
.build()
.await?
.to_runtime_api::<runtime::RuntimeApi<DefaultConfig, SubstrateExtrinsicParams<DefaultConfig>>>();
let hash: Option<H256> = Some(hex!("4f1a8ead12dc09b449e8a4b37fb1de21b3a2b1841a1df037194bf0e1bc156285").into());
let events = api.storage().system().events(hash).await?;
// NOTE: This fails to compile. How can I test that events[0] is a 'Committed' event?
let event: runtime::basic_outbound_channel::events::Committed = events[0].event.try_into()?;
println!("{:?}", event);
Ok(())
}
error message:
the trait bound `basic_outbound_channel::events::Committed: From<snowbase_runtime::Event>` is not satisfied
required because of the requirements on the impl of `Into<basic_outbound_channel::events::Committed>` for `snowbase_runtime::Event`
required because of the requirements on the impl of `TryFrom<snowbase_runtime::Event>` for `basic_outbound_channel::events::Committed`
required because of the requirements on the impl of `TryInto<basic_outbound_channel::events::Committed>` for `snowbase_runtime::Event`rustcE0277