-
Notifications
You must be signed in to change notification settings - Fork 0
/
jrpc.go
131 lines (115 loc) · 3.39 KB
/
jrpc.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
121
122
123
124
125
126
127
128
129
130
131
// 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"
"encoding/hex"
"github.com/33cn/chain33/types"
ptypes "github.com/GM-Publicchain/gm/plugin/dapp/trade/types"
)
//CreateRawTradeSellTx : 创建出售token的未签名交易
func (jrpc *Jrpc) CreateRawTradeSellTx(in *ptypes.TradeSellTx, result *interface{}) error {
if in == nil {
return types.ErrInvalidParam
}
param := &ptypes.TradeForSell{
TokenSymbol: in.TokenSymbol,
AmountPerBoardlot: in.AmountPerBoardlot,
MinBoardlot: in.MinBoardlot,
PricePerBoardlot: in.PricePerBoardlot,
TotalBoardlot: in.TotalBoardlot,
Starttime: 0,
Stoptime: 0,
Crowdfund: false,
AssetExec: in.AssetExec,
}
reply, err := jrpc.cli.CreateRawTradeSellTx(context.Background(), param)
if err != nil {
return err
}
*result = hex.EncodeToString(reply.Data)
return nil
}
//CreateRawTradeBuyTx : 创建购买token的未签名交易,向指定卖单发起购买
func (jrpc *Jrpc) CreateRawTradeBuyTx(in *ptypes.TradeBuyTx, result *interface{}) error {
if in == nil {
return types.ErrInvalidParam
}
param := &ptypes.TradeForBuy{
SellID: in.SellID,
BoardlotCnt: in.BoardlotCnt,
}
reply, err := jrpc.cli.CreateRawTradeBuyTx(context.Background(), param)
if err != nil {
return err
}
*result = hex.EncodeToString(reply.Data)
return nil
}
//CreateRawTradeRevokeTx : 取消指定卖单
func (jrpc *Jrpc) CreateRawTradeRevokeTx(in *ptypes.TradeRevokeTx, result *interface{}) error {
if in == nil {
return types.ErrInvalidParam
}
param := &ptypes.TradeForRevokeSell{
SellID: in.SellID,
}
reply, err := jrpc.cli.CreateRawTradeRevokeTx(context.Background(), param)
if err != nil {
return err
}
*result = hex.EncodeToString(reply.Data)
return nil
}
//CreateRawTradeBuyLimitTx : 挂买单购买token
func (jrpc *Jrpc) CreateRawTradeBuyLimitTx(in *ptypes.TradeBuyLimitTx, result *interface{}) error {
if in == nil {
return types.ErrInvalidParam
}
param := &ptypes.TradeForBuyLimit{
TokenSymbol: in.TokenSymbol,
AmountPerBoardlot: in.AmountPerBoardlot,
MinBoardlot: in.MinBoardlot,
PricePerBoardlot: in.PricePerBoardlot,
TotalBoardlot: in.TotalBoardlot,
AssetExec: in.AssetExec,
}
reply, err := jrpc.cli.CreateRawTradeBuyLimitTx(context.Background(), param)
if err != nil {
return err
}
*result = hex.EncodeToString(reply.Data)
return nil
}
//CreateRawTradeSellMarketTx : 向指定买单出售token
func (jrpc *Jrpc) CreateRawTradeSellMarketTx(in *ptypes.TradeSellMarketTx, result *interface{}) error {
if in == nil {
return types.ErrInvalidParam
}
param := &ptypes.TradeForSellMarket{
BuyID: in.BuyID,
BoardlotCnt: in.BoardlotCnt,
}
reply, err := jrpc.cli.CreateRawTradeSellMarketTx(context.Background(), param)
if err != nil {
return err
}
*result = hex.EncodeToString(reply.Data)
return nil
}
//CreateRawTradeRevokeBuyTx : 取消指定买单
func (jrpc *Jrpc) CreateRawTradeRevokeBuyTx(in *ptypes.TradeRevokeBuyTx, result *interface{}) error {
if in == nil {
return types.ErrInvalidParam
}
param := &ptypes.TradeForRevokeBuy{
BuyID: in.BuyID,
}
reply, err := jrpc.cli.CreateRawTradeRevokeBuyTx(context.Background(), param)
if err != nil {
return err
}
*result = hex.EncodeToString(reply.Data)
return nil
}