/
rawclient.go
60 lines (50 loc) · 1.52 KB
/
rawclient.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
package query
import (
"fmt"
sdkclient "github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
types "github.com/ovrclk/akash/x/audit/types/v1beta2"
)
// RawClient interface
type RawClient interface {
AllProviders() ([]byte, error)
Provider(sdk.AccAddress) ([]byte, error)
ProviderID(types.ProviderID) ([]byte, error)
Auditor(sdk.AccAddress) ([]byte, error)
}
// NewRawClient creates a client instance with provided context and key
func NewRawClient(ctx sdkclient.Context, key string) RawClient {
return &rawclient{ctx: ctx, key: key}
}
type rawclient struct {
ctx sdkclient.Context
key string
}
func (c *rawclient) AllProviders() ([]byte, error) {
buf, _, err := c.ctx.QueryWithData(fmt.Sprintf("custom/%s/attributes/list", c.key), nil)
if err != nil {
return []byte{}, err
}
return buf, err
}
func (c *rawclient) Provider(id sdk.AccAddress) ([]byte, error) {
buf, _, err := c.ctx.QueryWithData(fmt.Sprintf("custom/%s/attributes/owner/%s/list", c.key, id), nil)
if err != nil {
return []byte{}, err
}
return buf, err
}
func (c *rawclient) ProviderID(id types.ProviderID) ([]byte, error) {
buf, _, err := c.ctx.QueryWithData(fmt.Sprintf("custom/%s/attributes/auditor/%s/%s", c.key, id.Auditor, id.Owner), nil)
if err != nil {
return []byte{}, err
}
return buf, err
}
func (c *rawclient) Auditor(id sdk.AccAddress) ([]byte, error) {
buf, _, err := c.ctx.QueryWithData(fmt.Sprintf("custom/%s/attributes/auditor/%s/list", c.key, id), nil)
if err != nil {
return []byte{}, err
}
return buf, err
}