-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
64 changed files
with
1,668 additions
and
705 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
use primitives::Balance; | ||
|
||
use crate::AnyConnection; | ||
use crate::AnyConnectionExt; | ||
|
||
/// Reads from the storage how much balance is currently on chain. | ||
/// | ||
/// Performs a single storage read. | ||
pub fn total_issuance<C: AnyConnection>(connection: &C) -> Balance { | ||
pub fn total_issuance<C: AnyConnectionExt>(connection: &C) -> Balance { | ||
connection.read_storage_value("Balances", "TotalIssuance") | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,57 @@ | ||
use pallet_elections::EraValidators; | ||
use primitives::CommitteeSeats; | ||
use primitives::SessionIndex; | ||
pub use primitives::{CommitteeSeats, EraValidators}; | ||
use sp_core::H256; | ||
use substrate_api_client::AccountId; | ||
|
||
use crate::AnyConnection; | ||
use crate::{get_session_first_block, AnyConnectionExt}; | ||
|
||
const PALLET: &str = "Elections"; | ||
|
||
pub fn get_committee_seats<C: AnyConnection>( | ||
pub fn get_committee_seats<C: AnyConnectionExt>( | ||
connection: &C, | ||
block_hash: Option<H256>, | ||
) -> CommitteeSeats { | ||
connection | ||
.as_connection() | ||
.get_storage_value(PALLET, "CommitteeSize", block_hash) | ||
.expect("Failed to obtain CommitteeSize extrinsic!") | ||
.unwrap_or_else(|| { | ||
panic!( | ||
"Failed to decode CommitteeSize for block hash: {:?}.", | ||
block_hash | ||
) | ||
}) | ||
} | ||
|
||
pub fn get_next_era_committee_seats<C: AnyConnection>(connection: &C) -> CommitteeSeats { | ||
connection.read_storage_value_at_block(PALLET, "CommitteeSize", block_hash) | ||
} | ||
|
||
pub fn get_next_era_committee_seats<C: AnyConnectionExt>(connection: &C) -> CommitteeSeats { | ||
connection.read_storage_value(PALLET, "NextEraCommitteeSize") | ||
} | ||
|
||
pub fn get_validator_block_count<C: AnyConnection>( | ||
pub fn get_validator_block_count<C: AnyConnectionExt>( | ||
connection: &C, | ||
account_id: &AccountId, | ||
block_hash: Option<H256>, | ||
) -> Option<u32> { | ||
connection | ||
.as_connection() | ||
.get_storage_map(PALLET, "SessionValidatorBlockCount", account_id, block_hash) | ||
.expect("Failed to obtain SessionValidatorBlockCount extrinsic!") | ||
connection.read_storage_map(PALLET, "SessionValidatorBlockCount", account_id, block_hash) | ||
} | ||
|
||
pub fn get_current_era_validators<C: AnyConnection>(connection: &C) -> EraValidators<AccountId> { | ||
pub fn get_current_era_validators<C: AnyConnectionExt>(connection: &C) -> EraValidators<AccountId> { | ||
connection.read_storage_value(PALLET, "CurrentEraValidators") | ||
} | ||
|
||
pub fn get_current_era_reserved_validators<C: AnyConnection>(connection: &C) -> Vec<AccountId> { | ||
pub fn get_current_era_reserved_validators<C: AnyConnectionExt>(connection: &C) -> Vec<AccountId> { | ||
get_current_era_validators(connection).reserved | ||
} | ||
|
||
pub fn get_current_era_non_reserved_validators<C: AnyConnection>(connection: &C) -> Vec<AccountId> { | ||
pub fn get_current_era_non_reserved_validators<C: AnyConnectionExt>( | ||
connection: &C, | ||
) -> Vec<AccountId> { | ||
get_current_era_validators(connection).non_reserved | ||
} | ||
|
||
pub fn get_next_era_reserved_validators<C: AnyConnection>(connection: &C) -> Vec<AccountId> { | ||
pub fn get_next_era_reserved_validators<C: AnyConnectionExt>(connection: &C) -> Vec<AccountId> { | ||
connection.read_storage_value(PALLET, "NextEraReservedValidators") | ||
} | ||
|
||
pub fn get_next_era_non_reserved_validators<C: AnyConnection>(connection: &C) -> Vec<AccountId> { | ||
pub fn get_next_era_non_reserved_validators<C: AnyConnectionExt>(connection: &C) -> Vec<AccountId> { | ||
connection.read_storage_value(PALLET, "NextEraNonReservedValidators") | ||
} | ||
|
||
pub fn get_era_validators<C: AnyConnectionExt>( | ||
connection: &C, | ||
session: SessionIndex, | ||
) -> EraValidators<AccountId> { | ||
let block_hash = get_session_first_block(connection, session); | ||
connection.read_storage_value_at_block(PALLET, "CurrentEraValidators", Some(block_hash)) | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.