Reputation: 1480
I want to create a StorageMap in substrate and am following this example to do that. The purpose of the storage map is to have a HashMap where the key will be the account ID of the user and the value will be the count of how many times an invalid transaction has been done. For example:
Adkqwd4324dqlwdOqwdd: 2,
XCvqwd4324dqlwdOqwdd: 0,
Adkqwd4324dqlwdOqwPu: 0,
Xcvqwd4324dqlwdOqwdd: 1
My current decl_storage macro inside transaction_payment>src>lib.rs looks like this:
decl_storage! {
/// StorageMap to keep track of invalid transactions
trait Store for Module<T: Trait> as InvalidTransactionCount {
InvalidTransactionCount get(fn invalid_transaction_count): map hasher(identity) T::AccountId => u32;
}
/// already present in the substrate master code
trait Store for Module<T: Config> as TransactionPayment {
pub NextFeeMultiplier get(fn next_fee_multiplier): Multiplier = Multiplier::saturating_from_integer(1);
StorageVersion build(|_: &GenesisConfig| Releases::V2): Releases;
}
}
However, when I compile this code, I am getting errors related to NextFeeMultiplier because it is not being initialized properly due to the error in the decl_storage macro because of InvalidTransactionCount StorageMap. Full traceback of error is given below:
error: unexpected token
--> frame/transaction-payment/src/lib.rs:242:2
|
242 | trait Store for Module<T: Config> as TransactionPayment {
| ^^^^^
error[E0433]: failed to resolve: use of undeclared type `NextFeeMultiplier`
--> frame/transaction-payment/src/lib.rs:259:4
|
259 | NextFeeMultiplier::mutate(|fm| {
| ^^^^^^^^^^^^^^^^^ use of undeclared type `NextFeeMultiplier`
error[E0433]: failed to resolve: use of undeclared type `NextFeeMultiplier`
--> frame/transaction-payment/src/lib.rs:446:3
|
446 | NextFeeMultiplier::get().saturating_mul_int(Self::weight_to_fee(weight))
| ^^^^^^^^^^^^^^^^^ use of undeclared type `NextFeeMultiplier`
error[E0599]: no function or associated item named `next_fee_multiplier` found for struct `Module<T>` in the current scope
--> frame/transaction-payment/src/lib.rs:414:27
|
249 | / decl_module! {
250 | | pub struct Module<T: Config> for enum Call where origin: T::Origin {
251 | | /// The fee to be paid for making a transaction; the per-byte portion.
252 | | const TransactionByteFee: BalanceOf<T> = T::TransactionByteFee::get();
... |
304 | | }
305 | | }
| |_- function or associated item `next_fee_multiplier` not found for this
...
414 | let multiplier = Self::next_fee_multiplier();
| ^^^^^^^^^^^^^^^^^^^ function or associated item
not found in `Module<T>`
warning: unused import: `StorageMap`
--> frame/transaction-payment/src/lib.rs:46:2
|
46 | StorageMap,
| ^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
error: aborting due to 4 previous errors; 1 warning emitted
Some errors have detailed explanations: E0433, E0599.
For more information about an error, try `rustc --explain E0433`.
error: could not compile `pallet-transaction-payment`
If I remove the InvalidTransactionCount trait Store from the decl_storage, then the code is being compiled fine.
Any help in identifying the correct way to declare a storage map inside the decl_storage macro will be highly appreciated. Thanks!
Upvotes: 0
Views: 576
Reputation: 2865
This line only can be written once. In the decl_module
macro.
trait Store for Module<T: Config> as TransactionPayment {
If you want multi storage item just:
decl_storage! {
trait Store for Module<T: Trait> as InvalidTransactionCount {
InvalidTransactionCount get(fn invalid_transaction_count): map hasher(identity) T::AccountId => u32;
pub NextFeeMultiplier get(fn next_fee_multiplier): Multiplier = Multiplier::saturating_from_integer(1);
StorageVersion build(|_: &GenesisConfig| Releases::V2): Releases;
}
}
Upvotes: 2