@neuraiproject/neurai-rpc 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +282 -0
- package/createDocs.js +42 -0
- package/docs.json +174 -0
- package/docs.ts +5266 -0
- package/index.ts +251 -0
- package/neurai_methods.md +4580 -0
- package/package.json +43 -0
package/index.ts
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { methods } from "./docs";
|
|
3
|
+
|
|
4
|
+
export { methods };
|
|
5
|
+
function throwSyntaxError() {
|
|
6
|
+
throw new Error("Syntax error, call getRPC with (username, password, URL)");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function getRPC(username: string, password: string, URL: string) {
|
|
10
|
+
if (!username) {
|
|
11
|
+
throwSyntaxError();
|
|
12
|
+
}
|
|
13
|
+
if (!password) {
|
|
14
|
+
throwSyntaxError();
|
|
15
|
+
}
|
|
16
|
+
if (!URL) {
|
|
17
|
+
throwSyntaxError();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return async function rpc(method: string, params: any[]) {
|
|
21
|
+
const promise = new Promise((resolutionFunc, rejectionFunc) => {
|
|
22
|
+
const options = {
|
|
23
|
+
auth: {
|
|
24
|
+
username,
|
|
25
|
+
password,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
const data = {
|
|
29
|
+
jsonrpc: "2.0",
|
|
30
|
+
id: Math.random(),
|
|
31
|
+
method,
|
|
32
|
+
params,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
const rpcResponse = axios.post(URL, data, options);
|
|
37
|
+
|
|
38
|
+
rpcResponse
|
|
39
|
+
.then((re) => {
|
|
40
|
+
const result = re.data.result;
|
|
41
|
+
resolutionFunc(result);
|
|
42
|
+
})
|
|
43
|
+
.catch((e) => {
|
|
44
|
+
if (e.response) {
|
|
45
|
+
//We were able to connect to the wallet but something was wrong with our request
|
|
46
|
+
|
|
47
|
+
const { response } = e;
|
|
48
|
+
const { request, ...errorObject } = response;
|
|
49
|
+
|
|
50
|
+
rejectionFunc({
|
|
51
|
+
status: e.response.status,
|
|
52
|
+
statusText: e.response.statusText,
|
|
53
|
+
error: errorObject.data.error,
|
|
54
|
+
description: `Could connect to Raven core node but got an error. Method "${method}"`,
|
|
55
|
+
});
|
|
56
|
+
} else if (e.request) {
|
|
57
|
+
//Could NOT connect to wallet
|
|
58
|
+
|
|
59
|
+
rejectionFunc({
|
|
60
|
+
type:"ServerUnreachable",
|
|
61
|
+
error: "Could not communicate with Raven core node",
|
|
62
|
+
description:
|
|
63
|
+
"Are you sure that the URL is correct? The URL is usually something like http://localhost:8766",
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
} catch (e) {
|
|
68
|
+
rejectionFunc(e.response);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return promise;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function getValidMethods() {
|
|
75
|
+
const keys = Object.keys(methods).sort();
|
|
76
|
+
return keys.join(" ");
|
|
77
|
+
}
|
|
78
|
+
/*
|
|
79
|
+
export const methods = {
|
|
80
|
+
"getaddressbalance": "getaddressbalance",
|
|
81
|
+
"getaddressdeltas": "getaddressdeltas",
|
|
82
|
+
"getaddressmempool": "getaddressmempool",
|
|
83
|
+
"getaddresstxids": "getaddresstxids",
|
|
84
|
+
"getaddressutxos": "getaddressutxos",
|
|
85
|
+
"getassetdata": "getassetdata",
|
|
86
|
+
"getcacheinfo": "getcacheinfo",
|
|
87
|
+
"getsnapshot": "getsnapshot",
|
|
88
|
+
"issue": "issue",
|
|
89
|
+
"issueunique": "issueunique",
|
|
90
|
+
"listaddressesbyasset": "listaddressesbyasset",
|
|
91
|
+
"listassetbalancesbyaddress": "listassetbalancesbyaddress",
|
|
92
|
+
"listassets": "listassets",
|
|
93
|
+
"listmyassets": "listmyassets",
|
|
94
|
+
"purgesnapshot": "purgesnapshot",
|
|
95
|
+
"reissue": "reissue",
|
|
96
|
+
"transfer": "transfer",
|
|
97
|
+
"transferfromaddress": "transferfromaddress",
|
|
98
|
+
"transferfromaddresses": "transferfromaddresses",
|
|
99
|
+
"clearmempool": "clearmempool",
|
|
100
|
+
"decodeblock": "decodeblock",
|
|
101
|
+
"getbestblockhash": "getbestblockhash",
|
|
102
|
+
"getblock": "getblock",
|
|
103
|
+
"getblockchaininfo": "getblockchaininfo",
|
|
104
|
+
"getblockcount": "getblockcount",
|
|
105
|
+
"getblockhash": "getblockhash",
|
|
106
|
+
"getblockhashes": "getblockhashes",
|
|
107
|
+
"getblockheader": "getblockheader",
|
|
108
|
+
"getchaintips": "getchaintips",
|
|
109
|
+
"getchaintxstats": "getchaintxstats",
|
|
110
|
+
"getdifficulty": "getdifficulty",
|
|
111
|
+
"getmempoolancestors": "getmempoolancestors",
|
|
112
|
+
"getmempooldescendants": "getmempooldescendants",
|
|
113
|
+
"getmempoolentry": "getmempoolentry",
|
|
114
|
+
"getmempoolinfo": "getmempoolinfo",
|
|
115
|
+
"getrawmempool": "getrawmempool",
|
|
116
|
+
"getspentinfo": "getspentinfo",
|
|
117
|
+
"gettxout": "gettxout",
|
|
118
|
+
"gettxoutproof": "gettxoutproof",
|
|
119
|
+
"gettxoutsetinfo": "gettxoutsetinfo",
|
|
120
|
+
"preciousblock": "preciousblock",
|
|
121
|
+
"pruneblockchain": "pruneblockchain",
|
|
122
|
+
"savemempool": "savemempool",
|
|
123
|
+
"verifychain": "verifychain",
|
|
124
|
+
"verifytxoutproof": "verifytxoutproof",
|
|
125
|
+
"getinfo": "getinfo",
|
|
126
|
+
"getmemoryinfo": "getmemoryinfo",
|
|
127
|
+
"getrpcinfo": "getrpcinfo",
|
|
128
|
+
"help": "help",
|
|
129
|
+
"stop": "stop",
|
|
130
|
+
"uptime": "uptime",
|
|
131
|
+
"generate": "generate",
|
|
132
|
+
"generatetoaddress": "generatetoaddress",
|
|
133
|
+
"getgenerate": "getgenerate",
|
|
134
|
+
"setgenerate": "setgenerate",
|
|
135
|
+
"clearmessages": "clearmessages",
|
|
136
|
+
"sendmessage": "sendmessage",
|
|
137
|
+
"subscribetochannel": "subscribetochannel",
|
|
138
|
+
"unsubscribefromchannel": "unsubscribefromchannel",
|
|
139
|
+
"viewallmessagechannels": "viewallmessagechannels",
|
|
140
|
+
"viewallmessages": "viewallmessages",
|
|
141
|
+
"getblocktemplate": "getblocktemplate",
|
|
142
|
+
"getkawpowhash": "getkawpowhash",
|
|
143
|
+
"getmininginfo": "getmininginfo",
|
|
144
|
+
"getnetworkhashps": "getnetworkhashps",
|
|
145
|
+
"pprpcsb": "pprpcsb",
|
|
146
|
+
"prioritisetransaction": "prioritisetransaction",
|
|
147
|
+
"submitblock": "submitblock",
|
|
148
|
+
"addnode": "addnode",
|
|
149
|
+
"clearbanned": "clearbanned",
|
|
150
|
+
"disconnectnode": "disconnectnode",
|
|
151
|
+
"getaddednodeinfo": "getaddednodeinfo",
|
|
152
|
+
"getconnectioncount": "getconnectioncount",
|
|
153
|
+
"getnettotals": "getnettotals",
|
|
154
|
+
"getnetworkinfo": "getnetworkinfo",
|
|
155
|
+
"getpeerinfo": "getpeerinfo",
|
|
156
|
+
"listbanned": "listbanned",
|
|
157
|
+
"ping": "ping",
|
|
158
|
+
"setban": "setban",
|
|
159
|
+
"setnetworkactive": "setnetworkactive",
|
|
160
|
+
"combinerawtransaction": "combinerawtransaction",
|
|
161
|
+
"createrawtransaction": "createrawtransaction",
|
|
162
|
+
"decoderawtransaction": "decoderawtransaction",
|
|
163
|
+
"decodescript": "decodescript",
|
|
164
|
+
"fundrawtransaction": "fundrawtransaction",
|
|
165
|
+
"getrawtransaction": "getrawtransaction",
|
|
166
|
+
"sendrawtransaction": "sendrawtransaction",
|
|
167
|
+
"signrawtransaction": "signrawtransaction",
|
|
168
|
+
"testmempoolaccept": "testmempoolaccept",
|
|
169
|
+
"addtagtoaddress": "addtagtoaddress",
|
|
170
|
+
"checkaddressrestriction": "checkaddressrestriction",
|
|
171
|
+
"checkaddresstag": "checkaddresstag",
|
|
172
|
+
"checkglobalrestriction": "checkglobalrestriction",
|
|
173
|
+
"freezeaddress": "freezeaddress",
|
|
174
|
+
"freezerestrictedasset": "freezerestrictedasset",
|
|
175
|
+
"getverifierstring": "getverifierstring",
|
|
176
|
+
"issuequalifierasset": "issuequalifierasset",
|
|
177
|
+
"issuerestrictedasset": "issuerestrictedasset",
|
|
178
|
+
"isvalidverifierstring": "isvalidverifierstring",
|
|
179
|
+
"listaddressesfortag": "listaddressesfortag",
|
|
180
|
+
"listaddressrestrictions": "listaddressrestrictions",
|
|
181
|
+
"listglobalrestrictions": "listglobalrestrictions",
|
|
182
|
+
"listtagsforaddress": "listtagsforaddress",
|
|
183
|
+
"reissuerestrictedasset": "reissuerestrictedasset",
|
|
184
|
+
"removetagfromaddress": "removetagfromaddress",
|
|
185
|
+
"transferqualifier": "transferqualifier",
|
|
186
|
+
"unfreezeaddress": "unfreezeaddress",
|
|
187
|
+
"unfreezerestrictedasset": "unfreezerestrictedasset",
|
|
188
|
+
"viewmyrestrictedaddresses": "viewmyrestrictedaddresses",
|
|
189
|
+
"viewmytaggedaddresses": "viewmytaggedaddresses",
|
|
190
|
+
"cancelsnapshotrequest": "cancelsnapshotrequest",
|
|
191
|
+
"distributereward": "distributereward",
|
|
192
|
+
"getdistributestatus": "getdistributestatus",
|
|
193
|
+
"getsnapshotrequest": "getsnapshotrequest",
|
|
194
|
+
"listsnapshotrequests": "listsnapshotrequests",
|
|
195
|
+
"requestsnapshot": "requestsnapshot",
|
|
196
|
+
"createmultisig": "createmultisig",
|
|
197
|
+
"estimatefee": "estimatefee",
|
|
198
|
+
"estimatesmartfee": "estimatesmartfee",
|
|
199
|
+
"signmessagewithprivkey": "signmessagewithprivkey",
|
|
200
|
+
"validateaddress": "validateaddress",
|
|
201
|
+
"verifymessage": "verifymessage",
|
|
202
|
+
"abandontransaction": "abandontransaction",
|
|
203
|
+
"abortrescan": "abortrescan",
|
|
204
|
+
"addmultisigaddress": "addmultisigaddress",
|
|
205
|
+
"addwitnessaddress": "addwitnessaddress",
|
|
206
|
+
"backupwallet": "backupwallet",
|
|
207
|
+
"bumpfee": "bumpfee",
|
|
208
|
+
"dumpprivkey": "dumpprivkey",
|
|
209
|
+
"dumpwallet": "dumpwallet",
|
|
210
|
+
"encryptwallet": "encryptwallet",
|
|
211
|
+
"getaccount": "getaccount",
|
|
212
|
+
"getaccountaddress": "getaccountaddress",
|
|
213
|
+
"getaddressesbyaccount": "getaddressesbyaccount",
|
|
214
|
+
"getbalance": "getbalance",
|
|
215
|
+
"getmasterkeyinfo": "getmasterkeyinfo",
|
|
216
|
+
"getmywords": "getmywords",
|
|
217
|
+
"getnewaddress": "getnewaddress",
|
|
218
|
+
"getrawchangeaddress": "getrawchangeaddress",
|
|
219
|
+
"getreceivedbyaccount": "getreceivedbyaccount",
|
|
220
|
+
"getreceivedbyaddress": "getreceivedbyaddress",
|
|
221
|
+
"gettransaction": "gettransaction",
|
|
222
|
+
"getunconfirmedbalance": "getunconfirmedbalance",
|
|
223
|
+
"getwalletinfo": "getwalletinfo",
|
|
224
|
+
"importaddress": "importaddress",
|
|
225
|
+
"importmulti": "importmulti",
|
|
226
|
+
"importprivkey": "importprivkey",
|
|
227
|
+
"importprunedfunds": "importprunedfunds",
|
|
228
|
+
"importpubkey": "importpubkey",
|
|
229
|
+
"importwallet": "importwallet",
|
|
230
|
+
"keypoolrefill": "keypoolrefill",
|
|
231
|
+
"listaccounts": "listaccounts",
|
|
232
|
+
"listaddressgroupings": "listaddressgroupings",
|
|
233
|
+
"listlockunspent": "listlockunspent",
|
|
234
|
+
"listreceivedbyaccount": "listreceivedbyaccount",
|
|
235
|
+
"listreceivedbyaddress": "listreceivedbyaddress",
|
|
236
|
+
"listsinceblock": "listsinceblock",
|
|
237
|
+
"listtransactions": "listtransactions",
|
|
238
|
+
"listunspent": "listunspent",
|
|
239
|
+
"listwallets": "listwallets",
|
|
240
|
+
"lockunspent": "lockunspent",
|
|
241
|
+
"move": "move",
|
|
242
|
+
"removeprunedfunds": "removeprunedfunds",
|
|
243
|
+
"rescanblockchain": "rescanblockchain",
|
|
244
|
+
"sendfrom": "sendfrom",
|
|
245
|
+
"sendfromaddress": "sendfromaddress",
|
|
246
|
+
"sendmany": "sendmany",
|
|
247
|
+
"sendtoaddress": "sendtoaddress",
|
|
248
|
+
"setaccount": "setaccount",
|
|
249
|
+
"settxfee": "settxfee",
|
|
250
|
+
"signmessage": "signmessage"
|
|
251
|
+
}*/
|