Documentation
¶
Index ¶
- Constants
- Variables
- func RegisterCodec(cdc *codec.Codec)
- func ValidateGenesis(data GenesisState) error
- type GenesisState
- type KeyValue
- type MsgAddPostReaction
- type MsgCreatePost
- type MsgEditPost
- type MsgRemovePostReaction
- type OptionalData
- type Post
- type PostID
- type PostIDs
- type PostQueryResponse
- type Posts
- type QueryPostsParams
- type Reaction
- type Reactions
- func (reactions Reactions) AppendIfMissing(other Reaction) (Reactions, bool)
- func (reactions Reactions) ContainsReactionFrom(user sdk.Address, value string) bool
- func (reactions Reactions) IndexOfByUserAndValue(owner sdk.Address, value string) int
- func (reactions Reactions) RemoveReaction(user sdk.Address, value string) (Reactions, bool)
Constants ¶
const ( EventTypePostCreated = "post_created" EventTypePostEdited = "post_edited" EventTypeReactionAdded = "post_reaction_added" EventTypePostReactionRemoved = "post_reaction_removed" // Post attributes AttributeKeyPostID = "post_id" AttributeKeyPostParentID = "post_parent_id" AttributeKeyPostOwner = "post_owner" AttributeKeyPostEditTime = "post_edit_time" // Reaction attributes AttributeKeyReactionOwner = "user" AttributeKeyReactionValue = "reaction" // Generic attributes AttributeKeyCreationTime = "creation_time" )
Magpie module event types
const ( ModuleName = "posts" RouterKey = ModuleName StoreKey = ModuleName PostStorePrefix = "post:" LastPostIDStoreKey = "last_post_id" PostCommentsStorePrefix = "comments:" PostReactionsStorePrefix = "reactions:" MaxPostMessageLength = 500 MaxOptionalDataFieldsNumber = 10 MaxOptionalDataFieldValueLength = 200 ActionCreatePost = "create_post" ActionEditPost = "edit_post" ActionAddPostReaction = "add_post_reaction" ActionRemovePostReaction = "remove_post_reaction" // Queries QuerierRoute = ModuleName QueryPost = "post" QueryPosts = "posts" )
Variables ¶
var ModuleCdc = codec.New()
ModuleCdc is the codec
Functions ¶
func RegisterCodec ¶
RegisterCodec registers concrete types on the Amino codec
func ValidateGenesis ¶ added in v0.2.0
func ValidateGenesis(data GenesisState) error
ValidateGenesis validates the given genesis state and returns an error if something is invalid
Types ¶
type GenesisState ¶ added in v0.2.0
type GenesisState struct {
Posts Posts `json:"posts"`
Reactions map[string]Reactions `json:"reactions"`
}
GenesisState contains the data of the genesis state for the posts module
func DefaultGenesisState ¶ added in v0.2.0
func DefaultGenesisState() GenesisState
DefaultGenesisState returns a default GenesisState
type KeyValue ¶ added in v0.2.0
KeyValue is a simple key/value representation of one field of a OptionalData.
type MsgAddPostReaction ¶ added in v0.2.0
type MsgAddPostReaction struct {
PostID PostID `json:"post_id"` // Id of the post to react to
Value string `json:"value"` // Reaction of the reaction
User sdk.AccAddress `json:"user"` // Address of the user reacting to the post
}
MsgAddPostReaction defines the message to be used to add a reaction to a post
func NewMsgAddPostReaction ¶ added in v0.2.0
func NewMsgAddPostReaction(postID PostID, value string, user sdk.AccAddress) MsgAddPostReaction
NewMsgAddPostReaction is a constructor function for MsgAddPostReaction
func (MsgAddPostReaction) GetSignBytes ¶ added in v0.2.0
func (msg MsgAddPostReaction) GetSignBytes() []byte
GetSignBytes encodes the message for signing
func (MsgAddPostReaction) GetSigners ¶ added in v0.2.0
func (msg MsgAddPostReaction) GetSigners() []sdk.AccAddress
GetSigners defines whose signature is required
func (MsgAddPostReaction) Route ¶ added in v0.2.0
func (msg MsgAddPostReaction) Route() string
Route should return the name of the module
func (MsgAddPostReaction) Type ¶ added in v0.2.0
func (msg MsgAddPostReaction) Type() string
Type should return the action
func (MsgAddPostReaction) ValidateBasic ¶ added in v0.2.0
func (msg MsgAddPostReaction) ValidateBasic() sdk.Error
ValidateBasic runs stateless checks on the message
type MsgCreatePost ¶
type MsgCreatePost struct {
ParentID PostID `json:"parent_id"`
Message string `json:"message"`
AllowsComments bool `json:"allows_comments"`
Subspace string `json:"subspace"`
OptionalData map[string]string `json:"optional_data,omitempty"`
Creator sdk.AccAddress `json:"creator"`
CreationDate time.Time `json:"creation_date"`
}
MsgCreatePost defines a CreatePost message
func NewMsgCreatePost ¶
func NewMsgCreatePost(message string, parentID PostID, allowsComments bool, subspace string, optionalData map[string]string, owner sdk.AccAddress, creationDate time.Time) MsgCreatePost
NewMsgCreatePost is a constructor function for MsgSetName
func (MsgCreatePost) GetSignBytes ¶
func (msg MsgCreatePost) GetSignBytes() []byte
GetSignBytes encodes the message for signing
func (MsgCreatePost) GetSigners ¶
func (msg MsgCreatePost) GetSigners() []sdk.AccAddress
GetSigners defines whose signature is required
func (MsgCreatePost) MarshalJSON ¶ added in v0.2.0
func (msg MsgCreatePost) MarshalJSON() ([]byte, error)
MarshalJSON implements the custom marshaling as Amino does not support the JSON signature omitempty
func (MsgCreatePost) Route ¶
func (msg MsgCreatePost) Route() string
Route should return the name of the module
func (MsgCreatePost) ValidateBasic ¶
func (msg MsgCreatePost) ValidateBasic() sdk.Error
ValidateBasic runs stateless checks on the message
type MsgEditPost ¶
type MsgEditPost struct {
PostID PostID `json:"post_id"`
Message string `json:"message"`
Editor sdk.AccAddress `json:"editor"`
EditDate time.Time `json:"edit_date"`
}
MsgEditPost defines the EditPostMessage message
func NewMsgEditPost ¶
func NewMsgEditPost(id PostID, message string, owner sdk.AccAddress, editDate time.Time) MsgEditPost
NewMsgEditPost is the constructor function for MsgEditPost
func (MsgEditPost) GetSignBytes ¶
func (msg MsgEditPost) GetSignBytes() []byte
GetSignBytes encodes the message for signing
func (MsgEditPost) GetSigners ¶
func (msg MsgEditPost) GetSigners() []sdk.AccAddress
GetSigners defines whose signature is required
func (MsgEditPost) Route ¶
func (msg MsgEditPost) Route() string
Route should return the name of the module
func (MsgEditPost) ValidateBasic ¶
func (msg MsgEditPost) ValidateBasic() sdk.Error
ValidateBasic runs stateless checks on the message
type MsgRemovePostReaction ¶ added in v0.2.0
type MsgRemovePostReaction struct {
PostID PostID `json:"post_id"` // Id of the post to unlike
User sdk.AccAddress `json:"user"` // Address of the user that has previously liked the post
Reaction string `json:"reaction"` // Reaction of the reaction to be removed
}
MsgRemovePostReaction defines the message to be used when wanting to remove an existing reaction from a specific user having a specific value
func NewMsgRemovePostReaction ¶ added in v0.2.0
func NewMsgRemovePostReaction(postID PostID, user sdk.AccAddress, reaction string) MsgRemovePostReaction
MsgUnlikePostPost is the constructor of MsgRemovePostReaction
func (MsgRemovePostReaction) GetSignBytes ¶ added in v0.2.0
func (msg MsgRemovePostReaction) GetSignBytes() []byte
GetSignBytes encodes the message for signing
func (MsgRemovePostReaction) GetSigners ¶ added in v0.2.0
func (msg MsgRemovePostReaction) GetSigners() []sdk.AccAddress
GetSigners defines whose signature is required
func (MsgRemovePostReaction) Route ¶ added in v0.2.0
func (msg MsgRemovePostReaction) Route() string
Route should return the name of the module
func (MsgRemovePostReaction) Type ¶ added in v0.2.0
func (msg MsgRemovePostReaction) Type() string
Type should return the action
func (MsgRemovePostReaction) ValidateBasic ¶ added in v0.2.0
func (msg MsgRemovePostReaction) ValidateBasic() sdk.Error
ValidateBasic runs stateless checks on the message
type OptionalData ¶ added in v0.2.0
OptionalData represents a Posts' optional data and allows for custom Amino and JSON serialization and deserialization.
func (OptionalData) MarshalAmino ¶ added in v0.2.0
func (m OptionalData) MarshalAmino() ([]KeyValue, error)
MarshalAmino transforms the OptionalData to an array of key/value.
func (OptionalData) MarshalJSON ¶ added in v0.2.0
func (m OptionalData) MarshalJSON() ([]byte, error)
MarshalJSON implements encode.Marshaler
func (*OptionalData) UnmarshalAmino ¶ added in v0.2.0
func (m *OptionalData) UnmarshalAmino(keyValues []KeyValue) error
UnmarshalAmino transforms the key/value array to a OptionalData.
func (*OptionalData) UnmarshalJSON ¶ added in v0.2.0
func (m *OptionalData) UnmarshalJSON(data []byte) error
UnmarshalJSON implements decode.Unmarshaler
type Post ¶
type Post struct {
PostID PostID `json:"id"` // Unique id
ParentID PostID `json:"parent_id"` // Post of which this one is a comment
Message string `json:"message"` // Message contained inside the post
Created time.Time `json:"created"` // RFC3339 date at which the post has been created
LastEdited time.Time `json:"last_edited"` // RFC3339 date at which the post has been edited the last time
AllowsComments bool `json:"allows_comments"` // Tells if users can reference this PostID as the parent
Subspace string `json:"subspace"` // Identifies the application that has posted the message
OptionalData OptionalData `json:"optional_data,omitempty"` // Arbitrary data that can be used from the developers
Creator sdk.AccAddress `json:"creator"` // Creator of the Post
}
Post is a struct of a post
func NewPostComplete ¶ added in v0.2.0
type PostID ¶
type PostID uint64
PostID represents a unique post id
func ParsePostID ¶
ParsePostID returns the PostID represented inside the provided value, or an error if no id could be parsed properly
func (PostID) MarshalJSON ¶
MarshalJSON implements Marshaler
func (*PostID) UnmarshalJSON ¶
UnmarshalJSON implements Unmarshaler
type PostIDs ¶
type PostIDs []PostID
PostIDs represents a slice of PostID objects
func (PostIDs) AppendIfMissing ¶ added in v0.1.1
AppendIfMissing appends the given postID to the ids slice if it does not exist inside it yet. It returns a new slice of PostIDs containing such ID and a boolean indicating whether or not the original slice has been modified.
type PostQueryResponse ¶ added in v0.2.0
type PostQueryResponse struct {
Post
Reactions Reactions `json:"reactions"`
Children PostIDs `json:"children"`
}
PostQueryResponse represents the data of a post that is returned to user upon a query
func NewPostResponse ¶ added in v0.2.0
func NewPostResponse(post Post, reactions Reactions, children PostIDs) PostQueryResponse
func (PostQueryResponse) MarshalJSON ¶ added in v0.2.0
func (response PostQueryResponse) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler as Amino does not respect default json composition
func (*PostQueryResponse) UnmarshalJSON ¶ added in v0.2.0
func (response *PostQueryResponse) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler as Amino does not respect default json composition
type Posts ¶
type Posts []Post
Posts represents a slice of Post objects
type QueryPostsParams ¶ added in v0.2.0
type QueryPostsParams struct {
Page int
Limit int
ParentID *PostID
CreationTime *time.Time
AllowsComments *bool
Subspace string
Creator sdk.AccAddress
}
QueryPostsParams Params for query 'custom/posts/posts'
func DefaultQueryPostsParams ¶ added in v0.2.0
func DefaultQueryPostsParams(page, limit int) QueryPostsParams
func NewQueryPostsParams ¶ added in v0.2.0
func NewQueryPostsParams(page, limit int, parentID *PostID, creationTime time.Time, allowsComments bool, subspace string, owner sdk.AccAddress, ) QueryPostsParams
NewQueryPostsParams creates a new instance of QueryPostsParams
type Reaction ¶ added in v0.2.0
type Reaction struct {
Owner sdk.AccAddress `json:"owner"` // User that has created the reaction
Value string `json:"value"` // Reaction of the reaction
}
Reaction is a struct of a user reaction to a post
func NewReaction ¶ added in v0.2.0
func NewReaction(value string, owner sdk.AccAddress) Reaction
NewReaction returns a new Reaction
func (Reaction) Equals ¶ added in v0.2.0
Equals returns true if reaction and other contain the same data
type Reactions ¶ added in v0.2.0
type Reactions []Reaction
Reactions represents a slice of Reaction objects
func (Reactions) AppendIfMissing ¶ added in v0.2.0
AppendIfMissing returns a new slice of Reaction objects containing the given reaction if it wasn't already present. It also returns the result of the append.
func (Reactions) ContainsReactionFrom ¶ added in v0.2.0
ContainsReactionFrom returns true if the reactions slice contain a reaction from the given user having the given value, false otherwise
func (Reactions) IndexOfByUserAndValue ¶ added in v0.2.0
IndexOfByUserAndValue returns the index of the reaction from the given user with the specified value inside the reactions slice.
func (Reactions) RemoveReaction ¶ added in v0.2.0
RemoveReaction returns a new Reactions slice not containing the reaction of the given user with the given value. If the reaction was removed properly, true is also returned. Otherwise, if no reaction was found, false is returned instead.