Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Explicitly declare decl_storage! getters as functions #3870

Merged
merged 5 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions node-template/runtime/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ decl_storage! {
trait Store for Module<T: Trait> as TemplateModule {
// Just a dummy storage item.
// Here we are declaring a StorageValue, `Something` as a Option<u32>
// `get(something)` is the default getter which returns either the stored `u32` or `None` if nothing stored
Something get(something): Option<u32>;
// `get(fn something)` is the default getter which returns either the stored `u32` or `None` if nothing stored
Something get(fn something): Option<u32>;
}
}

Expand Down
2 changes: 1 addition & 1 deletion srml/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ decl_storage! {
/// The number of units of assets held by any given account.
Balances: map (T::AssetId, T::AccountId) => T::Balance;
/// The next asset identifier up for grabs.
NextAssetId get(next_asset_id): T::AssetId;
NextAssetId get(fn next_asset_id): T::AssetId;
/// The total unit supply of an asset.
TotalSupply: map T::AssetId => T::Balance;
}
Expand Down
4 changes: 2 additions & 2 deletions srml/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ pub trait Trait: timestamp::Trait {
decl_storage! {
trait Store for Module<T: Trait> as Aura {
/// The last timestamp.
LastTimestamp get(last) build(|_| 0.into()): T::Moment;
LastTimestamp get(fn last) build(|_| 0.into()): T::Moment;

/// The current authorities
pub Authorities get(authorities): Vec<T::AuthorityId>;
pub Authorities get(fn authorities): Vec<T::AuthorityId>;
}
add_extra_genesis {
config(authorities): Vec<T::AuthorityId>;
Expand Down
2 changes: 1 addition & 1 deletion srml/authority-discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub trait Trait: system::Trait + session::Trait {
decl_storage! {
trait Store for Module<T: Trait> as AuthorityDiscovery {
/// The current set of keys that may issue a heartbeat.
Keys get(keys): Vec<T::AuthorityId>;
Keys get(fn keys): Vec<T::AuthorityId>;
}
add_extra_genesis {
config(keys): Vec<T::AuthorityId>;
Expand Down
12 changes: 6 additions & 6 deletions srml/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,17 @@ type MaybeVrf = Option<[u8; 32 /* VRF_OUTPUT_LENGTH */]>;
decl_storage! {
trait Store for Module<T: Trait> as Babe {
/// Current epoch index.
pub EpochIndex get(epoch_index): u64;
pub EpochIndex get(fn epoch_index): u64;

/// Current epoch authorities.
pub Authorities get(authorities): Vec<(AuthorityId, BabeAuthorityWeight)>;
pub Authorities get(fn authorities): Vec<(AuthorityId, BabeAuthorityWeight)>;

/// The slot at which the first epoch actually started. This is 0
/// until the first block of the chain.
pub GenesisSlot get(genesis_slot): u64;
pub GenesisSlot get(fn genesis_slot): u64;

/// Current slot number.
pub CurrentSlot get(current_slot): u64;
pub CurrentSlot get(fn current_slot): u64;

/// The epoch randomness for the *current* epoch.
///
Expand All @@ -205,7 +205,7 @@ decl_storage! {
// NOTE: the following fields don't use the constants to define the
// array size because the metadata API currently doesn't resolve the
// variable to its underlying value.
pub Randomness get(randomness): [u8; 32 /* RANDOMNESS_LENGTH */];
pub Randomness get(fn randomness): [u8; 32 /* RANDOMNESS_LENGTH */];

/// Next epoch randomness.
NextRandomness: [u8; 32 /* RANDOMNESS_LENGTH */];
Expand All @@ -224,7 +224,7 @@ decl_storage! {

/// Temporary value (cleared at block finalization) which is `Some`
/// if per-block initialization has already been called for current block.
Initialized get(initialized): Option<MaybeVrf>;
Initialized get(fn initialized): Option<MaybeVrf>;
}
add_extra_genesis {
config(authorities): Vec<(AuthorityId, BabeAuthorityWeight)>;
Expand Down
10 changes: 5 additions & 5 deletions srml/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,12 @@ pub struct BalanceLock<Balance, BlockNumber> {
decl_storage! {
trait Store for Module<T: Trait<I>, I: Instance=DefaultInstance> as Balances {
/// The total units issued in the system.
pub TotalIssuance get(total_issuance) build(|config: &GenesisConfig<T, I>| {
pub TotalIssuance get(fn total_issuance) build(|config: &GenesisConfig<T, I>| {
config.balances.iter().fold(Zero::zero(), |acc: T::Balance, &(_, n)| acc + n)
}): T::Balance;

/// Information regarding the vesting of a given account.
pub Vesting get(vesting) build(|config: &GenesisConfig<T, I>| {
pub Vesting get(fn vesting) build(|config: &GenesisConfig<T, I>| {
// Generate initial vesting configuration
// * who - Account which we are generating vesting configuration for
// * begin - Block when the account will start to vest
Expand Down Expand Up @@ -337,7 +337,7 @@ decl_storage! {
///
/// `system::AccountNonce` is also deleted if `ReservedBalance` is also zero (it also gets
/// collapsed to zero if it ever becomes less than `ExistentialDeposit`.
pub FreeBalance get(free_balance)
pub FreeBalance get(fn free_balance)
build(|config: &GenesisConfig<T, I>| config.balances.clone()):
map T::AccountId => T::Balance;

Expand All @@ -352,10 +352,10 @@ decl_storage! {
///
/// `system::AccountNonce` is also deleted if `FreeBalance` is also zero (it also gets
/// collapsed to zero if it ever becomes less than `ExistentialDeposit`.)
pub ReservedBalance get(reserved_balance): map T::AccountId => T::Balance;
pub ReservedBalance get(fn reserved_balance): map T::AccountId => T::Balance;

/// Any liquidity locks on some account balances.
pub Locks get(locks): map T::AccountId => Vec<BalanceLock<T::Balance, T::BlockNumber>>;
pub Locks get(fn locks): map T::AccountId => Vec<BalanceLock<T::Balance, T::BlockNumber>>;
}
add_extra_genesis {
config(balances): Vec<(T::AccountId, T::Balance)>;
Expand Down
10 changes: 5 additions & 5 deletions srml/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ pub struct Votes<AccountId> {
decl_storage! {
trait Store for Module<T: Trait<I>, I: Instance=DefaultInstance> as Collective {
/// The hashes of the active proposals.
pub Proposals get(proposals): Vec<T::Hash>;
pub Proposals get(fn proposals): Vec<T::Hash>;
/// Actual proposal for a given hash, if it's current.
pub ProposalOf get(proposal_of): map T::Hash => Option<<T as Trait<I>>::Proposal>;
pub ProposalOf get(fn proposal_of): map T::Hash => Option<<T as Trait<I>>::Proposal>;
/// Votes on a given proposal, if it is ongoing.
pub Voting get(voting): map T::Hash => Option<Votes<T::AccountId>>;
pub Voting get(fn voting): map T::Hash => Option<Votes<T::AccountId>>;
/// Proposals so far.
pub ProposalCount get(proposal_count): u32;
pub ProposalCount get(fn proposal_count): u32;
/// The current members of the collective. This is stored sorted (just by value).
pub Members get(members): Vec<T::AccountId>;
pub Members get(fn members): Vec<T::AccountId>;
}
add_extra_genesis {
config(phantom): rstd::marker::PhantomData<I>;
Expand Down
6 changes: 3 additions & 3 deletions srml/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,9 +838,9 @@ decl_event! {
decl_storage! {
trait Store for Module<T: Trait> as Contract {
/// Gas spent so far in this block.
GasSpent get(gas_spent): Gas;
GasSpent get(fn gas_spent): Gas;
/// Current cost schedule for contracts.
CurrentSchedule get(current_schedule) config(): Schedule = Schedule::default();
CurrentSchedule get(fn current_schedule) config(): Schedule = Schedule::default();
/// A mapping from an original code hash to the original code, untouched by instrumentation.
pub PristineCode: map CodeHash<T> => Option<Vec<u8>>;
/// A mapping between an original code hash and instrumented wasm code, ready for execution.
Expand All @@ -850,7 +850,7 @@ decl_storage! {
/// The code associated with a given account.
pub ContractInfoOf: map T::AccountId => Option<ContractInfo<T>>;
/// The price of one unit of gas.
GasPrice get(gas_price) config(): BalanceOf<T> = 1.into();
GasPrice get(fn gas_price) config(): BalanceOf<T> = 1.into();
}
}

Expand Down
24 changes: 12 additions & 12 deletions srml/democracy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,38 +259,38 @@ impl<BlockNumber: Parameter, Proposal: Parameter> ReferendumInfo<BlockNumber, Pr
decl_storage! {
trait Store for Module<T: Trait> as Democracy {
/// The number of (public) proposals that have been made so far.
pub PublicPropCount get(public_prop_count) build(|_| 0 as PropIndex) : PropIndex;
pub PublicPropCount get(fn public_prop_count) build(|_| 0 as PropIndex) : PropIndex;
/// The public proposals. Unsorted.
pub PublicProps get(public_props): Vec<(PropIndex, T::Proposal, T::AccountId)>;
pub PublicProps get(fn public_props): Vec<(PropIndex, T::Proposal, T::AccountId)>;
/// Those who have locked a deposit.
pub DepositOf get(deposit_of): map PropIndex => Option<(BalanceOf<T>, Vec<T::AccountId>)>;
pub DepositOf get(fn deposit_of): map PropIndex => Option<(BalanceOf<T>, Vec<T::AccountId>)>;

/// The next free referendum index, aka the number of referenda started so far.
pub ReferendumCount get(referendum_count) build(|_| 0 as ReferendumIndex): ReferendumIndex;
pub ReferendumCount get(fn referendum_count) build(|_| 0 as ReferendumIndex): ReferendumIndex;
/// The next referendum index that should be tallied.
pub NextTally get(next_tally) build(|_| 0 as ReferendumIndex): ReferendumIndex;
pub NextTally get(fn next_tally) build(|_| 0 as ReferendumIndex): ReferendumIndex;
/// Information concerning any given referendum.
pub ReferendumInfoOf get(referendum_info):
pub ReferendumInfoOf get(fn referendum_info):
map ReferendumIndex => Option<(ReferendumInfo<T::BlockNumber, T::Proposal>)>;
/// Queue of successful referenda to be dispatched.
pub DispatchQueue get(dispatch_queue):
pub DispatchQueue get(fn dispatch_queue):
map T::BlockNumber => Vec<Option<(T::Proposal, ReferendumIndex)>>;

/// Get the voters for the current proposal.
pub VotersFor get(voters_for): map ReferendumIndex => Vec<T::AccountId>;
pub VotersFor get(fn voters_for): map ReferendumIndex => Vec<T::AccountId>;

/// Get the vote in a given referendum of a particular voter. The result is meaningful only
/// if `voters_for` includes the voter when called with the referendum (you'll get the
/// default `Vote` value otherwise). If you don't want to check `voters_for`, then you can
/// also check for simple existence with `VoteOf::exists` first.
pub VoteOf get(vote_of): map (ReferendumIndex, T::AccountId) => Vote;
pub VoteOf get(fn vote_of): map (ReferendumIndex, T::AccountId) => Vote;

/// Who is able to vote for whom. Value is the fund-holding account, key is the
/// vote-transaction-sending account.
pub Proxy get(proxy): map T::AccountId => Option<T::AccountId>;
pub Proxy get(fn proxy): map T::AccountId => Option<T::AccountId>;

/// Get the account (and lock periods) to which another account is delegating vote.
pub Delegations get(delegations): linked_map T::AccountId => (T::AccountId, Conviction);
pub Delegations get(fn delegations): linked_map T::AccountId => (T::AccountId, Conviction);

/// True if the last referendum tabled was submitted externally. False if it was a public
/// proposal.
Expand All @@ -304,7 +304,7 @@ decl_storage! {

/// A record of who vetoed what. Maps proposal hash to a possible existent block number
/// (until when it may not be resubmitted) and who vetoed it.
pub Blacklist get(blacklist): map T::Hash => Option<(T::BlockNumber, Vec<T::AccountId>)>;
pub Blacklist get(fn blacklist): map T::Hash => Option<(T::BlockNumber, Vec<T::AccountId>)>;

/// Record of all proposals that have been subject to emergency cancellation.
pub Cancellations: map T::Hash => bool;
Expand Down
18 changes: 9 additions & 9 deletions srml/elections-phragmen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,29 +132,29 @@ decl_storage! {
trait Store for Module<T: Trait> as PhragmenElection {
// ---- parameters
/// Number of members to elect.
pub DesiredMembers get(desired_members) config(): u32;
pub DesiredMembers get(fn desired_members) config(): u32;
/// Number of runners_up to keep.
pub DesiredRunnersUp get(desired_runners_up) config(): u32;
pub DesiredRunnersUp get(fn desired_runners_up) config(): u32;
/// How long each seat is kept. This defines the next block number at which an election
/// round will happen.
pub TermDuration get(term_duration) config(): T::BlockNumber;
pub TermDuration get(fn term_duration) config(): T::BlockNumber;

// ---- State
/// The current elected membership. Sorted based on account id.
pub Members get(members) config(): Vec<T::AccountId>;
pub Members get(fn members) config(): Vec<T::AccountId>;
/// The current runners_up. Sorted based on low to high merit (worse to best runner).
pub RunnersUp get(runners_up): Vec<T::AccountId>;
pub RunnersUp get(fn runners_up): Vec<T::AccountId>;
/// The total number of vote rounds that have happened, excluding the upcoming one.
pub ElectionRounds get(election_rounds): u32 = Zero::zero();
pub ElectionRounds get(fn election_rounds): u32 = Zero::zero();

/// Votes of a particular voter, with the round index of the votes.
pub VotesOf get(votes_of): linked_map T::AccountId => Vec<T::AccountId>;
pub VotesOf get(fn votes_of): linked_map T::AccountId => Vec<T::AccountId>;
/// Locked stake of a voter.
pub StakeOf get(stake_of): map T::AccountId => BalanceOf<T>;
pub StakeOf get(fn stake_of): map T::AccountId => BalanceOf<T>;

/// The present candidate list. Sorted based on account id. A current member can never enter
/// this vector and is always implicitly assumed to be a candidate.
pub Candidates get(candidates): Vec<T::AccountId>;
pub Candidates get(fn candidates): Vec<T::AccountId>;
}
}

Expand Down
32 changes: 16 additions & 16 deletions srml/elections/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,57 +213,57 @@ decl_storage! {
// ---- parameters

/// How long to give each top candidate to present themselves after the vote ends.
pub PresentationDuration get(presentation_duration) config(): T::BlockNumber;
pub PresentationDuration get(fn presentation_duration) config(): T::BlockNumber;
/// How long each position is active for.
pub TermDuration get(term_duration) config(): T::BlockNumber;
pub TermDuration get(fn term_duration) config(): T::BlockNumber;
/// Number of accounts that should constitute the collective.
pub DesiredSeats get(desired_seats) config(): u32;
pub DesiredSeats get(fn desired_seats) config(): u32;

// ---- permanent state (always relevant, changes only at the finalization of voting)

/// The current membership. When there's a vote going on, this should still be used for
/// executive matters. The block number (second element in the tuple) is the block that
/// their position is active until (calculated by the sum of the block number when the
/// member was elected and their term duration).
pub Members get(members) config(): Vec<(T::AccountId, T::BlockNumber)>;
pub Members get(fn members) config(): Vec<(T::AccountId, T::BlockNumber)>;
/// The total number of vote rounds that have happened or are in progress.
pub VoteCount get(vote_index): VoteIndex;
pub VoteCount get(fn vote_index): VoteIndex;

// ---- persistent state (always relevant, changes constantly)

// A list of votes for each voter. The votes are stored as numeric values and parsed in a
// bit-wise manner. In order to get a human-readable representation (`Vec<bool>`), use
// [`all_approvals_of`]. Furthermore, each vector of scalars is chunked with the cap of
// `APPROVAL_SET_SIZE`.
pub ApprovalsOf get(approvals_of): map (T::AccountId, SetIndex) => Vec<ApprovalFlag>;
pub ApprovalsOf get(fn approvals_of): map (T::AccountId, SetIndex) => Vec<ApprovalFlag>;
/// The vote index and list slot that the candidate `who` was registered or `None` if they
/// are not currently registered.
pub RegisterInfoOf get(candidate_reg_info): map T::AccountId => Option<(VoteIndex, u32)>;
pub RegisterInfoOf get(fn candidate_reg_info): map T::AccountId => Option<(VoteIndex, u32)>;
/// Basic information about a voter.
pub VoterInfoOf get(voter_info): map T::AccountId => Option<VoterInfo<BalanceOf<T>>>;
pub VoterInfoOf get(fn voter_info): map T::AccountId => Option<VoterInfo<BalanceOf<T>>>;
/// The present voter list (chunked and capped at [`VOTER_SET_SIZE`]).
pub Voters get(voters): map SetIndex => Vec<Option<T::AccountId>>;
pub Voters get(fn voters): map SetIndex => Vec<Option<T::AccountId>>;
/// the next free set to store a voter in. This will keep growing.
pub NextVoterSet get(next_nonfull_voter_set): SetIndex = 0;
pub NextVoterSet get(fn next_nonfull_voter_set): SetIndex = 0;
/// Current number of Voters.
pub VoterCount get(voter_count): SetIndex = 0;
pub VoterCount get(fn voter_count): SetIndex = 0;
/// The present candidate list.
pub Candidates get(candidates): Vec<T::AccountId>; // has holes
pub Candidates get(fn candidates): Vec<T::AccountId>; // has holes
/// Current number of active candidates
pub CandidateCount get(candidate_count): u32;
pub CandidateCount get(fn candidate_count): u32;

// ---- temporary state (only relevant during finalization/presentation)

/// The accounts holding the seats that will become free on the next tally.
pub NextFinalize get(next_finalize): Option<(T::BlockNumber, u32, Vec<T::AccountId>)>;
pub NextFinalize get(fn next_finalize): Option<(T::BlockNumber, u32, Vec<T::AccountId>)>;
/// Get the leaderboard if we're in the presentation phase. The first element is the weight
/// of each entry; It may be the direct summed approval stakes, or a weighted version of it.
/// Sorted from low to high.
pub Leaderboard get(leaderboard): Option<Vec<(BalanceOf<T>, T::AccountId)> >;
pub Leaderboard get(fn leaderboard): Option<Vec<(BalanceOf<T>, T::AccountId)> >;

/// Who is able to vote for whom. Value is the fund-holding account, key is the
/// vote-transaction-sending account.
pub Proxy get(proxy): map T::AccountId => Option<T::AccountId>;
pub Proxy get(fn proxy): map T::AccountId => Option<T::AccountId>;
}
}

Expand Down
10 changes: 5 additions & 5 deletions srml/example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ decl_storage! {
// keep things around between blocks.
trait Store for Module<T: Trait> as Example {
// Any storage declarations of the form:
// `pub? Name get(getter_name)? [config()|config(myname)] [build(|_| {...})] : <type> (= <new_default_value>)?;`
// `pub? Name get(fn getter_name)? [config()|config(myname)] [build(|_| {...})] : <type> (= <new_default_value>)?;`
// where `<type>` is either:
// - `Type` (a basic value item); or
// - `map KeyType => ValueType` (a map item).
Expand All @@ -331,7 +331,7 @@ decl_storage! {
// - `Foo::put(1); Foo::get()` returns `1`;
// - `Foo::kill(); Foo::get()` returns `0` (u32::default()).
// e.g. Foo: u32;
// e.g. pub Bar get(bar): map T::AccountId => Vec<(T::Balance, u64)>;
// e.g. pub Bar get(fn bar): map T::AccountId => Vec<(T::Balance, u64)>;
//
// For basic value items, you'll get a type which implements
// `support::StorageValue`. For map items, you'll get a type which
Expand All @@ -340,13 +340,13 @@ decl_storage! {
// If they have a getter (`get(getter_name)`), then your module will come
// equipped with `fn getter_name() -> Type` for basic value items or
// `fn getter_name(key: KeyType) -> ValueType` for map items.
Dummy get(dummy) config(): Option<T::Balance>;
Dummy get(fn dummy) config(): Option<T::Balance>;

// A map that has enumerable entries.
Bar get(bar) config(): linked_map T::AccountId => T::Balance;
Bar get(fn bar) config(): linked_map T::AccountId => T::Balance;

// this one uses the default, we'll demonstrate the usage of 'mutate' API.
Foo get(foo) config(): T::Balance;
Foo get(fn foo) config(): T::Balance;
}
}

Expand Down
8 changes: 4 additions & 4 deletions srml/finality-tracker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,17 @@ pub trait Trait: SystemTrait {
decl_storage! {
trait Store for Module<T: Trait> as Timestamp {
/// Recent hints.
RecentHints get(recent_hints) build(|_| vec![T::BlockNumber::zero()]): Vec<T::BlockNumber>;
RecentHints get(fn recent_hints) build(|_| vec![T::BlockNumber::zero()]): Vec<T::BlockNumber>;
/// Ordered recent hints.
OrderedHints get(ordered_hints) build(|_| vec![T::BlockNumber::zero()]): Vec<T::BlockNumber>;
OrderedHints get(fn ordered_hints) build(|_| vec![T::BlockNumber::zero()]): Vec<T::BlockNumber>;
/// The median.
Median get(median) build(|_| T::BlockNumber::zero()): T::BlockNumber;
Median get(fn median) build(|_| T::BlockNumber::zero()): T::BlockNumber;

/// Final hint to apply in the block. `None` means "same as parent".
Update: Option<T::BlockNumber>;

// when initialized through config this is set in the beginning.
Initialized get(initialized) build(|_| false): bool;
Initialized get(fn initialized) build(|_| false): bool;
}
}

Expand Down
Loading