Commit 9dbe6796 authored by gitlab's avatar gitlab

auto ci

parent cee84df9
......@@ -15,6 +15,7 @@ import (
pty "github.com/33cn/plugin/plugin/dapp/trade/types"
"github.com/spf13/cobra"
)
// TradeCmd : cmd related to trade,安装trade合约相关命令
func TradeCmd() *cobra.Command {
cmd := &cobra.Command{
......
......@@ -34,10 +34,12 @@ func init() {
ety := types.LoadExecutorType(driverName)
ety.InitFuncList(types.ListMethod(&trade{}))
}
// Init : 注册当前trade合约
func Init(name string, sub []byte) {
drivers.Register(GetName(), newTrade, types.GetDappFork(driverName, "Enable"))
}
// GetName : 获取trade合约名字
func GetName() string {
return newTrade().GetName()
......
......@@ -37,6 +37,7 @@ func (jrpc *Jrpc) CreateRawTradeSellTx(in *ptypes.TradeSellTx, result *interface
*result = hex.EncodeToString(reply.Data)
return nil
}
//CreateRawTradeBuyTx : 创建购买token的未签名交易,向指定卖单发起购买
func (jrpc *Jrpc) CreateRawTradeBuyTx(in *ptypes.TradeBuyTx, result *interface{}) error {
if in == nil {
......@@ -54,6 +55,7 @@ func (jrpc *Jrpc) CreateRawTradeBuyTx(in *ptypes.TradeBuyTx, result *interface{}
*result = hex.EncodeToString(reply.Data)
return nil
}
//CreateRawTradeRevokeTx : 取消指定卖单
func (jrpc *Jrpc) CreateRawTradeRevokeTx(in *ptypes.TradeRevokeTx, result *interface{}) error {
if in == nil {
......@@ -70,6 +72,7 @@ func (jrpc *Jrpc) CreateRawTradeRevokeTx(in *ptypes.TradeRevokeTx, result *inter
*result = hex.EncodeToString(reply.Data)
return nil
}
//CreateRawTradeBuyLimitTx : 挂买单购买token
func (jrpc *Jrpc) CreateRawTradeBuyLimitTx(in *ptypes.TradeBuyLimitTx, result *interface{}) error {
if in == nil {
......@@ -91,6 +94,7 @@ func (jrpc *Jrpc) CreateRawTradeBuyLimitTx(in *ptypes.TradeBuyLimitTx, result *i
*result = hex.EncodeToString(reply.Data)
return nil
}
//CreateRawTradeSellMarketTx : 向指定买单出售token
func (jrpc *Jrpc) CreateRawTradeSellMarketTx(in *ptypes.TradeSellMarketTx, result *interface{}) error {
if in == nil {
......@@ -108,6 +112,7 @@ func (jrpc *Jrpc) CreateRawTradeSellMarketTx(in *ptypes.TradeSellMarketTx, resul
*result = hex.EncodeToString(reply.Data)
return nil
}
//CreateRawTradeRevokeBuyTx : 取消指定买单
func (jrpc *Jrpc) CreateRawTradeRevokeBuyTx(in *ptypes.TradeRevokeBuyTx, result *interface{}) error {
if in == nil {
......
......@@ -10,6 +10,7 @@ import (
"github.com/33cn/chain33/types"
ptypes "github.com/33cn/plugin/plugin/dapp/trade/types"
)
//CreateRawTradeSellTx :
func (cc *channelClient) CreateRawTradeSellTx(ctx context.Context, in *ptypes.TradeForSell) (*types.UnsignTx, error) {
if in == nil {
......@@ -26,6 +27,7 @@ func (cc *channelClient) CreateRawTradeSellTx(ctx context.Context, in *ptypes.Tr
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 {
......@@ -42,6 +44,7 @@ func (cc *channelClient) CreateRawTradeBuyTx(ctx context.Context, in *ptypes.Tra
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 {
......@@ -58,6 +61,7 @@ func (cc *channelClient) CreateRawTradeRevokeTx(ctx context.Context, in *ptypes.
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 {
......@@ -74,6 +78,7 @@ func (cc *channelClient) CreateRawTradeBuyLimitTx(ctx context.Context, in *ptype
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 {
......@@ -90,6 +95,7 @@ func (cc *channelClient) CreateRawTradeSellMarketTx(ctx context.Context, in *pty
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 {
......
......@@ -13,14 +13,17 @@ import (
type channelClient struct {
rpctypes.ChannelClient
}
//Jrpc : Jrpc struct definition
type Jrpc struct {
cli *channelClient
}
//Grpc : Grpc struct definition
type Grpc struct {
*channelClient
}
//Init : do the init operation
func Init(name string, s rpctypes.RPCServer) {
cli := &channelClient{}
......@@ -28,6 +31,7 @@ func Init(name string, s rpctypes.RPCServer) {
cli.Init(name, s, &Jrpc{cli: cli}, grpc)
ptypes.RegisterTradeServer(s.GRPC(), grpc)
}
//GetLastMemPool : get the last memory pool
func (jrpc *Jrpc) GetLastMemPool(in types.ReqNil, result *interface{}) error {
reply, err := jrpc.cli.GetLastMempool()
......
......@@ -36,6 +36,7 @@ const (
TradeOrderStatusBoughtOut
TradeOrderStatusBuyRevoked
)
//SellOrderStatus : sell order status map
var SellOrderStatus = map[int32]string{
TradeOrderStatusNotStart: "NotStart",
......@@ -47,6 +48,7 @@ var SellOrderStatus = map[int32]string{
TradeOrderStatusBoughtOut: "BoughtOut",
TradeOrderStatusBuyRevoked: "BuyRevoked",
}
//SellOrderStatus2Int : SellOrderStatus info to value in int32
var SellOrderStatus2Int = map[string]int32{
"NotStart": TradeOrderStatusNotStart,
......@@ -58,12 +60,14 @@ var SellOrderStatus2Int = map[string]int32{
"BoughtOut": TradeOrderStatusBoughtOut,
"BuyRevoked": TradeOrderStatusBuyRevoked,
}
//MapSellOrderStatusStr2Int :
var MapSellOrderStatusStr2Int = map[string]int32{
"onsale": TradeOrderStatusOnSale,
"soldout": TradeOrderStatusSoldOut,
"revoked": TradeOrderStatusRevoked,
}
//MapBuyOrderStatusStr2Int :
var MapBuyOrderStatusStr2Int = map[string]int32{
"onbuy": TradeOrderStatusOnBuy,
......
......@@ -8,33 +8,33 @@ import "errors"
var (
//ErrTSellBalanceNotEnough :
ErrTSellBalanceNotEnough = errors.New("ErrTradeSellBalanceNotEnough")
ErrTSellBalanceNotEnough = errors.New("ErrTradeSellBalanceNotEnough")
//ErrTSellOrderNotExist :
ErrTSellOrderNotExist = errors.New("ErrTradeSellOrderNotExist")
ErrTSellOrderNotExist = errors.New("ErrTradeSellOrderNotExist")
//ErrTSellOrderNotStart :
ErrTSellOrderNotStart = errors.New("ErrTradeSellOrderNotStart")
ErrTSellOrderNotStart = errors.New("ErrTradeSellOrderNotStart")
//ErrTSellOrderNotEnough :
ErrTSellOrderNotEnough = errors.New("ErrTradeSellOrderNotEnough")
ErrTSellOrderNotEnough = errors.New("ErrTradeSellOrderNotEnough")
//ErrTSellOrderSoldout :
ErrTSellOrderSoldout = errors.New("ErrTradeSellOrderSoldout")
ErrTSellOrderSoldout = errors.New("ErrTradeSellOrderSoldout")
//ErrTSellOrderRevoked :
ErrTSellOrderRevoked = errors.New("ErrTradeSellOrderRevoked")
ErrTSellOrderRevoked = errors.New("ErrTradeSellOrderRevoked")
//ErrTSellOrderExpired :
ErrTSellOrderExpired = errors.New("ErrTradeSellOrderExpired")
ErrTSellOrderExpired = errors.New("ErrTradeSellOrderExpired")
//ErrTSellOrderRevoke :
ErrTSellOrderRevoke = errors.New("ErrTradeSellOrderRevokeNotAllowed")
ErrTSellOrderRevoke = errors.New("ErrTradeSellOrderRevokeNotAllowed")
//ErrTSellNoSuchOrder :
ErrTSellNoSuchOrder = errors.New("ErrTradeSellNoSuchOrder")
ErrTSellNoSuchOrder = errors.New("ErrTradeSellNoSuchOrder")
//ErrTBuyOrderNotExist :
ErrTBuyOrderNotExist = errors.New("ErrTradeBuyOrderNotExist")
ErrTBuyOrderNotExist = errors.New("ErrTradeBuyOrderNotExist")
//ErrTBuyOrderNotEnough :
ErrTBuyOrderNotEnough = errors.New("ErrTradeBuyOrderNotEnough")
ErrTBuyOrderNotEnough = errors.New("ErrTradeBuyOrderNotEnough")
//ErrTBuyOrderSoldout :
ErrTBuyOrderSoldout = errors.New("ErrTradeBuyOrderSoldout")
ErrTBuyOrderSoldout = errors.New("ErrTradeBuyOrderSoldout")
//ErrTBuyOrderRevoked :
ErrTBuyOrderRevoked = errors.New("ErrTradeBuyOrderRevoked")
ErrTBuyOrderRevoked = errors.New("ErrTradeBuyOrderRevoked")
//ErrTBuyOrderRevoke :
ErrTBuyOrderRevoke = errors.New("ErrTradeBuyOrderRevokeNotAllowed")
ErrTBuyOrderRevoke = errors.New("ErrTradeBuyOrderRevokeNotAllowed")
//ErrTCntLessThanMinBoardlot :
ErrTCntLessThanMinBoardlot = errors.New("ErrTradeCountLessThanMinBoardlot")
)
......@@ -27,6 +27,7 @@ type RPCReplyTradeOrder struct {
IsSellOrder bool `protobuf:"varint,15,opt,name=isSellOrder" json:"isSellOrder"`
AssetExec string `protobuf:"bytes,16,opt,name=assetExec" json:"assetExec"`
}
//MarshalJSON :
func (reply *ReplyTradeOrder) MarshalJSON() ([]byte, error) {
r := (*RPCReplyTradeOrder)(reply)
......
......@@ -69,6 +69,7 @@ func newType() *tradeType {
func (t *tradeType) GetPayload() types.Message {
return &Trade{}
}
//ActionName :
func (t *tradeType) ActionName(tx *types.Transaction) string {
var action Trade
......@@ -166,6 +167,7 @@ func (t *tradeType) CreateTx(action string, message json.RawMessage) (*types.Tra
return tx, nil
}
//CreateRawTradeSellTx : 创建卖单交易
func CreateRawTradeSellTx(parm *TradeSellTx) (*types.Transaction, error) {
if parm == nil {
......@@ -188,6 +190,7 @@ func CreateRawTradeSellTx(parm *TradeSellTx) (*types.Transaction, error) {
}
return types.CreateFormatTx(types.ExecName(TradeX), types.Encode(sell))
}
//CreateRawTradeBuyTx :创建想指定卖单发起的买单交易
func CreateRawTradeBuyTx(parm *TradeBuyTx) (*types.Transaction, error) {
if parm == nil {
......@@ -200,6 +203,7 @@ func CreateRawTradeBuyTx(parm *TradeBuyTx) (*types.Transaction, error) {
}
return types.CreateFormatTx(types.ExecName(TradeX), types.Encode(buy))
}
//CreateRawTradeRevokeTx :创建取消卖单的交易
func CreateRawTradeRevokeTx(parm *TradeRevokeTx) (*types.Transaction, error) {
if parm == nil {
......@@ -213,6 +217,7 @@ func CreateRawTradeRevokeTx(parm *TradeRevokeTx) (*types.Transaction, error) {
}
return types.CreateFormatTx(types.ExecName(TradeX), types.Encode(buy))
}
//CreateRawTradeBuyLimitTx :创建买单交易
func CreateRawTradeBuyLimitTx(parm *TradeBuyLimitTx) (*types.Transaction, error) {
if parm == nil {
......@@ -232,6 +237,7 @@ func CreateRawTradeBuyLimitTx(parm *TradeBuyLimitTx) (*types.Transaction, error)
}
return types.CreateFormatTx(types.ExecName(TradeX), types.Encode(buyLimit))
}
//CreateRawTradeSellMarketTx : 创建向指定买单出售token的卖单交易
func CreateRawTradeSellMarketTx(parm *TradeSellMarketTx) (*types.Transaction, error) {
if parm == nil {
......@@ -244,6 +250,7 @@ func CreateRawTradeSellMarketTx(parm *TradeSellMarketTx) (*types.Transaction, er
}
return types.CreateFormatTx(types.ExecName(TradeX), types.Encode(sellMarket))
}
//CreateRawTradeRevokeBuyTx : 取消发起的买单交易
func CreateRawTradeRevokeBuyTx(parm *TradeRevokeBuyTx) (*types.Transaction, error) {
if parm == nil {
......@@ -261,10 +268,12 @@ func CreateRawTradeRevokeBuyTx(parm *TradeRevokeBuyTx) (*types.Transaction, erro
// TradeSellLimitLog :
type TradeSellLimitLog struct {
}
//Name : get name string of TradeSellLimitLog
func (l TradeSellLimitLog) Name() string {
return "LogTradeSell"
}
//Decode : decode the log
func (l TradeSellLimitLog) Decode(msg []byte) (interface{}, error) {
var logTmp ReceiptTradeSellLimit
......@@ -274,13 +283,16 @@ func (l TradeSellLimitLog) Decode(msg []byte) (interface{}, error) {
}
return logTmp, err
}
//TradeSellMarketLog :
type TradeSellMarketLog struct {
}
//Name :
func (l TradeSellMarketLog) Name() string {
return "LogTradeSellMarket"
}
//Decode :
func (l TradeSellMarketLog) Decode(msg []byte) (interface{}, error) {
var logTmp ReceiptSellMarket
......@@ -290,13 +302,16 @@ func (l TradeSellMarketLog) Decode(msg []byte) (interface{}, error) {
}
return logTmp, err
}
//TradeBuyMarketLog :
type TradeBuyMarketLog struct {
}
//Name :
func (l TradeBuyMarketLog) Name() string {
return "LogTradeBuyMarket"
}
//Decode :
func (l TradeBuyMarketLog) Decode(msg []byte) (interface{}, error) {
var logTmp ReceiptTradeBuyMarket
......@@ -306,13 +321,16 @@ func (l TradeBuyMarketLog) Decode(msg []byte) (interface{}, error) {
}
return logTmp, err
}
//TradeBuyLimitLog :
type TradeBuyLimitLog struct {
}
//Name :
func (l TradeBuyLimitLog) Name() string {
return "LogTradeBuyLimit"
}
//Decode :
func (l TradeBuyLimitLog) Decode(msg []byte) (interface{}, error) {
var logTmp ReceiptTradeBuyLimit
......@@ -322,13 +340,16 @@ func (l TradeBuyLimitLog) Decode(msg []byte) (interface{}, error) {
}
return logTmp, err
}
//TradeBuyRevokeLog :
type TradeBuyRevokeLog struct {
}
//Name :
func (l TradeBuyRevokeLog) Name() string {
return "LogTradeBuyRevoke"
}
//Decode :
func (l TradeBuyRevokeLog) Decode(msg []byte) (interface{}, error) {
var logTmp ReceiptTradeBuyRevoke
......@@ -338,13 +359,16 @@ func (l TradeBuyRevokeLog) Decode(msg []byte) (interface{}, error) {
}
return logTmp, err
}
//TradeSellRevokeLog :
type TradeSellRevokeLog struct {
}
//Name :
func (l TradeSellRevokeLog) Name() string {
return "LogTradeSellRevoke"
}
//Decode :
func (l TradeSellRevokeLog) Decode(msg []byte) (interface{}, error) {
var logTmp ReceiptTradeSellRevoke
......
......@@ -3,6 +3,7 @@
// license that can be found in the LICENSE file.
package types
//TradeSellTx : info for sell order
type TradeSellTx struct {
TokenSymbol string `json:"tokenSymbol"`
......@@ -13,17 +14,20 @@ type TradeSellTx struct {
Fee int64 `json:"fee"`
AssetExec string `json:"assetExec"`
}
//TradeBuyTx :info for buy order to speficied order
type TradeBuyTx struct {
SellID string `json:"sellID"`
BoardlotCnt int64 `json:"boardlotCnt"`
Fee int64 `json:"fee"`
}
//TradeRevokeTx :用于取消卖单的信息
type TradeRevokeTx struct {
SellID string `json:"sellID,"`
Fee int64 `json:"fee"`
}
//TradeBuyLimitTx :用于挂买单的信息
type TradeBuyLimitTx struct {
TokenSymbol string `json:"tokenSymbol"`
......@@ -34,12 +38,14 @@ type TradeBuyLimitTx struct {
Fee int64 `json:"fee"`
AssetExec string `json:"assetExec"`
}
//TradeSellMarketTx :用于向指定买单出售token的信息
type TradeSellMarketTx struct {
BuyID string `json:"buyID"`
BoardlotCnt int64 `json:"boardlotCnt"`
Fee int64 `json:"fee"`
}
//TradeRevokeBuyTx :取消指定买单
type TradeRevokeBuyTx struct {
BuyID string `json:"buyID,"`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment