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

Commit cca3b60

Browse files
bkchrgavofyork
authored andcommitted
Implement storage json metadata (#670)
* `decl_storage!` exposes json metadata about the storage The metadata can be accessed by calling `store_json_metadata()`. * Hide internal macros in the documentation * Include the function documentation in the store json metadata * Adapt the storage declarations to use doc comments
1 parent 80e17a1 commit cca3b60

File tree

12 files changed

+703
-212
lines changed

12 files changed

+703
-212
lines changed

substrate/runtime-support/src/dispatch.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ macro_rules! decl_dispatch {
218218
}
219219

220220
#[macro_export]
221+
#[doc(hidden)]
221222
/// Implement a single dispatch modules to create a pairing of a dispatch trait and enum.
222223
macro_rules! __decl_dispatch_module_without_aux {
223224
(
@@ -262,6 +263,7 @@ macro_rules! __decl_dispatch_module_without_aux {
262263
}
263264

264265
#[macro_export]
266+
#[doc(hidden)]
265267
/// Implement a single dispatch modules to create a pairing of a dispatch trait and enum.
266268
macro_rules! __decl_dispatch_module_with_aux {
267269
(
@@ -308,6 +310,7 @@ macro_rules! __decl_dispatch_module_with_aux {
308310

309311
/// Implement a single dispatch modules to create a pairing of a dispatch trait and enum.
310312
#[macro_export]
313+
#[doc(hidden)]
311314
macro_rules! __decl_dispatch_module_common {
312315
(
313316
impl for $mod_type:ident<$trait_instance:ident: $trait_name:ident>;
@@ -419,6 +422,7 @@ macro_rules! __decl_dispatch_module_common {
419422
}
420423

421424
#[macro_export]
425+
#[doc(hidden)]
422426
macro_rules! __impl_decode {
423427
(
424428
$input:expr;
@@ -452,6 +456,7 @@ macro_rules! __impl_decode {
452456
}
453457

454458
#[macro_export]
459+
#[doc(hidden)]
455460
macro_rules! __impl_encode {
456461
(
457462
$dest:expr;
@@ -512,7 +517,7 @@ macro_rules! impl_outer_dispatch {
512517
$camelcase ( $crate::dispatch::AuxCallableCallFor<$camelcase> )
513518
,)*
514519
}
515-
impl_outer_dispatch_common! { $call_type, $($camelcase,)* }
520+
__impl_outer_dispatch_common! { $call_type, $($camelcase,)* }
516521
impl $crate::dispatch::AuxDispatchable for $call_type {
517522
type Aux = $aux;
518523
type Trait = $call_type;
@@ -552,7 +557,7 @@ macro_rules! impl_outer_dispatch {
552557
$camelcase ( $crate::dispatch::CallableCallFor<$camelcase> )
553558
,)*
554559
}
555-
impl_outer_dispatch_common! { $call_type, $($camelcase,)* }
560+
__impl_outer_dispatch_common! { $call_type, $($camelcase,)* }
556561
impl $crate::dispatch::Dispatchable for $call_type {
557562
type Trait = $call_type;
558563
fn dispatch(self) -> $crate::dispatch::Result {
@@ -580,7 +585,8 @@ macro_rules! impl_outer_dispatch {
580585

581586
/// Implement a meta-dispatch module to dispatch to other dispatchers.
582587
#[macro_export]
583-
macro_rules! impl_outer_dispatch_common {
588+
#[doc(hidden)]
589+
macro_rules! __impl_outer_dispatch_common {
584590
(
585591
$call_type:ident, $( $camelcase:ident, )*
586592
) => {
@@ -602,6 +608,7 @@ macro_rules! impl_outer_dispatch_common {
602608

603609
/// Implement the `json_metadata` function.
604610
#[macro_export]
611+
#[doc(hidden)]
605612
macro_rules! __impl_json_metadata {
606613
(
607614
impl for $mod_type:ident<$trait_instance:ident: $trait_name:ident>;
@@ -618,6 +625,7 @@ macro_rules! __impl_json_metadata {
618625

619626
/// Convert the list of calls into their JSON representation, joined by ",".
620627
#[macro_export]
628+
#[doc(hidden)]
621629
macro_rules! __calls_to_json {
622630
// WITHOUT AUX
623631
(
@@ -679,6 +687,7 @@ macro_rules! __calls_to_json {
679687

680688
/// Convert a list of function into their JSON representation, joined by ",".
681689
#[macro_export]
690+
#[doc(hidden)]
682691
macro_rules! __functions_to_json {
683692
// WITHOUT AUX
684693
(
@@ -736,6 +745,7 @@ macro_rules! __functions_to_json {
736745

737746
/// Convert a function into its JSON representation.
738747
#[macro_export]
748+
#[doc(hidden)]
739749
macro_rules! __function_to_json {
740750
(
741751
fn $fn_name:ident(
@@ -759,6 +769,7 @@ macro_rules! __function_to_json {
759769

760770
/// Convert a function documentation attribute into its JSON representation.
761771
#[macro_export]
772+
#[doc(hidden)]
762773
macro_rules! __function_doc_to_json {
763774
(
764775
$prefix_str:tt;

substrate/runtime-support/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ extern crate serde_json;
3838
pub extern crate substrate_codec as codec;
3939
pub use self::storage::generator::Storage as GenericStorage;
4040

41+
#[macro_use]
4142
pub mod dispatch;
4243
pub mod storage;
4344
mod hashable;

substrate/runtime-support/src/storage/generator.rs

Lines changed: 575 additions & 96 deletions
Large diffs are not rendered by default.

substrate/runtime/balances/src/lib.rs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -161,55 +161,55 @@ impl<A, I> From<RawEvent<A, I>> for () {
161161

162162
decl_storage! {
163163
trait Store for Module<T: Trait> as Balances {
164-
// The total amount of stake on the system.
164+
/// The total amount of stake on the system.
165165
pub TotalIssuance get(total_stake): required T::Balance;
166-
// The minimum amount allowed to keep an account open.
166+
/// The minimum amount allowed to keep an account open.
167167
pub ExistentialDeposit get(existential_deposit): required T::Balance;
168-
// The amount credited to a destination's account whose index was reclaimed.
168+
/// The amount credited to a destination's account whose index was reclaimed.
169169
pub ReclaimRebate get(reclaim_rebate): required T::Balance;
170-
// The fee required to make a transfer.
170+
/// The fee required to make a transfer.
171171
pub TransferFee get(transfer_fee): required T::Balance;
172-
// The fee required to create an account. At least as big as ReclaimRebate.
172+
/// The fee required to create an account. At least as big as ReclaimRebate.
173173
pub CreationFee get(creation_fee): required T::Balance;
174174

175-
// The next free enumeration set.
175+
/// The next free enumeration set.
176176
pub NextEnumSet get(next_enum_set): required T::AccountIndex;
177-
// The enumeration sets.
177+
/// The enumeration sets.
178178
pub EnumSet get(enum_set): default map [ T::AccountIndex => Vec<T::AccountId> ];
179179

180-
// The "free" balance of a given account.
181-
//
182-
// This is the only balance that matters in terms of most operations on tokens. It is
183-
// alone used to determine the balance when in the contract execution environment. When this
184-
// balance falls below the value of `ExistentialDeposit`, then the "current account" is
185-
// deleted: specifically `FreeBalance`. Furthermore, `OnFreeBalanceZero` callback
186-
// is invoked, giving a chance to external modules to cleanup data associated with
187-
// the deleted account.
188-
//
189-
// `system::AccountNonce` is also deleted if `ReservedBalance` is also zero (it also gets
190-
// collapsed to zero if it ever becomes less than `ExistentialDeposit`.
180+
/// The 'free' balance of a given account.
181+
///
182+
/// This is the only balance that matters in terms of most operations on tokens. It is
183+
/// alone used to determine the balance when in the contract execution environment. When this
184+
/// balance falls below the value of `ExistentialDeposit`, then the 'current account' is
185+
/// deleted: specifically `FreeBalance`. Furthermore, `OnFreeBalanceZero` callback
186+
/// is invoked, giving a chance to external modules to cleanup data associated with
187+
/// the deleted account.
188+
///
189+
/// `system::AccountNonce` is also deleted if `ReservedBalance` is also zero (it also gets
190+
/// collapsed to zero if it ever becomes less than `ExistentialDeposit`.
191191
pub FreeBalance get(free_balance): default map [ T::AccountId => T::Balance ];
192192

193-
// The amount of the balance of a given account that is exterally reserved; this can still get
194-
// slashed, but gets slashed last of all.
195-
//
196-
// This balance is a "reserve" balance that other subsystems use in order to set aside tokens
197-
// that are still "owned" by the account holder, but which are unspendable. (This is different
198-
// and wholly unrelated to the `Bondage` system used in the staking module.)
199-
//
200-
// When this balance falls below the value of `ExistentialDeposit`, then this "reserve account"
201-
// is deleted: specifically, `ReservedBalance`.
202-
//
203-
// `system::AccountNonce` is also deleted if `FreeBalance` is also zero (it also gets
204-
// collapsed to zero if it ever becomes less than `ExistentialDeposit`.
193+
/// The amount of the balance of a given account that is exterally reserved; this can still get
194+
/// slashed, but gets slashed last of all.
195+
///
196+
/// This balance is a 'reserve' balance that other subsystems use in order to set aside tokens
197+
/// that are still 'owned' by the account holder, but which are unspendable. (This is different
198+
/// and wholly unrelated to the `Bondage` system used in the staking module.)
199+
///
200+
/// When this balance falls below the value of `ExistentialDeposit`, then this 'reserve account'
201+
/// is deleted: specifically, `ReservedBalance`.
202+
///
203+
/// `system::AccountNonce` is also deleted if `FreeBalance` is also zero (it also gets
204+
/// collapsed to zero if it ever becomes less than `ExistentialDeposit`.
205205
pub ReservedBalance get(reserved_balance): default map [ T::AccountId => T::Balance ];
206206

207207

208208
// Payment stuff.
209209

210-
// The fee to be paid for making a transaction; the base.
210+
/// The fee to be paid for making a transaction; the base.
211211
pub TransactionBaseFee get(transaction_base_fee): required T::Balance;
212-
// The fee to be paid for making a transaction; the per-byte portion.
212+
/// The fee to be paid for making a transaction; the per-byte portion.
213213
pub TransactionByteFee get(transaction_byte_fee): required T::Balance;
214214
}
215215
}

substrate/runtime/contract/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,22 +144,22 @@ decl_module! {
144144

145145
decl_storage! {
146146
trait Store for Module<T: Trait> as Contract {
147-
// The fee required to create a contract. At least as big as staking's ReclaimRebate.
147+
/// The fee required to create a contract. At least as big as staking's ReclaimRebate.
148148
ContractFee get(contract_fee): required T::Balance;
149-
// The fee charged for a call into a contract.
149+
/// The fee charged for a call into a contract.
150150
CallBaseFee get(call_base_fee): required T::Gas;
151-
// The fee charged for a create of a contract.
151+
/// The fee charged for a create of a contract.
152152
CreateBaseFee get(create_base_fee): required T::Gas;
153-
// The price of one unit of gas.
153+
/// The price of one unit of gas.
154154
GasPrice get(gas_price): required T::Balance;
155-
// The maximum nesting level of a call/create stack.
155+
/// The maximum nesting level of a call/create stack.
156156
MaxDepth get(max_depth): required u32;
157-
// The maximum amount of gas that could be expended per block.
157+
/// The maximum amount of gas that could be expended per block.
158158
BlockGasLimit get(block_gas_limit): required T::Gas;
159-
// Gas spent so far in this block.
159+
/// Gas spent so far in this block.
160160
GasSpent get(gas_spent): default T::Gas;
161161

162-
// The code associated with an account.
162+
/// The code associated with an account.
163163
pub CodeOf: default map [ T::AccountId => Vec<u8> ]; // TODO Vec<u8> values should be optimised to not do a length prefix.
164164
}
165165
}

substrate/runtime/council/src/lib.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -130,53 +130,53 @@ decl_storage! {
130130
trait Store for Module<T: Trait> as Council {
131131

132132
// parameters
133-
// How much should be locked up in order to submit one's candidacy.
133+
/// How much should be locked up in order to submit one's candidacy.
134134
pub CandidacyBond get(candidacy_bond): required T::Balance;
135-
// How much should be locked up in order to be able to submit votes.
135+
/// How much should be locked up in order to be able to submit votes.
136136
pub VotingBond get(voting_bond): required T::Balance;
137-
// The punishment, per voter, if you provide an invalid presentation.
137+
/// The punishment, per voter, if you provide an invalid presentation.
138138
pub PresentSlashPerVoter get(present_slash_per_voter): required T::Balance;
139-
// How many runners-up should have their approvals persist until the next vote.
139+
/// How many runners-up should have their approvals persist until the next vote.
140140
pub CarryCount get(carry_count): required u32;
141-
// How long to give each top candidate to present themselves after the vote ends.
141+
/// How long to give each top candidate to present themselves after the vote ends.
142142
pub PresentationDuration get(presentation_duration): required T::BlockNumber;
143-
// How many votes need to go by after a voter's last vote before they can be reaped if their
144-
// approvals are moot.
143+
/// How many votes need to go by after a voter's last vote before they can be reaped if their
144+
/// approvals are moot.
145145
pub InactiveGracePeriod get(inactivity_grace_period): required VoteIndex;
146-
// How often (in blocks) to check for new votes.
146+
/// How often (in blocks) to check for new votes.
147147
pub VotingPeriod get(voting_period): required T::BlockNumber;
148-
// How long each position is active for.
148+
/// How long each position is active for.
149149
pub TermDuration get(term_duration): required T::BlockNumber;
150-
// Number of accounts that should be sitting on the council.
150+
/// Number of accounts that should be sitting on the council.
151151
pub DesiredSeats get(desired_seats): required u32;
152152

153153
// permanent state (always relevant, changes only at the finalisation of voting)
154-
// The current council. When there's a vote going on, this should still be used for executive
155-
// matters.
154+
/// The current council. When there's a vote going on, this should still be used for executive
155+
/// matters.
156156
pub ActiveCouncil get(active_council): default Vec<(T::AccountId, T::BlockNumber)>;
157-
// The total number of votes that have happened or are in progress.
157+
/// The total number of votes that have happened or are in progress.
158158
pub VoteCount get(vote_index): default VoteIndex;
159159

160160
// persistent state (always relevant, changes constantly)
161-
// The last cleared vote index that this voter was last active at.
161+
/// The last cleared vote index that this voter was last active at.
162162
pub ApprovalsOf get(approvals_of): default map [ T::AccountId => Vec<bool> ];
163-
// The vote index and list slot that the candidate `who` was registered or `None` if they are not
164-
// currently registered.
163+
/// The vote index and list slot that the candidate `who` was registered or `None` if they are not
164+
/// currently registered.
165165
pub RegisterInfoOf get(candidate_reg_info): map [ T::AccountId => (VoteIndex, u32) ];
166-
// The last cleared vote index that this voter was last active at.
166+
/// The last cleared vote index that this voter was last active at.
167167
pub LastActiveOf get(voter_last_active): map [ T::AccountId => VoteIndex ];
168-
// The present voter list.
168+
/// The present voter list.
169169
pub Voters get(voters): default Vec<T::AccountId>;
170-
// The present candidate list.
170+
/// The present candidate list.
171171
pub Candidates get(candidates): default Vec<T::AccountId>; // has holes
172172
pub CandidateCount get(candidate_count): default u32;
173173

174174
// temporary state (only relevant during finalisation/presentation)
175-
// The accounts holding the seats that will become free on the next tally.
175+
/// The accounts holding the seats that will become free on the next tally.
176176
pub NextFinalise get(next_finalise): (T::BlockNumber, u32, Vec<T::AccountId>);
177-
// The stakes as they were at the point that the vote ended.
177+
/// The stakes as they were at the point that the vote ended.
178178
pub SnapshotedStakes get(snapshoted_stakes): required Vec<T::Balance>;
179-
// Get the leaderboard if we;re in the presentation phase.
179+
/// Get the leaderboard if we;re in the presentation phase.
180180
pub Leaderboard get(leaderboard): Vec<(T::Balance, T::AccountId)>; // ORDERED low -> high
181181
}
182182
}

substrate/runtime/democracy/src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,31 +82,31 @@ decl_module! {
8282
decl_storage! {
8383
trait Store for Module<T: Trait> as Democracy {
8484

85-
// The number of (public) proposals that have been made so far.
85+
/// The number of (public) proposals that have been made so far.
8686
pub PublicPropCount get(public_prop_count): default PropIndex;
87-
// The public proposals. Unsorted.
87+
/// The public proposals. Unsorted.
8888
pub PublicProps get(public_props): default Vec<(PropIndex, T::Proposal, T::AccountId)>;
89-
// Those who have locked a deposit.
89+
/// Those who have locked a deposit.
9090
pub DepositOf get(deposit_of): map [ PropIndex => (T::Balance, Vec<T::AccountId>) ];
91-
// How often (in blocks) new public referenda are launched.
91+
/// How often (in blocks) new public referenda are launched.
9292
pub LaunchPeriod get(launch_period): required T::BlockNumber;
93-
// The minimum amount to be used as a deposit for a public referendum proposal.
93+
/// The minimum amount to be used as a deposit for a public referendum proposal.
9494
pub MinimumDeposit get(minimum_deposit): required T::Balance;
9595

96-
// How often (in blocks) to check for new votes.
96+
/// How often (in blocks) to check for new votes.
9797
pub VotingPeriod get(voting_period): required T::BlockNumber;
9898

99-
// The next free referendum index, aka the number of referendums started so far.
99+
/// The next free referendum index, aka the number of referendums started so far.
100100
pub ReferendumCount get(referendum_count): required ReferendumIndex;
101-
// The next referendum index that should be tallied.
101+
/// The next referendum index that should be tallied.
102102
pub NextTally get(next_tally): required ReferendumIndex;
103-
// Information concerning any given referendum.
103+
/// Information concerning any given referendum.
104104
pub ReferendumInfoOf get(referendum_info): map [ ReferendumIndex => (T::BlockNumber, T::Proposal, VoteThreshold) ];
105105

106-
// Get the voters for the current proposal.
106+
/// Get the voters for the current proposal.
107107
pub VotersFor get(voters_for): default map [ ReferendumIndex => Vec<T::AccountId> ];
108108

109-
// Get the vote, if Some, of `who`.
109+
/// Get the vote, if Some, of `who`.
110110
pub VoteOf get(vote_of): map [ (ReferendumIndex, T::AccountId) => bool ];
111111
}
112112
}

substrate/runtime/session/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,23 @@ impl<N> From<RawEvent<N>> for () {
105105
decl_storage! {
106106
trait Store for Module<T: Trait> as Session {
107107

108-
// The current set of validators.
108+
/// The current set of validators.
109109
pub Validators get(validators): required Vec<T::AccountId>;
110-
// Current length of the session.
110+
/// Current length of the session.
111111
pub SessionLength get(length): required T::BlockNumber;
112-
// Current index of the session.
112+
/// Current index of the session.
113113
pub CurrentIndex get(current_index): required T::BlockNumber;
114-
// Timestamp when current session started.
114+
/// Timestamp when current session started.
115115
pub CurrentStart get(current_start): required T::Moment;
116116

117-
// New session is being forced is this entry exists; in which case, the boolean value is whether
118-
// the new session should be considered a normal rotation (rewardable) or exceptional (slashable).
117+
/// New session is being forced is this entry exists; in which case, the boolean value is whether
118+
/// the new session should be considered a normal rotation (rewardable) or exceptional (slashable).
119119
pub ForcingNewSession get(forcing_new_session): bool;
120-
// Block at which the session length last changed.
120+
/// Block at which the session length last changed.
121121
LastLengthChange: T::BlockNumber;
122-
// The next key for a given validator.
122+
/// The next key for a given validator.
123123
NextKeyFor: map [ T::AccountId => T::SessionKey ];
124-
// The next session length.
124+
/// The next session length.
125125
NextSessionLength: T::BlockNumber;
126126
}
127127
}

0 commit comments

Comments
 (0)