Git Product home page Git Product logo

pallet-event-storage's Introduction

Pallet EventStorage

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

#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)]
#[scale_info(skip_type_params(T))]
pub struct CustomEvent<T: Config> {
// This is a very tech example, to make it more useful from business perspective this should be the first place to expand.
//pub time_stamp: i64, <<--- we have this as a key, but probably for more complex business operation we can need this inside as well.
pub content: Vec<u8>,
pub reporter: <T as frame_system::Config>::AccountId, //we limited access to our method so we could remove this from here as well.
}

Parametrization

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

parameter_types! {
pub const HistorySize: i64 = 2; // Here we set up a short history size (in seconds)
pub const AuthorizedAccountId: AccountId = 1;//Very basic idea for caller identity limitation
}

How to test it?

The best description for the whole functionalities we will find in tests.rs

cargo test

What we could do better?

1. Caller verification

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.

2. Storage

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.

3. Public methods

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.

4. CustomEvent - structure

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.

5. CustomEvents vs Pallet Events

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.

6. Errors

Now Exception handling show that we know how to use them, but we should try to catch more negative behaviors.

pallet-event-storage's People

Contributors

czareko avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.