-
Notifications
You must be signed in to change notification settings - Fork 1
/
type.go
135 lines (116 loc) · 3.28 KB
/
type.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
132
133
134
135
// 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 (
"encoding/hex"
"encoding/json"
rpctypes "github.com/assetcloud/chain/rpc/types"
"github.com/assetcloud/chain/types"
bw "github.com/assetcloud/plugin/plugin/dapp/blackwhite/types"
)
// Jrpc json rpc struct
type Jrpc struct {
cli *channelClient
}
// Grpc grpc struct
type Grpc struct {
*channelClient
}
type channelClient struct {
rpctypes.ChannelClient
}
// Init init grpc param
func Init(name string, s rpctypes.RPCServer) {
cli := &channelClient{}
grpc := &Grpc{channelClient: cli}
cli.Init(name, s, &Jrpc{cli: cli}, grpc)
bw.RegisterBlackwhiteServer(s.GRPC(), grpc)
}
// BlackwhiteCreateTxRPC ...
type BlackwhiteCreateTxRPC struct{}
// Input for convert struct
func (t *BlackwhiteCreateTxRPC) Input(message json.RawMessage) ([]byte, error) {
var req bw.BlackwhiteCreateTxReq
err := json.Unmarshal(message, &req)
if err != nil {
return nil, err
}
return types.Encode(&req), nil
}
// Output for convert struct
func (t *BlackwhiteCreateTxRPC) Output(reply interface{}) (interface{}, error) {
if replyData, ok := reply.(*types.Message); ok {
if tx, ok := (*replyData).(*types.Transaction); ok {
data := types.Encode(tx)
return hex.EncodeToString(data), nil
}
}
return nil, types.ErrTypeAsset
}
// BlackwhitePlayTxRPC ...
type BlackwhitePlayTxRPC struct {
}
// Input for convert struct
func (t *BlackwhitePlayTxRPC) Input(message json.RawMessage) ([]byte, error) {
var req bw.BlackwhitePlayTxReq
err := json.Unmarshal(message, &req)
if err != nil {
return nil, err
}
return types.Encode(&req), nil
}
// Output for convert struct
func (t *BlackwhitePlayTxRPC) Output(reply interface{}) (interface{}, error) {
if replyData, ok := reply.(*types.Message); ok {
if tx, ok := (*replyData).(*types.Transaction); ok {
data := types.Encode(tx)
return hex.EncodeToString(data), nil
}
}
return nil, types.ErrTypeAsset
}
// BlackwhiteShowTxRPC ...
type BlackwhiteShowTxRPC struct {
}
// Input for convert struct
func (t *BlackwhiteShowTxRPC) Input(message json.RawMessage) ([]byte, error) {
var req bw.BlackwhiteShowTxReq
err := json.Unmarshal(message, &req)
if err != nil {
return nil, err
}
return types.Encode(&req), nil
}
// Output for convert struct
func (t *BlackwhiteShowTxRPC) Output(reply interface{}) (interface{}, error) {
if replyData, ok := reply.(*types.Message); ok {
if tx, ok := (*replyData).(*types.Transaction); ok {
data := types.Encode(tx)
return hex.EncodeToString(data), nil
}
}
return nil, types.ErrTypeAsset
}
// BlackwhiteTimeoutDoneTxRPC ...
type BlackwhiteTimeoutDoneTxRPC struct {
}
// Input for convert struct
func (t *BlackwhiteTimeoutDoneTxRPC) Input(message json.RawMessage) ([]byte, error) {
var req bw.BlackwhiteTimeoutDoneTxReq
err := json.Unmarshal(message, &req)
if err != nil {
return nil, err
}
return types.Encode(&req), nil
}
// Output for convert struct
func (t *BlackwhiteTimeoutDoneTxRPC) Output(reply interface{}) (interface{}, error) {
if replyData, ok := reply.(*types.Message); ok {
if tx, ok := (*replyData).(*types.Transaction); ok {
data := types.Encode(tx)
return hex.EncodeToString(data), nil
}
}
return nil, types.ErrTypeAsset
}