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:
David Craven
2020-05-12 13:25:22 +02:00
committed by GitHub
parent 825f3ab64c
commit f861f3fac4
21 changed files with 697 additions and 564 deletions
+18 -21
View File
@@ -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(())
}