Created
November 10, 2019 20:48
-
-
Save insipx/483107ff2e784d662dfe7a90a8773d75 to your computer and use it in GitHub Desktop.
TrySubxt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use subxt::{Client, ClientBuilder, system::System, balances::Balances}; | |
use tokio::runtime::Runtime as TokioRuntime; | |
use futures::{Future, Stream}; | |
use node_runtime::{Runtime as RuntimeT, SignedExtra}; | |
use srml_system::Trait; | |
use balances::Trait as BalancesTrait; | |
fn main() { | |
let mut rt = TokioRuntime::new().unwrap(); | |
let client = ClientBuilder::<Runtime>::new().set_url(url::Url::parse("ws://127.0.0.1:9944").unwrap()).build(); | |
let client = rt.block_on(client).unwrap(); | |
let stream = rt.block_on(client.subscribe_blocks()).unwrap(); | |
rt.block_on(stream.for_each(|b| { | |
println!("block: {:?}", b); | |
Ok(()) | |
})); | |
} | |
#[derive(Clone, PartialEq, Eq, Debug)] | |
pub struct Runtime; | |
impl System for Runtime { | |
type Index = <RuntimeT as Trait>::Index; | |
type BlockNumber = <RuntimeT as Trait>::BlockNumber; | |
type Hash = <RuntimeT as Trait>::Hash; | |
type Hashing = <RuntimeT as Trait>::Hashing; | |
type Address = <RuntimeT as Trait>::AccountId; | |
type AccountId = <RuntimeT as Trait>::AccountId; | |
// type Lookup = <RuntimeT as Trait>::Lookup; | |
type Header = <RuntimeT as Trait>::Header; | |
// type Event = <RuntimeT as Trait>::Event; | |
// type SignedExtra = SignedExtra; | |
} | |
impl Balances for Runtime { | |
type Balance = <RuntimeT as BalancesTrait>::Balance; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[package]
name = "try-out-subxt"
version = "0.1.0"
authors = ["Andrew Plaza [email protected]"]
edition = "2018"
See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
subxt = { git = "https://github.com/paritytech/substrate-subxt", branch = "master", package = "substrate-subxt" }
futures = "0.1.29"
tokio = "0.1"
url = "1.7"
node-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", package = "node-runtime" }
srml-system = { git = "https://github.com/paritytech/substrate/", package = "srml-system", branch="master"}
balances = { package = "srml-balances", git = "https://github.com/paritytech/substrate/", default_features = false }