forked from sonm-io/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
market.go
53 lines (44 loc) · 1.18 KB
/
market.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
package hub
import (
pb "github.com/sonm-io/core/proto"
"github.com/sonm-io/core/util"
"golang.org/x/net/context"
)
type Market interface {
// OrderExists checks whether an order with the specified ID exists in the
// marketplace.
OrderExists(ID string) (bool, error)
// CreateOrder creates order on marketplace
CreateOrder(ord *pb.Order) (*pb.Order, error)
// CancelOrder removes order from marketplace
CancelOrder(ID string) error
}
type market struct {
ctx context.Context
client pb.MarketClient
}
func (m *market) OrderExists(ID string) (bool, error) {
_, err := m.client.GetOrderByID(m.ctx, &pb.ID{Id: ID})
if err != nil {
return false, err
}
return true, nil
}
func (m *market) CancelOrder(ID string) error {
_, err := m.client.CancelOrder(m.ctx, &pb.Order{Id: ID})
return err
}
func (m *market) CreateOrder(ord *pb.Order) (*pb.Order, error) {
return m.client.CreateOrder(m.ctx, ord)
}
// NewMarket constructs a new SONM marketplace client.
func NewMarket(ctx context.Context, addr string) (Market, error) {
cc, err := util.MakeGrpcClient(ctx, addr, nil)
if err != nil {
return nil, err
}
return &market{
ctx: ctx,
client: pb.NewMarketClient(cc),
}, nil
}