-
Notifications
You must be signed in to change notification settings - Fork 212
/
rawclient.go
77 lines (65 loc) · 2 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package query
import (
"fmt"
sdkclient "github.com/cosmos/cosmos-sdk/client"
types "github.com/akash-network/akash-api/go/node/market/v1beta3"
)
// RawClient interface
type RawClient interface {
Orders(filters OrderFilters) ([]byte, error)
Order(id types.OrderID) ([]byte, error)
Bids(filters BidFilters) ([]byte, error)
Bid(id types.BidID) ([]byte, error)
Leases(filters LeaseFilters) ([]byte, error)
Lease(id types.LeaseID) ([]byte, error)
}
// NewRawClient creates a raw 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) Orders(ofilters OrderFilters) ([]byte, error) {
buf, _, err := c.ctx.QueryWithData(fmt.Sprintf("custom/%s/%s", c.key, getOrdersPath(ofilters)), nil)
if err != nil {
return []byte{}, err
}
return buf, nil
}
func (c *rawclient) Order(id types.OrderID) ([]byte, error) {
buf, _, err := c.ctx.QueryWithData(fmt.Sprintf("custom/%s/%s", c.key, OrderPath(id)), nil)
if err != nil {
return []byte{}, err
}
return buf, nil
}
func (c *rawclient) Bids(bfilters BidFilters) ([]byte, error) {
buf, _, err := c.ctx.QueryWithData(fmt.Sprintf("custom/%s/%s", c.key, getBidsPath(bfilters)), nil)
if err != nil {
return []byte{}, err
}
return buf, nil
}
func (c *rawclient) Bid(id types.BidID) ([]byte, error) {
buf, _, err := c.ctx.QueryWithData(fmt.Sprintf("custom/%s/%s", c.key, getBidPath(id)), nil)
if err != nil {
return []byte{}, err
}
return buf, nil
}
func (c *rawclient) Leases(lfilters LeaseFilters) ([]byte, error) {
buf, _, err := c.ctx.QueryWithData(fmt.Sprintf("custom/%s/%s", c.key, getLeasesPath(lfilters)), nil)
if err != nil {
return []byte{}, err
}
return buf, nil
}
func (c *rawclient) Lease(id types.LeaseID) ([]byte, error) {
buf, _, err := c.ctx.QueryWithData(fmt.Sprintf("custom/%s/%s", c.key, LeasePath(id)), nil)
if err != nil {
return []byte{}, err
}
return buf, nil
}