mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 20:31:13 +00:00
Split subxt (#102)
* Proc macro improvements. * Use proc-macros. * Update examples. * Fix build. * Run rustfmt. * Fix total issuance test. * Remove gas limit from put code call. * Handle runtime errors. * Fix tests. * Make test more reliable. * Revert "Handle runtime errors." This reverts commit 26f30a9f4cfcfddfb3e49308cded46cfe6468697. * Use expect instead of unwrap. * Parse marker type. * Fetch doesn't fail.
This commit is contained in:
+18
-21
@@ -15,31 +15,28 @@
|
||||
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use substrate_subxt::{
|
||||
system::System,
|
||||
Error,
|
||||
ClientBuilder,
|
||||
KusamaRuntime,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
async_std::task::block_on(async move {
|
||||
env_logger::init();
|
||||
#[async_std::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
env_logger::init();
|
||||
|
||||
let block_hash = fetch_block_hash(1).await;
|
||||
match block_hash {
|
||||
Ok(Some(hash)) => println!("Block hash for block number 1: {}", hash),
|
||||
Ok(None) => println!("Block number 1 not found."),
|
||||
Err(_) => eprintln!("Failed to fetch block hash"),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async fn fetch_block_hash(
|
||||
block_number: u32,
|
||||
) -> Result<Option<<KusamaRuntime as System>::Hash>, Error> {
|
||||
substrate_subxt::ClientBuilder::<KusamaRuntime>::new()
|
||||
let client = ClientBuilder::<KusamaRuntime>::new()
|
||||
.set_url("wss://kusama-rpc.polkadot.io")
|
||||
.build()
|
||||
.await?
|
||||
.block_hash(Some(block_number.into()))
|
||||
.await
|
||||
.await?;
|
||||
|
||||
let block_number = 1;
|
||||
|
||||
let block_hash = client.block_hash(Some(block_number.into())).await?;
|
||||
|
||||
if let Some(hash) = block_hash {
|
||||
println!("Block hash for block number {}: {}", block_number, hash);
|
||||
} else {
|
||||
println!("Block number {} not found.", block_number);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user