-
Notifications
You must be signed in to change notification settings - Fork 2
/
cc_faucet.go
216 lines (178 loc) · 5.73 KB
/
cc_faucet.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// 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"
)
// FaucetAddress type
type FaucetAddress struct {
Result struct {
Result string `json:"result"`
FaucetCCaddress string `json:"FaucetCCaddress"`
Faucetmarker string `json:"Faucetmarker"`
GatewaysPubkey string `json:"GatewaysPubkey"`
FaucetCCassets string `json:"FaucetCCassets"`
MyCCaddress string `json:"myCCaddress"`
Myaddress string `json:"myaddress"`
} `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// FaucetAddress method returns the Antara address information for the specified pubkey.
// If no pubkey is provided, the method returns information for the pubkey used to launch the daemon
func (appName AppType) FaucetAddress(params APIParams) (FaucetAddress, error) {
var paramsJSON string
if params[0] == "" || params[0] == nil {
paramsJSON = `[]`
//fmt.Println(paramsJSON)
} else {
paramsBytes, _ := json.Marshal(params)
paramsJSON = string(paramsBytes)
//fmt.Println(paramsJSON)
}
query := APIQuery{
Method: `faucetaddress`,
Params: paramsJSON,
}
//fmt.Println(query)
var faucetaddress FaucetAddress
faucetaddressJSON := appName.APICall(&query)
if faucetaddressJSON == "EMPTY RPC INFO" {
return faucetaddress, errors.New("EMPTY RPC INFO")
}
//fmt.Println(faucetaddressJSON)
var result APIResult
json.Unmarshal([]byte(faucetaddressJSON), &result)
if result.Error != nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(faucetaddressJSON), &faucetaddress)
return faucetaddress, errors.New(string(answerError))
}
json.Unmarshal([]byte(faucetaddressJSON), &faucetaddress)
return faucetaddress, nil
}
// FaucetFund type
// This should have been a `int` value or `float64` value.
// But since the API only accepts string, for now this is input as string.
type FaucetFund struct {
Result struct {
Result string `json:"result"`
Hex string `json:"hex"`
} `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// FaucetFund method funds the on-chain faucet.
// The method returns a hex value which must then be broadcast using the sendrawtransaction method
func (appName AppType) FaucetFund(params APIParams) (FaucetFund, error) {
paramsJSON, _ := json.Marshal(params)
//fmt.Println(string(paramsJSON))
query := APIQuery{
Method: `faucetfund`,
Params: string(paramsJSON),
}
//fmt.Println(query)
var faucetfund FaucetFund
faucetfundJSON := appName.APICall(&query)
if faucetfundJSON == "EMPTY RPC INFO" {
return faucetfund, errors.New("EMPTY RPC INFO")
}
//fmt.Println(faucetfundJSON)
var result APIResult
json.Unmarshal([]byte(faucetfundJSON), &result)
if result.Error != nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(faucetfundJSON), &faucetfund)
return faucetfund, errors.New(string(answerError))
}
json.Unmarshal([]byte(faucetfundJSON), &faucetfund)
return faucetfund, nil
}
// FaucetGet type
type FaucetGet struct {
Result struct {
Result string `json:"result"`
Hex string `json:"hex"`
} `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// FaucetGet method requests the faucet module to send coins.
// The method returns a hex value which must then be broadcast using the sendrawtransaction method.
// The faucetget command yields 0.1 coins and requires about 30 seconds of CPU time to execute
func (appName AppType) FaucetGet() (FaucetGet, error) {
query := APIQuery{
Method: `faucetget`,
Params: `[]`,
}
//fmt.Println(query)
var faucetget FaucetGet
faucetgetJSON := appName.APICall(&query)
if faucetgetJSON == "EMPTY RPC INFO" {
return faucetget, errors.New("EMPTY RPC INFO")
}
//fmt.Println(faucetgetJSON)
var result APIResult
json.Unmarshal([]byte(faucetgetJSON), &result)
if result.Error != nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(faucetgetJSON), &faucetget)
return faucetget, errors.New(string(answerError))
}
json.Unmarshal([]byte(faucetgetJSON), &faucetget)
return faucetget, nil
}
// FaucetInfo type
// This should have been a `int` value or `float64` value.
// But since the API only accepts string, for now this is input as string.
type FaucetInfo struct {
Result struct {
Result string `json:"result"`
Name string `json:"name"`
Funding string `json:"funding"`
} `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// FaucetInfo method displays the balance of funds in the chain's faucet.
func (appName AppType) FaucetInfo() (FaucetInfo, error) {
query := APIQuery{
Method: `faucetinfo`,
Params: `[]`,
}
//fmt.Println(query)
var faucetinfo FaucetInfo
faucetinfoJSON := appName.APICall(&query)
if faucetinfoJSON == "EMPTY RPC INFO" {
return faucetinfo, errors.New("EMPTY RPC INFO")
}
//fmt.Println(faucetinfoJSON)
var result APIResult
json.Unmarshal([]byte(faucetinfoJSON), &result)
if result.Error != nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(faucetinfoJSON), &faucetinfo)
return faucetinfo, errors.New(string(answerError))
}
json.Unmarshal([]byte(faucetinfoJSON), &faucetinfo)
return faucetinfo, nil
}