/
rpc.go
135 lines (119 loc) · 4.06 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
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/PhenixChain/devchain/rpc/types"
"github.com/PhenixChain/devchain/types"
pty "github.com/PhenixChain/devchain/plugin/dapp/privacy/types"
"golang.org/x/net/context"
)
// 显示指定地址的公钥对信息,可以作为后续交易参数
func (g *channelClient) ShowPrivacyKey(ctx context.Context, in *types.ReqString) (*pty.ReplyPrivacyPkPair, error) {
data, err := g.ExecWalletFunc(pty.PrivacyX, "ShowPrivacyKey", in)
if err != nil {
return nil, err
}
return data.(*pty.ReplyPrivacyPkPair), nil
}
// 扫描UTXO以及获取扫描UTXO后的状态
func (g *channelClient) RescanUtxos(ctx context.Context, in *pty.ReqRescanUtxos) (*pty.RepRescanUtxos, error) {
data, err := g.ExecWalletFunc(pty.PrivacyX, "RescanUtxos", in)
if err != nil {
return nil, err
}
return data.(*pty.RepRescanUtxos), nil
}
// 使能隐私账户
func (g *channelClient) EnablePrivacy(ctx context.Context, in *pty.ReqEnablePrivacy) (*pty.RepEnablePrivacy, error) {
data, err := g.ExecWalletFunc(pty.PrivacyX, "EnablePrivacy", in)
if err != nil {
return nil, err
}
return data.(*pty.RepEnablePrivacy), nil
}
func (g *channelClient) CreateRawTransaction(ctx context.Context, in *pty.ReqCreatePrivacyTx) (*types.Transaction, error) {
data, err := g.ExecWalletFunc(pty.PrivacyX, "CreateTransaction", in)
if err != nil {
return nil, err
}
return data.(*types.Transaction), nil
}
// ShowPrivacyAccountInfo display privacy account information for json rpc
func (c *Jrpc) ShowPrivacyAccountInfo(in *pty.ReqPPrivacyAccount, result *json.RawMessage) error {
reply, err := c.cli.ExecWalletFunc(pty.PrivacyX, "ShowPrivacyAccountInfo", in)
if err != nil {
return err
}
*result, err = types.PBToJSON(reply)
return err
}
/////////////////privacy///////////////
// ShowPrivacyAccountSpend display spend privacy account for json rpc
func (c *Jrpc) ShowPrivacyAccountSpend(in *pty.ReqPrivBal4AddrToken, result *json.RawMessage) error {
if 0 == len(in.Addr) {
return types.ErrInvalidParam
}
reply, err := c.cli.ExecWalletFunc(pty.PrivacyX, "ShowPrivacyAccountSpend", in)
if err != nil {
log.Info("ShowPrivacyAccountSpend", "return err info", err)
return err
}
*result, err = types.PBToJSON(reply)
return err
}
// ShowPrivacyKey display privacy key for json rpc
func (c *Jrpc) ShowPrivacyKey(in *types.ReqString, result *json.RawMessage) error {
reply, err := c.cli.ShowPrivacyKey(context.Background(), in)
if err != nil {
return err
}
*result, err = types.PBToJSON(reply)
return err
}
// GetPrivacyTxByAddr get all privacy transaction list by param
func (c *Jrpc) GetPrivacyTxByAddr(in *pty.ReqPrivacyTransactionList, result *interface{}) error {
if in.Direction != 0 && in.Direction != 1 {
return types.ErrInvalidParam
}
reply, err := c.cli.ExecWalletFunc(pty.PrivacyX, "PrivacyTransactionList", in)
if err != nil {
return err
}
var txdetails rpctypes.WalletTxDetails
err = rpctypes.ConvertWalletTxDetailToJSON(reply.(*types.WalletTxDetails), &txdetails)
if err != nil {
return err
}
*result = &txdetails
return nil
}
// RescanUtxos rescan utxosl for json rpc
func (c *Jrpc) RescanUtxos(in *pty.ReqRescanUtxos, result *json.RawMessage) error {
reply, err := c.cli.RescanUtxos(context.Background(), in)
if err != nil {
return err
}
*result, err = types.PBToJSON(reply)
return err
}
// EnablePrivacy enable privacy for json rpc
func (c *Jrpc) EnablePrivacy(in *pty.ReqEnablePrivacy, result *json.RawMessage) error {
reply, err := c.cli.EnablePrivacy(context.Background(), in)
if err != nil {
return err
}
*result, err = types.PBToJSON(reply)
return err
}
// CreateRawTransaction create raw trasaction for json rpc
func (c *Jrpc) CreateRawTransaction(in *pty.ReqCreatePrivacyTx, result *interface{}) error {
reply, err := c.cli.CreateRawTransaction(context.Background(), in)
if err != nil {
return err
}
*result = hex.EncodeToString(types.Encode(reply))
return err
}