-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil.go
184 lines (157 loc) · 5.84 KB
/
util.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// Copyright © 2018-2020 Satinderjit Singh.
//
// See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at
// the top-level directory of this distribution for the individual copyright
// holder information and the developer policies on copyright and licensing.
//
// Unless otherwise agreed in a custom licensing agreement, no part of the
// kmdgo software, including this file may be copied, modified, propagated.
// or distributed except according to the terms contained in the LICENSE file
//
// Removal or modification of this copyright notice is prohibited.
package kmdgo
import (
//"fmt"
"encoding/json"
"errors"
//"strconv"
)
// ValidateAddress struct type to store validate address API output
type ValidateAddress struct {
Result struct {
Isvalid bool `json:"isvalid"`
Address string `json:"address"`
ScriptPubKey string `json:"scriptPubKey"`
Segid int `json:"segid"`
Ismine bool `json:"ismine"`
Iswatchonly bool `json:"iswatchonly"`
Isscript bool `json:"isscript"`
Pubkey string `json:"pubkey"`
Iscompressed bool `json:"iscompressed"`
Account string `json:"account"`
} `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// ValidateAddress method allows to check the information about a single wallet address's status
func (appName AppType) ValidateAddress(taddr string) (ValidateAddress, error) {
query := APIQuery{
Method: `validateaddress`,
Params: `["` + taddr + `"]`,
}
//fmt.Println(query)
var validateaddress ValidateAddress
validateaddressJSON := appName.APICall(&query)
if validateaddressJSON == "EMPTY RPC INFO" {
return validateaddress, errors.New("EMPTY RPC INFO")
}
var result APIResult
json.Unmarshal([]byte(validateaddressJSON), &result)
if result.Error != nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(validateaddressJSON), &validateaddress)
return validateaddress, errors.New(string(answerError))
}
json.Unmarshal([]byte(validateaddressJSON), &validateaddress)
return validateaddress, nil
}
// VerifyMessage type
type VerifyMessage struct {
Result bool `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// VerifyMessage - Verify a signed message
//
// verifymessage "address or identity" "signature" "message" "checklatest"
//
// Arguments:
// 1. "t-addr or identity" (string, required) The transparent address or identity that signed the message.
// 2. "signature" (string, required) The signature provided by the signer in base 64 encoding (see signmessage).
// 3. "message" (string, required) The message that was signed.
// 3. "checklatest" (bool, optional) If true, checks signature validity based on latest identity. defaults to false,
// which determines validity of signing height stored in signature.
//
// Result:
// true|false (boolean) If the signature is verified or not.
func (appName AppType) VerifyMessage(params APIParams) (VerifyMessage, error) {
paramsJSON, _ := json.Marshal(params)
//fmt.Println(string(paramsJSON))
query := APIQuery{
Method: `verifymessage`,
Params: string(paramsJSON),
}
//fmt.Println(query)
var verifymessage VerifyMessage
verifymessageJSON := appName.APICall(&query)
if verifymessageJSON == "EMPTY RPC INFO" {
return verifymessage, errors.New("EMPTY RPC INFO")
}
var result APIResult
json.Unmarshal([]byte(verifymessageJSON), &result)
if result.Error != nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(verifymessageJSON), &verifymessage)
return verifymessage, errors.New(string(answerError))
}
json.Unmarshal([]byte(verifymessageJSON), &verifymessage)
return verifymessage, nil
}
// ZValidateAddress type
type ZValidateAddress struct {
Result struct {
Isvalid bool `json:"isvalid"`
Address string `json:"address"`
Type string `json:"type"`
Diversifier string `json:"diversifier"`
Diversifiedtransmissionkey string `json:"diversifiedtransmissionkey"`
Ismine bool `json:"ismine"`
} `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// ZValidateAddress returns information about the given z address.
//
// z_validateaddress "zaddr"
//
// Arguments:
// 1. "zaddr" (string, required) The z address to validate
//
// Result:
// {
// "isvalid" : true|false, (boolean) If the address is valid or not. If not, this is the only property returned.
// "address" : "zaddr", (string) The z address validated
// "type" : "xxxx", (string) "sprout" or "sapling"
// "ismine" : true|false, (boolean) If the address is yours or not
// "payingkey" : "hex", (string) [sprout] The hex value of the paying key, a_pk
// "transmissionkey" : "hex", (string) [sprout] The hex value of the transmission key, pk_enc
// "diversifier" : "hex", (string) [sapling] The hex value of the diversifier, d
// "diversifiedtransmissionkey" : "hex", (string) [sapling] The hex value of pk_d
// }
func (appName AppType) ZValidateAddress(zaddr string) (ZValidateAddress, error) {
query := APIQuery{
Method: `z_validateaddress`,
Params: `["` + zaddr + `"]`,
}
//fmt.Println(query)
var zvalidateaddress ZValidateAddress
zvalidateaddressJSON := appName.APICall(&query)
if zvalidateaddressJSON == "EMPTY RPC INFO" {
return zvalidateaddress, errors.New("EMPTY RPC INFO")
}
var result APIResult
json.Unmarshal([]byte(zvalidateaddressJSON), &result)
if result.Error != nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(zvalidateaddressJSON), &zvalidateaddress)
return zvalidateaddress, errors.New(string(answerError))
}
json.Unmarshal([]byte(zvalidateaddressJSON), &zvalidateaddress)
return zvalidateaddress, nil
}