-
Notifications
You must be signed in to change notification settings - Fork 0
/
jrpc.go
86 lines (76 loc) · 2.02 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
// 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"
bw "github.com/GM-Publicchain/gm/plugin/dapp/blackwhite/types"
)
// BlackwhiteCreateTx 创建游戏RPC接口
func (c *Jrpc) BlackwhiteCreateTx(parm *bw.BlackwhiteCreateTxReq, result *interface{}) error {
if parm == nil {
return types.ErrInvalidParam
}
head := &bw.BlackwhiteCreate{
PlayAmount: parm.PlayAmount,
PlayerCount: parm.PlayerCount,
Timeout: parm.Timeout,
GameName: parm.GameName,
}
reply, err := c.cli.Create(context.Background(), head)
if err != nil {
return err
}
*result = hex.EncodeToString(reply.Data)
return nil
}
// BlackwhiteShowTx 出示游戏密钥的RPC接口
func (c *Jrpc) BlackwhiteShowTx(parm *BlackwhiteShowTx, result *interface{}) error {
if parm == nil {
return types.ErrInvalidParam
}
head := &bw.BlackwhiteShow{
GameID: parm.GameID,
Secret: parm.Secret,
}
reply, err := c.cli.Show(context.Background(), head)
if err != nil {
return err
}
*result = hex.EncodeToString(reply.Data)
return nil
}
// BlackwhitePlayTx 参与游戏的RPC接口
func (c *Jrpc) BlackwhitePlayTx(parm *BlackwhitePlayTx, result *interface{}) error {
if parm == nil {
return types.ErrInvalidParam
}
head := &bw.BlackwhitePlay{
GameID: parm.GameID,
Amount: parm.Amount,
HashValues: parm.HashValues,
}
reply, err := c.cli.Play(context.Background(), head)
if err != nil {
return err
}
*result = hex.EncodeToString(reply.Data)
return nil
}
// BlackwhiteTimeoutDoneTx 游戏超时RPC接口
func (c *Jrpc) BlackwhiteTimeoutDoneTx(parm *BlackwhiteTimeoutDoneTx, result *interface{}) error {
if parm == nil {
return types.ErrInvalidParam
}
head := &bw.BlackwhiteTimeoutDone{
GameID: parm.GameID,
}
reply, err := c.cli.TimeoutDone(context.Background(), head)
if err != nil {
return err
}
*result = hex.EncodeToString(reply.Data)
return nil
}