-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcclib.go
174 lines (145 loc) · 4.84 KB
/
cclib.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
// 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 (
"encoding/json"
"errors"
"fmt"
)
// CCLibInfo type
type CCLibInfo struct {
Result struct {
Result string `json:"result"`
CClib string `json:"CClib"`
Methods []struct {
Evalcode int `json:"evalcode"`
Funcid string `json:"funcid"`
Name string `json:"name"`
Method string `json:"method"`
Help string `json:"help"`
ParamsRequired int `json:"params_required"`
ParamsMax int `json:"params_max"`
} `json:"methods"`
} `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// CCLibInfo method displays all the methods of all the modules that are available in the current library.
// The library is loaded at runtime using the -ac_cclib parameter.
func (appName AppType) CCLibInfo() (CCLibInfo, error) {
query := APIQuery{
Method: `cclibinfo`,
Params: `[]`,
}
//fmt.Println(query)
var cclibinfo CCLibInfo
cclibinfoJSON := appName.APICall(&query)
if cclibinfoJSON == "EMPTY RPC INFO" {
return cclibinfo, errors.New("EMPTY RPC INFO")
}
//fmt.Println(cclibinfoJSON)
var result APIResult
json.Unmarshal([]byte(cclibinfoJSON), &result)
if result.Error != nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(cclibinfoJSON), &cclibinfo)
return cclibinfo, errors.New(string(answerError))
}
json.Unmarshal([]byte(cclibinfoJSON), &cclibinfo)
return cclibinfo, nil
}
// CCLibAddress type
type CCLibAddress struct {
Result struct {
Result string `json:"result"`
CClibCCAddress string `json:"CClibCCAddress"`
CCbalance float64 `json:"CCbalance"`
CClibNormalAddress string `json:"CClibNormalAddress"`
CClibCCTokensAddress string `json:"CClibCCTokensAddress"`
MyAddress string `json:"myAddress"`
MyCCAddressCClib string `json:"myCCAddress(CClib)"`
MyCCaddress string `json:"myCCaddress"`
MyCCbalance float64 `json:"myCCbalance"`
Myaddress string `json:"myaddress"`
Mybalance float64 `json:"mybalance"`
} `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// CCLibAddress method returns information about the addresses related to the specified pubkey,
// and according to the Antara Module associated with the specified evalcode. If no pubkey is provided,
// the pubkey used to the launch the daemon is the default.
func (appName AppType) CCLibAddress(params APIParams) (CCLibAddress, error) {
paramsJSON, _ := json.Marshal(params)
fmt.Println(string(paramsJSON))
query := APIQuery{
Method: `cclibaddress`,
Params: string(paramsJSON),
}
//fmt.Println(query)
var cclibaddr CCLibAddress
cclibaddrJSON := appName.APICall(&query)
if cclibaddrJSON == "EMPTY RPC INFO" {
return cclibaddr, errors.New("EMPTY RPC INFO")
}
//fmt.Println(cclibaddrJSON)
var result APIResult
json.Unmarshal([]byte(cclibaddrJSON), &result)
if result.Error != nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(cclibaddrJSON), &cclibaddr)
return cclibaddr, errors.New(string(answerError))
}
json.Unmarshal([]byte(cclibaddrJSON), &cclibaddr)
return cclibaddr, nil
}
// cclib method has these command line options:
// $ komodo-cli -ac_name=ROGUE help cclib
// cclib method [evalcode] [JSON params]
//
// Example command
// komodo-cli -ac_name=ROGUE cclib newgame 17 "[1]"
//
// Explantion
// Command line Utility: komodo-cli
// Assetchain name parameter: -ac_name=ROGUE
// Command Method: cclib
// Command Sub-Method: newgame
// evalcode used by the Crypto-Condition: 17
// JSON Parameters passed for this crypto-conditions as string value: "[1]"
/*func (appName AppType) CCLib(params APIParams) (interface{}, error) {
paramsJSON, _ := json.Marshal(params)
fmt.Println(string(paramsJSON))
query := APIQuery {
Method: `cclib`,
Params: string(paramsJSON),
}
//fmt.Println(query)
//var cclb CCLib
cclbJson := appName.APICall(&query)
//fmt.Println(cclbJson)
var result APIResult
json.Unmarshal([]byte(cclbJson), &result)
if result.Error != nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(cclbJson), &cclb)
return cclb, errors.New(string(answerError))
}
json.Unmarshal([]byte(cclbJson), &cclb)
return cclb, nil
}*/