-
Notifications
You must be signed in to change notification settings - Fork 385
/
types.go
63 lines (51 loc) · 1.71 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package types
import (
"fmt"
"strings"
codec "github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
// ModuleName is the name of the module
ModuleName = "greeter"
// StoreKey is used to register the module's store
StoreKey = ModuleName
)
var (
// ModuleCdc contains the types for the module that require encoding in amino
ModuleCdc = codec.New()
)
// struct containing the data of the Greeting. json and yaml tags are used to specify field names
// when marshalled to json
type Greeting struct {
Sender sdk.AccAddress `json:"sender" yaml:"sender"` // address of the account "sending" the greeting
Recipient sdk.AccAddress `json:"receiver" yaml:"receiver"` // address of the account "receiving" the greeting
Body string `json:"body" yaml:"body"` // string body of the greeting
}
// GreetingsList stores all the greeting for a given address
type GreetingsList []Greeting
// NewGreeting Returns a new Greeting
func NewGreeting(sender sdk.AccAddress, body string, receiver sdk.AccAddress) Greeting {
return Greeting{
Recipient: receiver,
Sender: sender,
Body: body,
}
}
// implement fmt.Stringer
func (g Greeting) String() string {
return strings.TrimSpace(
fmt.Sprintf(`Sender: %s Recipient: %s Body: %s`, g.Sender.String(), g.Recipient.String(),
g.Body),
)
}
// QueryResGreetings defines the response to our Querier, containing greetings for a given address
type QueryResGreetings map[string][]Greeting
func (q QueryResGreetings) String() string {
b := ModuleCdc.MustMarshalJSON(q)
return string(b)
}
// NewQueryResGreetings constructs a new instance
func NewQueryResGreetings() QueryResGreetings {
return make(map[string][]Greeting)
}