Chat
Abstract
This document specifies the chat module of the DaoDst.
Contents
Module Architecture
NOTE:: If you're not familiar with the overall module structure from the SDK modules, please check this document as prerequisite reading.
chat/
βββ client
β βββ rest
β βββ error.go # errors for api
β βββ grpc.go # query method fro grpc
β βββ handle_account.go # Account details acquisition and processing
β βββ handle_chat.go # Chat module message preprocessing
β βββ query.go # Interface Query Function
β βββ rest.go # Registration of Message and Query Routes
β βββ tx.go # Tx related methods, including broadcasting, etc
βββ keeper
β βββ genesis.go # Genesis state for the module
β βββ keeper.go # Store keeper that handles the business logic of the module and has access to a specific subtree of the state tree.
β βββ msg_server.go # Provide message service processing logic
β βββ params.go # Parameter getter and setter
β βββ query.go # State query functions
βββ types
βΒ Β βββ codec.go # Type registration for encoding
βΒ Β βββ errors.go # Module-specific errors
βΒ Β βββ events.go # Events exposed to the Tendermint PubSub/Websocket
βΒ Β βββ genesis.go # Genesis state for the module
βΒ Β βββ interface.go # interface of the module
βΒ Β βββ keys.go # Store keys and utility functions
βΒ Β βββ msg.go # chat module transaction messages
βΒ Β βββ params.go # Module parameters that can be customized with governance parameter change proposals
βΒ Β βββ types.go # Type collection of modules
βββ genesis.go # ABCI InitGenesis and ExportGenesis functionality
βββ handler.go # Message routing
βββ module.go # Module setup for the module manager
Concepts
Chat
DaoDst, as a blockchain with decentralized chat, mainly manages the chat data on the chain through the 'x/chat' module, When a user registers for a chat, a broadcast will be initiated, recording the user's address, gateway, DID, chat, and other information on the chain. When other functions or modules need to call these data, they also need to be obtained through the chat module
State
The Chat module stores basic on chain data about chat users
// User Info
type UserInfo struct {
//Wallet address
FromAddress string `json:"from_address" yaml:"from_address"`
//Register Gateway
RegisterNodeAddress string `json:"register_node_address" yaml:"register_node_address"`
//Current gateway
NodeAddress string `json:"node_address" yaml:"node_address"`
//address book
AddressBook string `json:"address_book" yaml:"address_book"`
//Address book blacklist (user public key encryption)
ChatBlacklist string `json:"chat_blacklist" yaml:"chat_blacklist"`
//Chat restriction mode (feel | any | list)
ChatRestrictedMode string `json:"chat_restricted_mode" yaml:"chat_restricted_mode"`
//Address book whitelist (user public key encryption)
ChatWhitelist string `json:"chat_whitelist" yaml:"chat_whitelist"`
//Chat fee
ChatFee types.Coin `json:"chat_fee" yaml:"chat_fee"`
//Holding a mobile phone number
Mobile []string `json:"mobile" yaml:"mobile"`
//Last update time
UpdateTime int64 `json:"update_time" yaml:"update_time"`
//Address book blacklist (gateway public key encryption)
ChatBlackEncList string `json:"chat_black_enc_list" yaml:"chat_black_enc_list"`
//Address book whitelist (gateway public key encryption)
ChatWhiteEncList string `json:"chat_white_enc_list" yaml:"chat_white_enc_list" `
//remarks
Remarks string `json:"remarks" yaml:"remarks"`
}
Users will initialize it during registration, The ChatRestrictedMode and ChatFee parameters regarding chat fees will have default values Most of the business logic of the Chat module is based on this structure
DID
When registering, users need to select the gateway they belong to and select a number range that belongs to the gateway Under this number range, users will receive a unique number (DID) that belongs to the wallet address (even if the gateway no longer exists) Outside of the preceding number range, subsequent numbers are incremented
For example, in the 8888888 number segment of a certain gateway, the number in this segment has already reached 1234 So the next person to choose this number range will receive a number of 8888881235
In addition to registration, you can also proactively destroy to obtain DID
Did can voluntarily transfer
Destruction and Pledge
When registering for chat, a certain number of DSTs need to be destroyed. At the same time, the registration contract will automatically pledge the destroyed hash coins to the Pledge module, thereby obtaining a pledge reward
Chat charging mode
When users register, the default chat charging mode is "fee", and users can change it themselves
There are three modes as follows
- fee
After activating the fee mode, initiating a chat or pulling into a room requires a certain fee to be paid
- any
After opening any mode, anyone can initiate a chat with you voluntarily
- list
After turning on the whitelist mode, only the addresses on the whitelist can initiate a chat with you (the whitelist settings belong to the chat module)
Keeper
The Chat module Keeper
grants access to the Chat module state
and implements statedb.Keeper
interface to support the StateDB
implementation.
The Keeper contains a store key that allows the DB
to write to a concrete subtree of the multistore that is only accessible by the Chat module.
Instead of using a trie and database for querying and persistence (the StateDB
implementation),
Daodst uses the Cosmos KVStore
(key-value store) and Cosmos SDK Keeper
to facilitate state transitions.
To support the interface functionality, it imports 4 module Keepers:
auth
: CURD for accountsbank
: CURD for supply and balancecomm
: Management of gateway related datapledge
: Pledge, Destruction, and Rewards
type Keeper struct {
storeKey sdk.StoreKey
cdc codec.BinaryCodec
paramstore paramtypes.Subspace
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
commKeeper commkeeper.Keeper
pledgeKeeper pledgekeeper.Keeper
}
Messages
MsgSendGift
Register the address to the chat module and initialize the corresponding information through this message
type MsgRegister struct {
FromAddress string `protobuf:"bytes,1,opt,name=from_address,json=fromAddress,proto3" json:"from_address,omitempty" yaml:"from_address"`
NodeAddress string `protobuf:"bytes,2,opt,name=node_address,json=nodeAddress,proto3" json:"node_address,omitempty" yaml:"node_address"`
MortgageAmount types.Coin `protobuf:"bytes,3,opt,name=mortgage_amount,json=mortgageAmount,proto3" json:"mortgage_amount" yaml:"mortgage_amount"`
MobilePrefix string `protobuf:"bytes,4,opt,name=mobile_prefix,json=mobilePrefix,proto3" json:"mobile_prefix,omitempty" yaml:"mobile_prefix"`
}
MsgSetChatInfo
Modify the data stored in the chat module corresponding to the address through this message, which accepts the full amount of user data and overwrites the original data
type MsgSetChatInfo struct {
FromAddress string `protobuf:"bytes,1,opt,name=from_address,json=fromAddress,proto3" json:"from_address,omitempty" yaml:"from_address"`
NodeAddress string `protobuf:"bytes,2,opt,name=node_address,json=nodeAddress,proto3" json:"node_address,omitempty" yaml:"node_address"`
AddressBook string `protobuf:"bytes,3,opt,name=address_book,json=addressBook,proto3" json:"address_book,omitempty" yaml:"address_book"`
ChatBlacklist string `protobuf:"bytes,4,opt,name=chat_blacklist,json=chatBlacklist,proto3" json:"chat_blacklist,omitempty" yaml:"chat_blacklist"`
ChatRestrictedMode string `protobuf:"bytes,5,opt,name=chat_restricted_mode,json=chatRestrictedMode,proto3" json:"chat_restricted_mode,omitempty" yaml:"chat_limit"`
ChatFee types.Coin `protobuf:"bytes,6,opt,name=chat_fee,json=chatFee,proto3" json:"chat_fee" yaml:"chat_fee"`
ChatWhitelist string `protobuf:"bytes,7,opt,name=chat_whitelist,json=chatWhitelist,proto3" json:"chat_whitelist,omitempty" yaml:"chat_whitelist"`
UpdateTime int64 `protobuf:"varint,8,opt,name=update_time,json=updateTime,proto3" json:"update_time,omitempty" yaml:"update_time"`
ChatBlacklistEnc string `protobuf:"bytes,9,opt,name=chat_blacklist_enc,json=chatBlacklistEnc,proto3" json:"chat_blacklist_enc,omitempty" yaml:"chat_blacklist_enc"`
ChatWhitelistEnc string `protobuf:"bytes,10,opt,name=chat_whitelist_enc,json=chatWhitelistEnc,proto3" json:"chat_whitelist_enc,omitempty" yaml:"chat_whitelist_enc"`
}
MsgBurnGetMobile
By destroying this message, the did is obtained. The prefix of the obtained did is the selected did number segment, and the suffix is incremented under this number segment
If the number segment does not match the gateway or the number under the segment is full, the acquisition fails
type MsgBurnGetMobile struct {
FromAddress string `protobuf:"bytes,1,opt,name=from_address,json=fromAddress,proto3" json:"from_address,omitempty" yaml:"from_address"`
MobilePrefix string `protobuf:"bytes,2,opt,name=mobile_prefix,json=mobilePrefix,proto3" json:"mobile_prefix,omitempty" yaml:"mobile_prefix"`
}
MsgMobileTransfer
The held DID can be transferred
If the other party's hold of DID has reached the maximum holding amount, the transfer fails
type MsgMobileTransfer struct {
FromAddress string `protobuf:"bytes,1,opt,name=from_address,json=fromAddress,proto3" json:"from_address,omitempty" yaml:"from_address"`
ToAddress string `protobuf:"bytes,2,opt,name=to_address,json=toAddress,proto3" json:"to_address,omitempty" yaml:"to_address"`
Mobile string `protobuf:"bytes,3,opt,name=mobile,proto3" json:"mobile,omitempty" yaml:"mobile"`
}
MsgChatSendGift
Chat payment. If the other party has set a chat fee, this message needs to be sent to pay a certain token to the other party
type MsgChatSendGift struct {
FromAddress string `protobuf:"bytes,1,opt,name=from_address,json=fromAddress,proto3" json:"from_address,omitempty" yaml:"from_address"`
ToAddress string `protobuf:"bytes,2,opt,name=to_address,json=toAddress,proto3" json:"to_address,omitempty" yaml:"to_address"`
GiftValue types.Coin `protobuf:"bytes,3,opt,name=gift_value,json=giftValue,proto3" json:"gift_value" yaml:"gift_value"`
}
Parameters
The chat module contains the following module parameters
Params
Key | Type | Default Value |
---|---|---|
MaxPhoneNumber |
uint64 | 10 |
DestroyPhoneNumberCoin |
github.com/cosmos/cosmos-sdk/types.Coin | 100000000000000000000dst |
ChatFee |
github.com/cosmos/cosmos-sdk/types.Coin | 1000000000000000000dst |
MinRegisterBurnAmount |
github.com/cosmos/cosmos-sdk/types.Coin | 100000000000000000000dst |