Skip to content

Commit

Permalink
initial spec of module
Browse files Browse the repository at this point in the history
  • Loading branch information
catShaark committed Jul 9, 2024
1 parent 792140d commit 5426721
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 27 deletions.
1 change: 1 addition & 0 deletions x/asset/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
15 changes: 12 additions & 3 deletions x/asset/spec/02_state.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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 :
Expand Down
6 changes: 3 additions & 3 deletions x/asset/spec/04_messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type MsgAssignPrivilege struct {
## MessageUnassignPrivilege

```go
type MsgAssignPrivilege struct {
type MsgUnassignPrivilege struct {
Manager string
TokenID string
UnassignedFrom []string
Expand All @@ -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
Expand Down
16 changes: 15 additions & 1 deletion x/asset/spec/05_gov.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
47 changes: 27 additions & 20 deletions x/asset/spec/06_logic.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,47 @@ 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.

Note that here we prefixed the token denom with the manager address in order to allow many different creators to create token with the same symbol, differentiate their denom by including in their creator.

## 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:

```
- 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`.

0 comments on commit 5426721

Please sign in to comment.