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
+17 -43
View File
@@ -39,6 +39,12 @@
)]
#![allow(clippy::type_complexity)]
#[macro_use]
extern crate substrate_subxt_proc_macro;
pub use sp_core;
pub use sp_runtime;
use std::{
convert::TryFrom,
marker::PhantomData,
@@ -98,12 +104,13 @@ pub use crate::{
ExtrinsicSuccess,
},
runtimes::*,
substrate_subxt_proc_macro::*,
};
use crate::{
frame::{
balances::Balances,
system::{
AccountStore,
AccountStoreExt,
Phase,
System,
SystemEvent,
@@ -161,8 +168,7 @@ impl<T: System, S, E> ClientBuilder<T, S, E> {
jsonrpsee::http_client(url)
}
};
let rpc = Rpc::new(client).await?;
let rpc = Rpc::new(client);
let (metadata, genesis_hash, runtime_version) = future::join3(
rpc.metadata(),
rpc.genesis_hash(),
@@ -211,11 +217,11 @@ impl<T: System, S, E> Client<T, S, E> {
&self,
store: F,
hash: Option<T::Hash>,
) -> Result<Option<F::Returns>, Error> {
) -> Result<F::Returns, Error> {
let key = store.key(&self.metadata)?;
let value = self.rpc.storage::<F::Returns>(key, hash).await?;
if let Some(v) = value {
Ok(Some(v))
Ok(v)
} else {
Ok(store.default(&self.metadata)?)
}
@@ -324,7 +330,7 @@ impl<T: System, S, E> Client<T, S, E> {
impl<T, S, E> Client<T, S, E>
where
T: System + Balances + Send + Sync,
T: System + Balances + Send + Sync + 'static,
S: 'static,
E: SignedExtra<T> + SignedExtension + 'static,
{
@@ -334,11 +340,7 @@ where
account_id: &<T as System>::AccountId,
call: C,
) -> Result<SignedPayload<Encoded, <E as SignedExtra<T>>::Extra>, Error> {
let account_nonce = self
.fetch(AccountStore(account_id), None)
.await?
.unwrap()
.nonce;
let account_nonce = self.account(account_id).await?.nonce;
let version = self.runtime_version.spec_version;
let genesis_hash = self.genesis_hash;
let call = self
@@ -365,12 +367,7 @@ where
let account_id = S::Signer::from(signer.public()).into_account();
let nonce = match nonce {
Some(nonce) => nonce,
None => {
self.fetch(AccountStore(&account_id), None)
.await?
.unwrap()
.nonce
}
None => self.account(&account_id).await?.nonce,
};
let genesis_hash = self.genesis_hash;
@@ -419,7 +416,7 @@ impl<T: System, P, S, E> XtBuilder<T, P, S, E> {
}
}
impl<T: System + Send + Sync, P, S: 'static, E> XtBuilder<T, P, S, E>
impl<T: System + Send + Sync + 'static, P, S: 'static, E> XtBuilder<T, P, S, E>
where
P: Pair,
S: Verify + Codec + From<P::Signature>,
@@ -499,7 +496,7 @@ impl<T: System, P, S, E> EventsSubscriber<T, P, S, E> {
}
}
impl<T: System + Send + Sync, P, S: 'static, E> EventsSubscriber<T, P, S, E>
impl<T: System + Send + Sync + 'static, P, S: 'static, E> EventsSubscriber<T, P, S, E>
where
P: Pair,
S: Verify + Codec + From<P::Signature>,
@@ -522,7 +519,7 @@ where
/// Wraps an already encoded byte vector, prevents being encoded as a raw byte vector as part of
/// the transaction payload
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct Encoded(pub Vec<u8>);
impl codec::Encode for Encoded {
@@ -610,29 +607,6 @@ mod tests {
.unwrap();
}
#[async_std::test]
#[ignore] // requires locally running substrate node
async fn test_state_total_issuance() {
let client = test_client().await;
client
.fetch(balances::TotalIssuance(Default::default()), None)
.await
.unwrap()
.unwrap();
}
#[async_std::test]
#[ignore] // requires locally running substrate node
async fn test_state_read_free_balance() {
let client = test_client().await;
let account = AccountKeyring::Alice.to_account_id();
client
.fetch(AccountStore(&account), None)
.await
.unwrap()
.unwrap();
}
#[async_std::test]
#[ignore] // requires locally running substrate node
async fn test_chain_subscribe_blocks() {