/
attendees.go
84 lines (68 loc) · 2.2 KB
/
attendees.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package querier
import (
"fmt"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/eco/longy/x/longy/internal/keeper"
"github.com/eco/longy/x/longy/internal/types"
"strconv"
)
//nolint:gocritic,unparam
func queryAttendee(ctx sdk.Context, path []string, keeper keeper.Keeper) (res []byte, err sdk.Error) {
id := path[0]
attendee, ok := keeper.GetAttendeeWithID(ctx, id)
if !ok {
return nil, types.ErrAttendeeNotFound("non-existent attendee id")
}
res, e := codec.MarshalJSONIndent(keeper.Cdc, attendee)
if e != nil {
panic("could not marshal result to JSON")
}
return res, nil
}
//nolint:gocritic,unparam
func queryAttendees(ctx sdk.Context, keeper keeper.Keeper) (res []byte, err sdk.Error) {
attendees := keeper.GetAllAttendees(ctx)
res, e := codec.MarshalJSONIndent(keeper.Cdc, attendees)
if e != nil {
panic("could not marshal result to JSON")
}
return res, nil
}
//nolint:gocritic,unparam
func queryAttendeeKeyed(ctx sdk.Context, path []string, keeper keeper.Keeper) (res []byte, err sdk.Error) {
id := path[0]
attendee, ok := keeper.GetAttendeeWithID(ctx, id)
if !ok {
return nil, types.ErrAttendeeNotFound("non-existent attendee id")
}
keyed := attendee.IsKeyed()
return []byte(strconv.FormatBool(keyed)), nil
}
//nolint: gocritic,unparam
func queryAttendeeClaimed(ctx sdk.Context, path []string, keeper keeper.Keeper) (res []byte, err sdk.Error) {
id := path[0]
attendee, ok := keeper.GetAttendeeWithID(ctx, id)
if !ok {
return nil, types.ErrAttendeeNotFound("non-existent attendee id")
}
claimed := attendee.IsClaimed()
return []byte(strconv.FormatBool(claimed)), nil
}
//nolint:gocritic,unparam
func queryAttendeesByAddr(ctx sdk.Context, path []string,
keeper keeper.Keeper) (res []byte, err sdk.Error) {
addr, e := sdk.AccAddressFromBech32(path[0])
if e != nil {
return nil, sdk.ErrInvalidAddress(fmt.Sprintf("cannot turn param into cosmos AccAddress: %s", path[0]))
}
attendee, ok := keeper.GetAttendee(ctx, addr)
if !ok {
return nil, types.ErrAttendeeNotFound("could not find attendee with that AccAddress")
}
res, e = codec.MarshalJSONIndent(keeper.Cdc, attendee)
if e != nil {
panic("could not marshal result to JSON")
}
return
}