Simple event storage with a parametrized history size
The idea is to store custom events in our pallet, access to this functionality should be limited only to one predefined account. All events older than a configured period of time should be removed automatically.
This example is a tech representation of the idea because we didn’t focus on how to use these events. The first step to change it would be to redesign the CustomEvent struct
pallet-event-storage/src/lib.rs
Lines 20 to 27 in d83af49
Parameter | Description |
---|---|
HistorySize: i64 | History size defined in seconds |
AuthorizedAccountId: AccountId | Basic account id privilaged to create custome events |
Here we have a sample from mock.rs
pallet-event-storage/src/mock.rs
Lines 29 to 32 in d83af49
The best description for the whole functionalities we will find in tests.rs
cargo test
Now we have a very basic idea for this, but not as simple as using root
as a caller. There are many good examples how to prepare this in the more advanced way. For example: pallet_sudo, pallet_membership, pallet_identity.
There are many ways how we could protect our storage better. For example, we could set a maximum number of items and a single item size. Access to the Storage should be limited as much as possible.
Frame V2 has good support for running the pallet in more than one instance, I don't see a business example of why we would like to do this with this pallet, but of course, if we have a serious need we could think about it.
We have a few public methods in our pallet. We use them only for tests. The question is if we need them, or maybe it would be possible to organize this pallet in a different way to hide everything that is possible.
Now it's a completely tech representation. With more detailed business requirements, more needs can come. This could change our idea for the map key in our Storage and how we search history items.
Now we generate simple system events after every method execution, but we don't know the external/integration requirements for this pallet, so in a serious example we should think about this part more.
Now Exception handling show that we know how to use them, but we should try to catch more negative behaviors.