-
Notifications
You must be signed in to change notification settings - Fork 1
/
rpc.go
120 lines (111 loc) · 3.41 KB
/
rpc.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package rpc
import (
"context"
"github.com/assetcloud/chain/types"
ptypes "github.com/assetcloud/plugin/plugin/dapp/trade/types"
)
//CreateRawTradeSellTx :
func (cc *channelClient) CreateRawTradeSellTx(ctx context.Context, in *ptypes.TradeForSell) (*types.UnsignTx, error) {
if in == nil {
return nil, types.ErrInvalidParam
}
sell := &ptypes.Trade{
Ty: ptypes.TradeSellLimit,
Value: &ptypes.Trade_SellLimit{SellLimit: in},
}
cfg := cc.GetConfig()
tx, err := types.CreateFormatTx(cfg, cfg.ExecName(ptypes.TradeX), types.Encode(sell))
if err != nil {
return nil, err
}
data := types.Encode(tx)
return &types.UnsignTx{Data: data}, nil
}
//CreateRawTradeBuyTx :
func (cc *channelClient) CreateRawTradeBuyTx(ctx context.Context, in *ptypes.TradeForBuy) (*types.UnsignTx, error) {
if in == nil {
return nil, types.ErrInvalidParam
}
buy := &ptypes.Trade{
Ty: ptypes.TradeBuyMarket,
Value: &ptypes.Trade_BuyMarket{BuyMarket: in},
}
cfg := cc.GetConfig()
tx, err := types.CreateFormatTx(cfg, cfg.ExecName(ptypes.TradeX), types.Encode(buy))
if err != nil {
return nil, err
}
data := types.Encode(tx)
return &types.UnsignTx{Data: data}, nil
}
//CreateRawTradeRevokeTx :
func (cc *channelClient) CreateRawTradeRevokeTx(ctx context.Context, in *ptypes.TradeForRevokeSell) (*types.UnsignTx, error) {
if in == nil {
return nil, types.ErrInvalidParam
}
buy := &ptypes.Trade{
Ty: ptypes.TradeRevokeSell,
Value: &ptypes.Trade_RevokeSell{RevokeSell: in},
}
cfg := cc.GetConfig()
tx, err := types.CreateFormatTx(cfg, cfg.ExecName(ptypes.TradeX), types.Encode(buy))
if err != nil {
return nil, err
}
data := types.Encode(tx)
return &types.UnsignTx{Data: data}, nil
}
//CreateRawTradeBuyLimitTx :
func (cc *channelClient) CreateRawTradeBuyLimitTx(ctx context.Context, in *ptypes.TradeForBuyLimit) (*types.UnsignTx, error) {
if in == nil {
return nil, types.ErrInvalidParam
}
buy := &ptypes.Trade{
Ty: ptypes.TradeBuyLimit,
Value: &ptypes.Trade_BuyLimit{BuyLimit: in},
}
cfg := cc.GetConfig()
tx, err := types.CreateFormatTx(cfg, cfg.ExecName(ptypes.TradeX), types.Encode(buy))
if err != nil {
return nil, err
}
data := types.Encode(tx)
return &types.UnsignTx{Data: data}, nil
}
//CreateRawTradeSellMarketTx :
func (cc *channelClient) CreateRawTradeSellMarketTx(ctx context.Context, in *ptypes.TradeForSellMarket) (*types.UnsignTx, error) {
if in == nil {
return nil, types.ErrInvalidParam
}
buy := &ptypes.Trade{
Ty: ptypes.TradeSellMarket,
Value: &ptypes.Trade_SellMarket{SellMarket: in},
}
cfg := cc.GetConfig()
tx, err := types.CreateFormatTx(cfg, cfg.ExecName(ptypes.TradeX), types.Encode(buy))
if err != nil {
return nil, err
}
data := types.Encode(tx)
return &types.UnsignTx{Data: data}, nil
}
//CreateRawTradeRevokeBuyTx :
func (cc *channelClient) CreateRawTradeRevokeBuyTx(ctx context.Context, in *ptypes.TradeForRevokeBuy) (*types.UnsignTx, error) {
if in == nil {
return nil, types.ErrInvalidParam
}
buy := &ptypes.Trade{
Ty: ptypes.TradeRevokeBuy,
Value: &ptypes.Trade_RevokeBuy{RevokeBuy: in},
}
cfg := cc.GetConfig()
tx, err := types.CreateFormatTx(cfg, cfg.ExecName(ptypes.TradeX), types.Encode(buy))
if err != nil {
return nil, err
}
data := types.Encode(tx)
return &types.UnsignTx{Data: data}, nil
}