types

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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

View Source
var ModuleCdc = codec.New()

ModuleCdc is the codec

Functions

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

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

type KeyValue struct {
	Key   string
	Value string
}

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) Type

func (msg MsgCreatePost) Type() string

Type should return the action

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) Type

func (msg MsgEditPost) Type() string

Type should return the action

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

type OptionalData map[string]string

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 NewPost

func NewPost(id, parentID PostID, message string, allowsComments bool, subspace string, optionalData map[string]string,
	created time.Time, creator sdk.AccAddress) Post

func NewPostComplete added in v0.2.0

func NewPostComplete(id, parentID PostID, message string, created, lastEdited time.Time, allowsComments bool,
	subspace string, optionalData map[string]string, creator sdk.AccAddress) Post

func (Post) Equals

func (p Post) Equals(other Post) bool

Equals allows to check whether the contents of p are the same of other

func (Post) String

func (p Post) String() string

String implements fmt.Stringer

func (Post) Validate

func (p Post) Validate() error

Validate implements validator

type PostID

type PostID uint64

PostID represents a unique post id

func ParsePostID

func ParsePostID(value string) (PostID, error)

ParsePostID returns the PostID represented inside the provided value, or an error if no id could be parsed properly

func (PostID) Equals

func (id PostID) Equals(other PostID) bool

Equals compares two PostID instances

func (PostID) MarshalJSON

func (id PostID) MarshalJSON() ([]byte, error)

MarshalJSON implements Marshaler

func (PostID) Next

func (id PostID) Next() PostID

Next returns the subsequent id to this one

func (PostID) String

func (id PostID) String() string

String implements fmt.Stringer

func (*PostID) UnmarshalJSON

func (id *PostID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements Unmarshaler

func (PostID) Valid

func (id PostID) Valid() bool

Valid tells if the id can be used safely

type PostIDs

type PostIDs []PostID

PostIDs represents a slice of PostID objects

func (PostIDs) AppendIfMissing added in v0.1.1

func (ids PostIDs) AppendIfMissing(id PostID) (PostIDs, bool)

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.

func (PostIDs) Equals

func (ids PostIDs) Equals(other PostIDs) bool

Equals returns true iff the ids slice and the other one contain the same data in the same order

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

func (Posts) Equals

func (p Posts) Equals(other Posts) bool

Equals returns true iff the p slice contains the same data in the same order of the other slice

func (Posts) String added in v0.2.0

func (p Posts) String() string

String implements stringer interface

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

func (reaction Reaction) Equals(other Reaction) bool

Equals returns true if reaction and other contain the same data

func (Reaction) String added in v0.2.0

func (reaction Reaction) String() string

String implements fmt.Stringer

func (Reaction) Validate added in v0.2.0

func (reaction Reaction) Validate() error

Validate implements validator

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

func (reactions Reactions) AppendIfMissing(other Reaction) (Reactions, bool)

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

func (reactions Reactions) ContainsReactionFrom(user sdk.Address, value string) bool

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

func (reactions Reactions) IndexOfByUserAndValue(owner sdk.Address, value string) int

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

func (reactions Reactions) RemoveReaction(user sdk.Address, value string) (Reactions, bool)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL