Merge branch 'master' into staking

This commit is contained in:
Demi M. Obenour
2020-06-07 12:42:37 -04:00
8 changed files with 94 additions and 38 deletions
+2 -2
View File
@@ -146,7 +146,7 @@ mod tests {
async fn test_state_total_issuance() {
env_logger::try_init().ok();
let client = test_client().await;
let total_issuance = client.total_issuance().await.unwrap();
let total_issuance = client.total_issuance(None).await.unwrap();
assert_ne!(total_issuance, 0);
}
@@ -156,7 +156,7 @@ mod tests {
env_logger::try_init().ok();
let client = test_client().await;
let account = AccountKeyring::Alice.to_account_id();
let info = client.account(&account).await.unwrap();
let info = client.account(&account, None).await.unwrap();
assert_ne!(info.data.free, 0);
}
}
+24 -8
View File
@@ -44,7 +44,10 @@ extern crate substrate_subxt_proc_macro;
pub use sp_core;
pub use sp_runtime;
use codec::Encode;
use codec::{
Decode,
Encode,
};
use futures::future;
use jsonrpsee::client::Subscription;
use sc_rpc_api::state::ReadProof;
@@ -199,21 +202,34 @@ impl<T: System, S, E> Client<T, S, E> {
&self.metadata
}
/// Fetch a StorageKey.
pub async fn fetch<F: Store<T>>(
/// Fetch a StorageKey with default value.
pub async fn fetch_or_default<F: Store<T>>(
&self,
store: F,
hash: Option<T::Hash>,
) -> 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(v)
if let Some(data) = self.rpc.storage(key, hash).await? {
Ok(Decode::decode(&mut &data.0[..])?)
} else {
Ok(store.default(&self.metadata)?)
}
}
/// Fetch a StorageKey an optional storage key.
pub async fn fetch<F: Store<T>>(
&self,
store: F,
hash: Option<T::Hash>,
) -> Result<Option<F::Returns>, Error> {
let key = store.key(&self.metadata)?;
if let Some(data) = self.rpc.storage(key, hash).await? {
Ok(Some(Decode::decode(&mut &data.0[..])?))
} else {
Ok(None)
}
}
/// Query historical storage entries
pub async fn query_storage(
&self,
@@ -311,7 +327,7 @@ where
let account_nonce = if let Some(nonce) = nonce {
nonce
} else {
self.account(account_id).await?.nonce
self.account(account_id, None).await?.nonce
};
let spec_version = self.runtime_version.spec_version;
let tx_version = self.runtime_version.transaction_version;
@@ -452,7 +468,7 @@ mod tests {
let client = test_client().await;
let nonce = client
.account(&AccountKeyring::Alice.to_account_id())
.account(&AccountKeyring::Alice.to_account_id(), None)
.await
.unwrap()
.nonce;
+5 -12
View File
@@ -132,22 +132,15 @@ impl<T: System> Rpc<T> {
}
/// Fetch a storage key
pub async fn storage<V: Decode>(
pub async fn storage(
&self,
key: StorageKey,
hash: Option<T::Hash>,
) -> Result<Option<V>, Error> {
) -> Result<Option<StorageData>, Error> {
let params = Params::Array(vec![to_json_value(key)?, to_json_value(hash)?]);
let data: Option<StorageData> =
self.client.request("state_getStorage", params).await?;
match data {
Some(data) => {
log::debug!("state_getStorage {:?}", data.0);
let value = Decode::decode(&mut &data.0[..])?;
Ok(Some(value))
}
None => Ok(None),
}
let data = self.client.request("state_getStorage", params).await?;
log::debug!("state_getStorage {:?}", data);
Ok(data)
}
/// Query historical storage entries
+6 -1
View File
@@ -100,10 +100,15 @@ where
self.nonce = Some(nonce);
}
/// Increment the nonce
/// Increment the nonce.
pub fn increment_nonce(&mut self) {
self.nonce = self.nonce.map(|nonce| nonce + 1.into());
}
/// Returns the signer.
pub fn signer(&self) -> &P {
&self.signer
}
}
impl<T, S, E, P> Signer<T, S, E> for PairSigner<T, S, E, P>