Staking support (#99)

* Initial Staking API

* Add more staking types

* Reformat

* Remove dead code

* Fix missing documentation

* Reformat

* Staking: use proc macros

* Add partial session support

* Reformat

* Try to implement nomination

This currently fails with compilation errors I do not understand.

* Use the #[module] macro

This fixes a compile error

* Explain undefined method diagnostics

* Use ‘#[module]’ and implement session for Kusama

* Don’t impl ‘Staking’ for all ‘T: System’

* Add staking payout support

* Fix compilation errors and remove useless lifetimes

* Respond to code review

This fixes most of the issues found during review, with the exception of
tests.

* Make signing fallable and asynchronous

This is needed for hardware wallets, which require human confirmation to
sign transactions.  Blocking on a human to sign transactions is not a
good idea, and the signing might fail for many reasons (device
unplugged, authorization not granted, etc).

* Reformat

* Refactor as suggested by Andrew Jones (@ascjones).

* Reformat

* Refactor as suggested by Andrew Jones (@ascjones).

* Trait cleanups

* Make the `Signer` impl require Send + Sync

This is what Ledgeracio needs.

* Use the correct key for staking maps

They use the key type, not ‘PhantomData’.

* Implement set_payee call

* Switch to associated types for Staking

* Implement `set_keys`

This is needed for Ledgeracio.

* Remove impl of Signer for Box<dyn Signer + Send + Sync>

It isn’t needed, since Box implements Deref.

* Fix Polkadot and Kusama ‘SessionKey’ structs

I had failed to include the ‘Parachains’ component, which the default
Substrate runtime doesn’t have.

* Include a copy of `ValidatorId`

This avoids needing to depend on Polkadot.

* Fix syntax error in Cargo.toml

* Fix compile errors

* Add Debug impls

* Fix return type of `BondedStore`

* Use some upstream type definitions

Also add `Default` impls.

* Bump deps and fix build

* Remove last reference to Kusama feature

* Fix compilation errors

* Implement the `concat` in `twox_64_concat`

* Expose properties and per-era preferences

* Era rewards point support

I also did some refactoring.

* Expose clipped exposure

* Era reward points support

* Make `PayoutStakersCall` public

* Add in all default features for debugging

* Chill support and update to latest Substrate

* If property fetch fails, use dummy values

* Fix tests

* Fix header

* Remove some code Ledgeracio does not need

* More deletions

* Remove more code not needed for Ledgeracio

* Remove a pointless change in Cargo.toml

w.r.t. upstream.

* Remove more junk

* Revert contracts put_code test to pure code (not using the macro)

* Test contract instantiate

* Fmt

* WIP

* Add some more submission tests

* Reformat

* More tests

* Cleanup

* Hopefully fix CI

* Remove dead code

* Test chill

* Add missing docs

* Remove unnecessary use

* Revert "Remove unnecessary use"

This reverts commit bc8bc36bde581f1892ea88a778dfe0fe5bff24d7.

* Retry on temporary failures

* Ignore the staking tests on CI

* Obey the fmt

* Run CI with at most one test thread

* Implement tests for staking

* More tests

* Remove unhelpful println!

* Revert changes in contract tests

* Reformat

* Remove spurious diff

* More tests

Co-authored-by: Demi M. Obenour <demiobenour@gmail.com>
Co-authored-by: David Palm <dvdplm@gmail.com>
Co-authored-by: Andrew Jones <ascjones@gmail.com>
This commit is contained in:
Demi Obenour
2020-09-21 17:15:46 +00:00
committed by GitHub
parent 0c7454dfcd
commit f9f69b8c3b
12 changed files with 606 additions and 4 deletions
+13 -2
View File
@@ -35,7 +35,8 @@
while_true,
trivial_casts,
trivial_numeric_casts,
unused_extern_crates
unused_extern_crates,
clippy::all
)]
#![allow(clippy::type_complexity)]
@@ -93,6 +94,7 @@ pub use crate::{
rpc::{
BlockNumber,
ExtrinsicSuccess,
SystemProperties,
},
runtimes::*,
subscription::*,
@@ -161,16 +163,18 @@ impl<T: Runtime> ClientBuilder<T> {
}
};
let rpc = Rpc::new(client);
let (metadata, genesis_hash, runtime_version) = future::join3(
let (metadata, genesis_hash, runtime_version, properties) = future::join4(
rpc.metadata(),
rpc.genesis_hash(),
rpc.runtime_version(None),
rpc.system_properties(),
)
.await;
Ok(Client {
rpc,
genesis_hash: genesis_hash?,
metadata: metadata?,
properties: properties.unwrap_or_else(|_| Default::default()),
runtime_version: runtime_version?,
_marker: PhantomData,
page_size: self.page_size.unwrap_or(10),
@@ -183,6 +187,7 @@ pub struct Client<T: Runtime> {
rpc: Rpc<T>,
genesis_hash: T::Hash,
metadata: Metadata,
properties: SystemProperties,
runtime_version: RuntimeVersion,
_marker: PhantomData<(fn() -> T::Signature, T::Extra)>,
page_size: u32,
@@ -194,6 +199,7 @@ impl<T: Runtime> Clone for Client<T> {
rpc: self.rpc.clone(),
genesis_hash: self.genesis_hash,
metadata: self.metadata.clone(),
properties: self.properties.clone(),
runtime_version: self.runtime_version.clone(),
_marker: PhantomData,
page_size: self.page_size,
@@ -258,6 +264,11 @@ impl<T: Runtime> Client<T> {
&self.metadata
}
/// Returns the system properties
pub fn properties(&self) -> &SystemProperties {
&self.properties
}
/// Fetch the value under an unhashed storage key
pub async fn fetch_unhashed<V: Decode>(
&self,