From 542672167215bf682923afde9b2bcc5ee3afee73 Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Tue, 9 Jul 2024 15:32:52 +0700 Subject: [PATCH] initial spec of module --- x/asset/module.go | 1 + x/asset/spec/02_state.md | 15 +++++++++--- x/asset/spec/04_messages.md | 6 ++--- x/asset/spec/05_gov.md | 16 ++++++++++++- x/asset/spec/06_logic.md | 47 +++++++++++++++++++++---------------- 5 files changed, 58 insertions(+), 27 deletions(-) diff --git a/x/asset/module.go b/x/asset/module.go index 88ad6184..fc0ffe2f 100644 --- a/x/asset/module.go +++ b/x/asset/module.go @@ -137,6 +137,7 @@ func (am AppModule) LegacyQuerierHandler(_ *codec.LegacyAmino) sdk.Querier { // RegisterServices registers a GRPC query service to respond to the // module-specific GRPC queries. func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) types.RegisterQueryServer(cfg.QueryServer(), am.keeper) } diff --git a/x/asset/spec/02_state.md b/x/asset/spec/02_state.md index f05d8e87..97bc8e4c 100644 --- a/x/asset/spec/02_state.md +++ b/x/asset/spec/02_state.md @@ -8,6 +8,17 @@ order: 2 ### Token Management +Map: `0x00 | {Token ID} -> Token` + +```go +type Token struct { + Name string + Symbol string + Decimal string + Description string +} +``` + Map: `0x01 | {Token ID} | TokenManagement -> TokenManagement` Token management holds these information about the token: @@ -17,7 +28,7 @@ Token management holds these information about the token: * if we can add newly introduced privilege to the token later on ```go -type TokenManagement struct { +type TokenManagement struct { Manager string AddNewPrivilege bool ExcludedPrivileges []string @@ -34,8 +45,6 @@ Sub stores: `0x03 | {Token ID} | {Privilege Name}` Since each type of privilege has its own logic, we need to leave a seprate space for each of them to store their data. A privilege should manage its own store provided by the asset module, prefixed with `0x03 | {Token ID} | {Privilege Name}` -**Note:** We don't want to store the basic info of a token (name, symbol, decimal and description) as we want to utilize bank metadata for storing it instead. - ## Genesis State The `x/asset` module's `GenesisState` defines the state necessary for initializing the chain from a previous exported height. It contains the module parameters and the registered token pairs : diff --git a/x/asset/spec/04_messages.md b/x/asset/spec/04_messages.md index 93ab1e10..5182317c 100644 --- a/x/asset/spec/04_messages.md +++ b/x/asset/spec/04_messages.md @@ -51,7 +51,7 @@ type MsgAssignPrivilege struct { ## MessageUnassignPrivilege ```go -type MsgAssignPrivilege struct { +type MsgUnassignPrivilege struct { Manager string TokenID string UnassignedFrom []string @@ -77,10 +77,10 @@ type MsgDisablePrivilege struct { ```go type PrivilegeMsg interface { - Privilege() string + NeedPrivilege() string } -type MsgExecute struct { +type MsgExecutePrivilege struct { Address string TokenID string PrivilegeMsg PrivilegeMsg diff --git a/x/asset/spec/05_gov.md b/x/asset/spec/05_gov.md index 6f419451..f2c7c9b9 100644 --- a/x/asset/spec/05_gov.md +++ b/x/asset/spec/05_gov.md @@ -2,4 +2,18 @@ order: 5 --> -# Client +# Gov proposals + +The asset module supports the following types of gov proposals: + +## TokenCreatorWhitelistProposal + +This proposal allows the community to decide on what addresses are allowed to create token via the asset module. + +## AddPrilegeProposal + +This proposal functioning similarly to the `SoftwareUpgradeProposal`. It specifies the `Privilege` that will be added into the privilege system. Then, It'll stop the chain at a specified height so that a new binary that contains logic for the specified `Privilege` is switched in to continue running the chain. After said process is finished, the new `Privilege` will be available on chain. + +## ExecutePrivilege + +These types of proposals is implemented as sdk.msg with respective handling methods following `gov.v1beta` standard. diff --git a/x/asset/spec/06_logic.md b/x/asset/spec/06_logic.md index 39715200..86dfb6a8 100644 --- a/x/asset/spec/06_logic.md +++ b/x/asset/spec/06_logic.md @@ -17,7 +17,7 @@ Validation: Flow: -1. The denom for the token will be derived from `Creator` and `Symbol` with the format of `asset/{Manager}/{Symbol}` +1. The denom for the token will be derived from `Creator` and `Symbol` with the format of `asset/{Creator}/{Symbol}` 2. Save the token basic information (name, symbol, decimal and description) in the x/bank metadata store 3. Save the token management info (`Manager`, `ExcludedPrivileges` and `AddNewPrivilege`) in the x/asset store. @@ -25,32 +25,39 @@ Note that here we prefixed the token denom with the manager address in order to ## Register a privilege -Each type of privilege enables a set of messages to be executed. +To intergrate with the `asset module` Each type of privilege has to implement this interface -MintPrivilege { - storeKey - mintKeeper MintKeeper - bankKeeper BankKeeper +```go +type Privilege interface { + RegisterInterfaces() + MsgHandler() MsgHandler + QueryHandler() QueryHandler + CLI() *cobra.Command } -func Wrap +type MsgHandler func(context Context, privMsg PrivilegeMsg) error -```go -type handler func(ctx, store, msg) +type QueryHandler func(context Context, privQuery PrivilegeQuery) error +``` +This interface provides all the functionality necessary for a privilege, including a message handler, query handler and cli -MintPrivilege func Handle (ctx, store, msg) error{ - func +All the `PrivilegeMsg` of a privilege should return the name of that privilege when called `NeedPrivilege()`. A message handler should handle all the `PrivilegeMsg` of that privilege. +When adding a `Privilege`, we calls `PrivilegeManager.AddPrivilege()` in `app.go` which inturn maps all the `PrivilegeMsg` of that privilege to its `MsgHandler`. This mapping logic will later be used when running a `MsgExecutePrivilege` -} +## Flow of MsgExecutePrivilege -type Privilege interface { - - RegisterMsgHandlers(msgType string, MsgHandler func(ctx, store, msg) ) - RegisterCodec() - RegisterQuerier(queryType string, ) - -} +This process is triggered by the `MsgExecutePrivilege`. + +Validation: + +- Checks if the token specified in the msg exists. +- Checks if the privilege is supported. +- Checks if the `Msg.Address` has the corresponding `Privilege` specified by `PrivilegeMsg.NeedPrivilege()` + +Flow: -``` \ No newline at end of file +- Prepare store for the privilege of the token via `MakePrivilegeStore(privilege name, token denom)`. That store is the only store accessable by the privilege's `MsgHandler`. +- `PrivilegeManager` routes the `PrivilegeMsg` to the its `MsgHandler`. +- `MsgHandler` now handles the `PrivilegeMsg`.