Skip to content

網關

此模塊負責網關鏈上數據的管理

chat/
├── client
│   └── rest
│        ├── error.go          # 介面錯誤集
│        ├── grpc.go           # grpc査詢方法
│        ├── handle_comm.go    # comm模塊消息前置處理
│        ├── handle_msg.go    # comm模塊消息前置處理
│        ├── query.go          # 介面査詢函數
│        ├── rest.go           # 消息與査詢路由的注册
│        └── tx.go             # tx相關方法,包括廣播等
├── keeper
│   ├── hooks.go          # 鉤子函數,被其他模塊邏輯觸發
│   ├── keeper.go         # 存儲管理器,處理模塊的業務邏輯,並有許可權訪問狀態樹的特定子樹
│   ├── msg_server.go     # 提供上鏈消息的服務處理邏輯
│   ├── params.go         # 模塊參數的設定和獲取
│   ├── query.go          # 狀態査詢函數
├── types
│   ├── codec.go          # 編碼注册類型
│   ├── errors.go         # 模塊特定的錯誤
│   ├── events.go         # 向Tendermint PubSub/Websocket暴露的事件
│   ├── genesis.go        # 模塊的創世狀態
│   ├── interface.go      # 模塊的介面集合
│   ├── keys.go           # 模塊存儲key以及一些其他的常數
│   ├── msg.go            # 聊天模塊交易消息
│   ├── params.go         # 模塊可以通過治理模塊修改的自定義參數
│   ├── interface.go      # 引入的外部模块实现的方法
│   └── types.go          # 模塊的類型集合
├── genesis.go            # ABCI的創世狀態初始化和匯出功能
├── handler.go            # 消息路由
└── module.go             # 模塊管理器的模塊設定

目录

網關

gateway模塊負責網關鏈上數據的管理,包括號碼段的歸屬,獲得等

網關信息

網關註冊需要填寫網關的名稱、網關通訊地址、APP打包的名稱及首個號碼段信息。網關通訊地址支持IP及域名,需要綁定50327通訊端口。 APP包名需要以小寫字母開頭進行命名,長度不可超過32位。 網關不可以重複註冊,每個DPOS節點只能註冊一個網關。網關信息支持修改名稱和網關通訊地址。 🚨 危險: 一旦修改網關通訊地址後,網關的聊天信息將會被重置,請謹慎操作。

號碼段

首次註冊網關必須填寫一個號碼段,該號碼段會標記為網關的首個號碼段作為通訊域名使用。 號碼段長度可以為5、6、7,當網關號碼段額度足夠時,支持添加多個號碼段。 號碼段分為三種狀態 :綁定中、贖回中、和已解綁。已綁定和贖回中的號碼段不能被其他網關所使用,贖回中的號碼段默認一年的保護期,當網關所有者再次質押後,可以再次選擇該號碼段並進行綁定。 已解綁的號碼段可以被所有網關再次使用。

網關質押與贖回

默認每質押10個FM可以獲得一個網關號碼段額度。 當網關所有者進行DPOS贖回時,對應每贖回10個FM就要對應贖回一個號碼段或減少對應號碼段的額度。 當部分贖回時,首個號碼段不允許贖回,只能選擇其他號碼段。如果是質押全部贖回,則贖回所有號碼段。 全部質押贖回後,網關狀態變為不可用狀態。

功能

合約模塊Keeper授予對聊天模塊狀態的存取權限並實現statedb,以支持StateDB實現。 Keeper包含一個允許資料庫的存儲鍵寫入只能由Chat模塊訪問的多庫的具體子樹。 而不是使用樹和資料庫進行査詢和持久化(StateDB實現),DaoDst使用Cosmos的KVStore(鍵值存儲)和Cosmos SDK的Keeper來促進狀態轉換。

為了支持介面功能,它導入了7個模塊Keepers:

  • auth: 帳號的增刪改查
  • bank: 供應量和餘額的增刪改查
  • staking: 閘道相關資料的管理
  • pledge: 聊天相關數據的管理
  • evm: evm相關數據的管理
  • chat: 聊天相關資料的管理
  • gateway: 閘道資料管理
    type Keeper struct {
        storeKey   sdk.StoreKey
        cdc        codec.BinaryCodec
        paramstore paramtypes.Subspace

        stakingKeeper *stakingKeeper.Keeper
        accountKeeper types.AccountKeeper
        BankKeeper    types.BankKeeper
        pledgeKeeper  types.PledgeKeeper
        evmKeeper     types.EVMKeeper
        chatKeeper    types.ChatKeeper
        gatewayKeeper types.GatewayKeeper
        erc20Keeper   erc20keeper.Keeper
    }

消息

MsgAppTokenIssue

通過此消息,備份網關的驗證器密鑰等信息
    type MsgGatewayUpload struct {
        FromAddress    string `protobuf:"bytes,1,opt,name=fromAddress,proto3" json:"fromAddress,omitempty" yaml:"from_address"`
        GatewayKeyInfo []byte `protobuf:"bytes,2,opt,name=GatewayKeyInfo,proto3" json:"GatewayKeyInfo,omitempty" yaml:"gateway_key_info"`
    }

MsgGatewayRegister

通過此消息,註冊成為網關,並獲得did號段
    type MsgGatewayRegister struct {
        Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"`
        GatewayName string `protobuf:"bytes,2,opt,name=gateway_name,json=gatewayName,proto3" json:"gateway_name,omitempty"`
        GatewayUrl string `protobuf:"bytes,3,opt,name=gateway_url,json=gatewayUrl,proto3" json:"gateway_url,omitempty"`
        Delegation string `protobuf:"bytes,4,opt,name=delegation,proto3" json:"delegation,omitempty"`
        IndexNumber []string `protobuf:"bytes,5,rep,name=index_number,json=indexNumber,proto3" json:"index_number,omitempty"`
    }

MsgGatewayIndexNum

通過此消息,網關可以通過質押獲取額外的did號碼段
    type MsgGatewayIndexNum struct {
        DelegatorAddress string `protobuf:"bytes,1,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty" yaml:"delegator_address"`
        ValidatorAddress string `protobuf:"bytes,2,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty" yaml:"validator_address"`
        IndexNumber []string `protobuf:"bytes,3,rep,name=index_number,json=indexNumber,proto3" json:"index_number,omitempty"`
    }

MsgGatewayUndelegate

通過此消息,網關可以贖回質押
    type MsgGatewayUndelegate struct {
        DelegatorAddress string      `protobuf:"bytes,1,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty" yaml:"delegator_address"`
        ValidatorAddress string      `protobuf:"bytes,2,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty" yaml:"validator_address"`
        Amount           types1.Coin `protobuf:"bytes,3,opt,name=amount,proto3" json:"amount"`
        IndexNumber []string `protobuf:"bytes,4,rep,name=index_number,json=indexNumber,proto3" json:"index_number,omitempty"`
    }

參數

gateway模塊包含如下模塊參數

參數

Key 類型 預設值
IndexNumHeight int64 100
RedeemFeeHeight int64 432000
RedeemFee github_com_cosmos_cosmos_sdk_types.Dec 0.1
MinDelegate github_com_cosmos_cosmos_sdk_types.Coin 10000000000000000000000fm
Validity int64 5256000