@xelis/sdk 0.11.44 → 0.12.1
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/dist/cjs/address/index.spec.js +34 -0
- package/dist/cjs/daemon/rpc.js +17 -2
- package/dist/cjs/daemon/rpc.spec.js +640 -0
- package/dist/cjs/daemon/types.js +8 -3
- package/dist/cjs/daemon/websocket.js +16 -1
- package/dist/cjs/daemon/websocket.spec.js +103 -0
- package/dist/cjs/data/element.spec.js +67 -0
- package/dist/cjs/rpc/parse_json/parse_json.spec.js +24 -0
- package/dist/cjs/wallet/rpc.js +24 -0
- package/dist/cjs/wallet/rpc.spec.js +270 -0
- package/dist/cjs/wallet/types.js +10 -1
- package/dist/cjs/wallet/websocket.js +26 -2
- package/dist/cjs/wallet/websocket.spec.js +20 -0
- package/dist/cjs/xswd/websocket.spec.js +34 -0
- package/dist/esm/address/index.spec.js +29 -0
- package/dist/esm/daemon/rpc.js +17 -2
- package/dist/esm/daemon/rpc.spec.js +635 -0
- package/dist/esm/daemon/types.js +8 -3
- package/dist/esm/daemon/websocket.js +16 -1
- package/dist/esm/daemon/websocket.spec.js +98 -0
- package/dist/esm/data/element.spec.js +65 -0
- package/dist/esm/rpc/parse_json/parse_json.spec.js +19 -0
- package/dist/esm/wallet/rpc.js +24 -0
- package/dist/esm/wallet/rpc.spec.js +265 -0
- package/dist/esm/wallet/types.js +10 -1
- package/dist/esm/wallet/websocket.js +26 -2
- package/dist/esm/wallet/websocket.spec.js +15 -0
- package/dist/esm/xswd/websocket.spec.js +29 -0
- package/dist/types/address/index.spec.d.ts +1 -0
- package/dist/types/daemon/rpc.d.ts +7 -2
- package/dist/types/daemon/rpc.spec.d.ts +1 -0
- package/dist/types/daemon/types.d.ts +56 -4
- package/dist/types/daemon/websocket.d.ts +8 -9
- package/dist/types/daemon/websocket.spec.d.ts +1 -0
- package/dist/types/data/element.spec.d.ts +1 -0
- package/dist/types/rpc/parse_json/parse_json.spec.d.ts +1 -0
- package/dist/types/wallet/rpc.d.ts +8 -0
- package/dist/types/wallet/rpc.spec.d.ts +1 -0
- package/dist/types/wallet/types.d.ts +46 -1
- package/dist/types/wallet/websocket.d.ts +12 -0
- package/dist/types/wallet/websocket.spec.d.ts +1 -0
- package/dist/types/xswd/websocket.spec.d.ts +1 -0
- package/package.json +1 -1
|
@@ -234,7 +234,7 @@ class DaemonMethods {
|
|
|
234
234
|
return this.dataCall(types_1.RPCMethod.GetContractRegisteredExecutionsAtTopoheight, params);
|
|
235
235
|
}
|
|
236
236
|
getContractsOutputs(params) {
|
|
237
|
-
return this.dataCall(types_1.RPCMethod.GetContractsOutputs);
|
|
237
|
+
return this.dataCall(types_1.RPCMethod.GetContractsOutputs, params);
|
|
238
238
|
}
|
|
239
239
|
getContractModule(params) {
|
|
240
240
|
return this.dataCall(types_1.RPCMethod.GetContractModule, params);
|
|
@@ -272,6 +272,21 @@ class DaemonMethods {
|
|
|
272
272
|
submitBlock(params) {
|
|
273
273
|
return this.dataCall(types_1.RPCMethod.SubmitBlock, params);
|
|
274
274
|
}
|
|
275
|
+
getContractTransactions(params) {
|
|
276
|
+
return this.dataCall(types_1.RPCMethod.GetContractTransactions, params);
|
|
277
|
+
}
|
|
278
|
+
simulateContractInvoke(params) {
|
|
279
|
+
return this.dataCall(types_1.RPCMethod.SimulateContractInvoke, params);
|
|
280
|
+
}
|
|
281
|
+
rewindChain(params) {
|
|
282
|
+
return this.dataCall(types_1.RPCMethod.RewindChain, params);
|
|
283
|
+
}
|
|
284
|
+
clearCaches() {
|
|
285
|
+
return this.dataCall(types_1.RPCMethod.ClearCaches);
|
|
286
|
+
}
|
|
287
|
+
pruneChain(params) {
|
|
288
|
+
return this.dataCall(types_1.RPCMethod.PruneChain, params);
|
|
289
|
+
}
|
|
275
290
|
}
|
|
276
291
|
exports.DaemonMethods = DaemonMethods;
|
|
277
292
|
class WS extends websocket_1.WSRPC {
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const await_to_js_1 = require("await-to-js");
|
|
7
|
+
const config_1 = require("../config");
|
|
8
|
+
const types_1 = require("./types");
|
|
9
|
+
const websocket_1 = __importDefault(require("./websocket"));
|
|
10
|
+
describe('DaemonWS', () => {
|
|
11
|
+
test('getInfo', async () => {
|
|
12
|
+
const daemonWS = new websocket_1.default(config_1.MAINNET_NODE_WS);
|
|
13
|
+
// we don't need to wait for socket open
|
|
14
|
+
//daemonWS.socket.addEventListener(`open`, async () => {
|
|
15
|
+
const [err1, res] = await (0, await_to_js_1.to)(daemonWS.methods.getInfo());
|
|
16
|
+
expect(err1).toBeNull();
|
|
17
|
+
console.log(res);
|
|
18
|
+
expect(res);
|
|
19
|
+
daemonWS.socket.close();
|
|
20
|
+
//})
|
|
21
|
+
});
|
|
22
|
+
const timeout = 40000;
|
|
23
|
+
test('listen_NewBlock', () => {
|
|
24
|
+
return new Promise(async (resolve, reject) => {
|
|
25
|
+
const daemonWS = new websocket_1.default(config_1.MAINNET_NODE_WS);
|
|
26
|
+
daemonWS.socket.addEventListener(`open`, async () => {
|
|
27
|
+
const doneTest = (err) => {
|
|
28
|
+
daemonWS.socket.close();
|
|
29
|
+
if (err)
|
|
30
|
+
return reject(err);
|
|
31
|
+
resolve(null);
|
|
32
|
+
};
|
|
33
|
+
daemonWS.methods.addListener(types_1.RPCEvent.NewBlock, null, async (data, err) => {
|
|
34
|
+
console.log(data);
|
|
35
|
+
doneTest(err);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}, timeout);
|
|
40
|
+
test('listen_ContractInvoke', () => {
|
|
41
|
+
return new Promise(async (resolve, reject) => {
|
|
42
|
+
const daemonWS = new websocket_1.default(config_1.MAINNET_NODE_WS);
|
|
43
|
+
daemonWS.socket.addEventListener(`open`, async () => {
|
|
44
|
+
const doneTest = (err) => {
|
|
45
|
+
daemonWS.socket.close();
|
|
46
|
+
if (err)
|
|
47
|
+
return reject(err);
|
|
48
|
+
resolve(null);
|
|
49
|
+
};
|
|
50
|
+
daemonWS.methods.addListener(types_1.RPCEvent.ContractInvoke, { contract: "32c5ccae542846696b0cd7f40949023219e123adca44d123d14d467ae8761f83" }, async (data, err) => {
|
|
51
|
+
console.log(data);
|
|
52
|
+
doneTest(err);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}, timeout);
|
|
57
|
+
test('multi_listen', () => {
|
|
58
|
+
return new Promise(async (resolve, reject) => {
|
|
59
|
+
const daemonWS = new websocket_1.default(config_1.MAINNET_NODE_WS);
|
|
60
|
+
daemonWS.socket.addEventListener(`open`, async () => {
|
|
61
|
+
let count = 3;
|
|
62
|
+
const doneTest = async (err) => {
|
|
63
|
+
if (err)
|
|
64
|
+
return reject(err);
|
|
65
|
+
count--;
|
|
66
|
+
if (count === 0) {
|
|
67
|
+
daemonWS.socket.close();
|
|
68
|
+
resolve(null);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
for (let i = 0; i < count; i++) {
|
|
72
|
+
daemonWS.methods.addListener(types_1.RPCEvent.NewBlock, null, async (data, err) => {
|
|
73
|
+
console.log(data);
|
|
74
|
+
doneTest(err);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}, timeout);
|
|
80
|
+
test('check_invalid_event', async () => {
|
|
81
|
+
const daemonWS = new websocket_1.default(config_1.MAINNET_NODE_WS);
|
|
82
|
+
daemonWS.socket.addEventListener(`open`, async () => {
|
|
83
|
+
daemonWS.addListener(`asdasd`, async (data, err) => {
|
|
84
|
+
}).catch((err) => {
|
|
85
|
+
expect(err).toBeDefined();
|
|
86
|
+
daemonWS.socket.close();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
test(`batchRequest`, async () => {
|
|
91
|
+
const daemonWS = new websocket_1.default(config_1.MAINNET_NODE_WS);
|
|
92
|
+
daemonWS.socket.addEventListener(`open`, async () => {
|
|
93
|
+
const requests = [
|
|
94
|
+
{ method: types_1.RPCMethod.GetTopoheight },
|
|
95
|
+
{ method: types_1.RPCMethod.GetInfo },
|
|
96
|
+
{ method: "invalid" }
|
|
97
|
+
];
|
|
98
|
+
const [err1, res] = await (0, await_to_js_1.to)(daemonWS.batchCall(requests));
|
|
99
|
+
console.log(err1, res);
|
|
100
|
+
expect(err1).toBeNull();
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const element_1 = require("./element");
|
|
4
|
+
const value_1 = require("./value");
|
|
5
|
+
test(`TestElementValue`, () => {
|
|
6
|
+
let value = new value_1.Value(value_1.ValueType.String, "Hello world");
|
|
7
|
+
let element = element_1.Element.value(value);
|
|
8
|
+
let data = element.toBytes();
|
|
9
|
+
let newElement = element_1.Element.fromBytes(data);
|
|
10
|
+
let obj = element.toObject();
|
|
11
|
+
let jsonObj = JSON.stringify(obj);
|
|
12
|
+
});
|
|
13
|
+
test(`TestValueNew`, () => {
|
|
14
|
+
let str = value_1.Value.new("hello");
|
|
15
|
+
if (str.vType !== value_1.ValueType.String)
|
|
16
|
+
throw "";
|
|
17
|
+
let u8 = value_1.Value.new(10);
|
|
18
|
+
if (u8.vType !== value_1.ValueType.U8)
|
|
19
|
+
throw "";
|
|
20
|
+
let u16 = value_1.Value.new(34523);
|
|
21
|
+
if (u16.vType !== value_1.ValueType.U16)
|
|
22
|
+
throw "";
|
|
23
|
+
let u32 = value_1.Value.new(3452305469);
|
|
24
|
+
if (u32.vType !== value_1.ValueType.U32)
|
|
25
|
+
throw "";
|
|
26
|
+
let u64 = value_1.Value.new(BigInt("3452305469567567456"));
|
|
27
|
+
if (u64.vType !== value_1.ValueType.U64)
|
|
28
|
+
throw "";
|
|
29
|
+
let u128 = value_1.Value.new(BigInt("2093458230498572039452039485702938475"));
|
|
30
|
+
if (u128.vType !== value_1.ValueType.U128)
|
|
31
|
+
throw "";
|
|
32
|
+
let blob = value_1.Value.new([1, 2, 3, 4, 5]);
|
|
33
|
+
if (blob.vType !== value_1.ValueType.Blob)
|
|
34
|
+
throw "";
|
|
35
|
+
let hash = value_1.Value.new(new Uint8Array([185, 77, 39, 185, 147, 77, 62, 8, 165, 46, 82, 215, 218, 125, 171, 250, 196, 132, 239, 227, 122, 83, 128, 238, 144, 136, 247, 172, 226, 239, 205, 233]));
|
|
36
|
+
if (hash.vType !== value_1.ValueType.Hash)
|
|
37
|
+
throw "";
|
|
38
|
+
let bool = value_1.Value.new(true);
|
|
39
|
+
if (bool.vType !== value_1.ValueType.Bool)
|
|
40
|
+
throw "";
|
|
41
|
+
});
|
|
42
|
+
test(`TestElementArray`, async () => {
|
|
43
|
+
let encoder = new TextEncoder();
|
|
44
|
+
let data = encoder.encode("hello world");
|
|
45
|
+
let hashBuf = await crypto.subtle.digest("SHA-256", data);
|
|
46
|
+
let hash = new Uint8Array(hashBuf);
|
|
47
|
+
let element = element_1.Element.array([
|
|
48
|
+
element_1.Element.value(new value_1.Value(value_1.ValueType.String, "Hello world")),
|
|
49
|
+
element_1.Element.value(new value_1.Value(value_1.ValueType.U8, 34)),
|
|
50
|
+
element_1.Element.value(new value_1.Value(value_1.ValueType.U16, 34523)),
|
|
51
|
+
element_1.Element.value(new value_1.Value(value_1.ValueType.U32, 3452305469)),
|
|
52
|
+
element_1.Element.value(new value_1.Value(value_1.ValueType.U64, BigInt("3452305469567567456"))),
|
|
53
|
+
element_1.Element.value(new value_1.Value(value_1.ValueType.U128, BigInt("2093458230498572039452039485702938475"))),
|
|
54
|
+
element_1.Element.value(new value_1.Value(value_1.ValueType.Hash, hash)),
|
|
55
|
+
element_1.Element.value(new value_1.Value(value_1.ValueType.Blob, [0, 1, 2, 3, 4, 5]))
|
|
56
|
+
]);
|
|
57
|
+
let bytes = element.toBytes();
|
|
58
|
+
let newElement = element_1.Element.fromBytes(bytes);
|
|
59
|
+
let obj = element.toObject();
|
|
60
|
+
});
|
|
61
|
+
test(`TestElementFields`, () => {
|
|
62
|
+
let fields = new Map();
|
|
63
|
+
fields.set(value_1.Value.new("hello"), element_1.Element.v("world"));
|
|
64
|
+
let element = element_1.Element.fields(fields);
|
|
65
|
+
let obj = element.toObject();
|
|
66
|
+
let jsonObj = JSON.stringify(obj);
|
|
67
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const parse_json_1 = require("./parse_json");
|
|
8
|
+
test(`parseJsonPerf`, () => {
|
|
9
|
+
// load data using fs instead of import or fix-esm will hang
|
|
10
|
+
const bigData = fs_1.default.readFileSync(`./src/rpc/parse_json/test_data.txt`, `utf-8`);
|
|
11
|
+
console.time();
|
|
12
|
+
let data = (0, parse_json_1.parseJSON)(bigData);
|
|
13
|
+
console.timeEnd();
|
|
14
|
+
console.time();
|
|
15
|
+
data = JSON.parse(bigData);
|
|
16
|
+
console.timeEnd();
|
|
17
|
+
});
|
|
18
|
+
test(`bigNumber`, () => {
|
|
19
|
+
const test = `{ "nonce": 234905872304968723405968730498576039485, "nbr": 23452, "nonce_string": "234905872304968723405968730498576039485" }`;
|
|
20
|
+
let data = (0, parse_json_1.parseJSON)(test);
|
|
21
|
+
console.log(data, data["nonce"], data["nbr"]);
|
|
22
|
+
data = JSON.parse(test);
|
|
23
|
+
console.log(data, data["nonce"], data["nbr"]);
|
|
24
|
+
});
|
package/dist/cjs/wallet/rpc.js
CHANGED
|
@@ -40,6 +40,15 @@ class RPC extends http_1.HttpRPC {
|
|
|
40
40
|
getTrackedAssets() {
|
|
41
41
|
return this.request(types_1.RPCMethod.GetTrackedAssets);
|
|
42
42
|
}
|
|
43
|
+
isAssetTracked(asset) {
|
|
44
|
+
return this.request(types_1.RPCMethod.IsAssetTracked, { asset });
|
|
45
|
+
}
|
|
46
|
+
trackAsset(params) {
|
|
47
|
+
return this.request(types_1.RPCMethod.TrackAsset, params);
|
|
48
|
+
}
|
|
49
|
+
untrackAsset(params) {
|
|
50
|
+
return this.request(types_1.RPCMethod.UntrackAsset, params);
|
|
51
|
+
}
|
|
43
52
|
getAssetPrecision(params) {
|
|
44
53
|
return this.request(types_1.RPCMethod.GetAssetPrecision, params);
|
|
45
54
|
}
|
|
@@ -73,6 +82,9 @@ class RPC extends http_1.HttpRPC {
|
|
|
73
82
|
finalizeUnsignedTransaction(params) {
|
|
74
83
|
return this.request(types_1.RPCMethod.FinalizeUnsignedTransaction, params);
|
|
75
84
|
}
|
|
85
|
+
getPendingTransactions() {
|
|
86
|
+
return this.request(types_1.RPCMethod.GetPendingTransactions);
|
|
87
|
+
}
|
|
76
88
|
clearTxCache() {
|
|
77
89
|
return this.request(types_1.RPCMethod.ClearTxCache);
|
|
78
90
|
}
|
|
@@ -91,6 +103,9 @@ class RPC extends http_1.HttpRPC {
|
|
|
91
103
|
signData(data) {
|
|
92
104
|
return this.request(types_1.RPCMethod.SignData, data.toObject());
|
|
93
105
|
}
|
|
106
|
+
verifySignedData(params) {
|
|
107
|
+
return this.request(types_1.RPCMethod.VerifySignedData, params);
|
|
108
|
+
}
|
|
94
109
|
estimateFees(params) {
|
|
95
110
|
return this.request(types_1.RPCMethod.EstimateFees, params);
|
|
96
111
|
}
|
|
@@ -106,6 +121,15 @@ class RPC extends http_1.HttpRPC {
|
|
|
106
121
|
decryptCiphertext(params) {
|
|
107
122
|
return this.request(types_1.RPCMethod.DecryptCiphertext, params);
|
|
108
123
|
}
|
|
124
|
+
createOwnershipProof(params) {
|
|
125
|
+
return this.request(types_1.RPCMethod.CreateOwnershipProof, params);
|
|
126
|
+
}
|
|
127
|
+
createBalanceProof(params) {
|
|
128
|
+
return this.request(types_1.RPCMethod.CreateBalanceProof, params);
|
|
129
|
+
}
|
|
130
|
+
verifyHumanReadableProof(params) {
|
|
131
|
+
return this.request(types_1.RPCMethod.VerifyHumanReadableProof, params);
|
|
132
|
+
}
|
|
109
133
|
getMatchingKeys(params) {
|
|
110
134
|
return this.request(types_1.RPCMethod.GetMatchingKeys, params);
|
|
111
135
|
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const await_to_js_1 = require("await-to-js");
|
|
7
|
+
const element_1 = require("../data/element");
|
|
8
|
+
const config_1 = require("../config");
|
|
9
|
+
const rpc_1 = __importDefault(require("./rpc"));
|
|
10
|
+
const walletRPC = new rpc_1.default(config_1.LOCAL_WALLET_RPC, `test`, `test`);
|
|
11
|
+
describe('WalletRPC', () => {
|
|
12
|
+
test('getVersion', async () => {
|
|
13
|
+
const [err, res] = await (0, await_to_js_1.to)(walletRPC.getVersion());
|
|
14
|
+
expect(err).toBeNull();
|
|
15
|
+
console.log(res);
|
|
16
|
+
expect(res);
|
|
17
|
+
});
|
|
18
|
+
test('getNetwork', async () => {
|
|
19
|
+
const [err, res] = await (0, await_to_js_1.to)(walletRPC.getNetwork());
|
|
20
|
+
expect(err).toBeNull();
|
|
21
|
+
console.log(res);
|
|
22
|
+
expect(res);
|
|
23
|
+
});
|
|
24
|
+
test('getNonce', async () => {
|
|
25
|
+
const [err, res] = await (0, await_to_js_1.to)(walletRPC.getNonce());
|
|
26
|
+
expect(err).toBeNull();
|
|
27
|
+
console.log(res);
|
|
28
|
+
expect(res);
|
|
29
|
+
});
|
|
30
|
+
test('getTopoheight', async () => {
|
|
31
|
+
const [err, res] = await (0, await_to_js_1.to)(walletRPC.getTopoheight());
|
|
32
|
+
expect(err).toBeNull();
|
|
33
|
+
console.log(res);
|
|
34
|
+
expect(res);
|
|
35
|
+
});
|
|
36
|
+
test('getAddress', async () => {
|
|
37
|
+
const [err, res] = await (0, await_to_js_1.to)(walletRPC.getAddress());
|
|
38
|
+
expect(err).toBeNull();
|
|
39
|
+
console.log(res);
|
|
40
|
+
expect(res);
|
|
41
|
+
});
|
|
42
|
+
test('splitAddress', async () => {
|
|
43
|
+
const [err, res] = await (0, await_to_js_1.to)(walletRPC.splitAddress({
|
|
44
|
+
address: `xet:6eadzwf5xdacts6fs4y3csmnsmy4mcxewqt3xyygwfx0hm0tm32szqsrqyzkjar9d4esyqgpq4ehwmmjvsqqypgpq45x2mrvduqqzpthdaexceqpq4mk7unywvqsgqqpq4yx2mrvduqqzp2hdaexceqqqyzxvun0d5qqzp2cg4xyj5ct5udlg`
|
|
45
|
+
}));
|
|
46
|
+
expect(err).toBeNull();
|
|
47
|
+
console.log(res);
|
|
48
|
+
expect(res);
|
|
49
|
+
});
|
|
50
|
+
test('getBalance', async () => {
|
|
51
|
+
const [err, res] = await (0, await_to_js_1.to)(walletRPC.getBalance());
|
|
52
|
+
expect(err).toBeNull();
|
|
53
|
+
console.log(res);
|
|
54
|
+
expect(res);
|
|
55
|
+
});
|
|
56
|
+
test('hasBalance', async () => {
|
|
57
|
+
const [err, res] = await (0, await_to_js_1.to)(walletRPC.hasBalance());
|
|
58
|
+
expect(err).toBeNull();
|
|
59
|
+
console.log(res);
|
|
60
|
+
expect(res);
|
|
61
|
+
});
|
|
62
|
+
test('getTrackedAssets', async () => {
|
|
63
|
+
const [err, res] = await (0, await_to_js_1.to)(walletRPC.getTrackedAssets());
|
|
64
|
+
expect(err).toBeNull();
|
|
65
|
+
console.log(res);
|
|
66
|
+
expect(res);
|
|
67
|
+
});
|
|
68
|
+
test('getAssetPrecision', async () => {
|
|
69
|
+
const [err, res] = await (0, await_to_js_1.to)(walletRPC.getAssetPrecision({
|
|
70
|
+
asset: config_1.XELIS_ASSET
|
|
71
|
+
}));
|
|
72
|
+
expect(err).toBeNull();
|
|
73
|
+
console.log(res);
|
|
74
|
+
expect(res);
|
|
75
|
+
});
|
|
76
|
+
test('getTransaction', async () => {
|
|
77
|
+
const [err, res] = await (0, await_to_js_1.to)(walletRPC.getTransaction(`381edf117446514852eace4e48e641d072d285e9c610662e21d2ae5a1cc0367a`));
|
|
78
|
+
expect(err).toBeNull();
|
|
79
|
+
console.log(res);
|
|
80
|
+
expect(res);
|
|
81
|
+
});
|
|
82
|
+
test('buildTransaction', async () => {
|
|
83
|
+
const [err, res] = await (0, await_to_js_1.to)(walletRPC.buildTransaction({
|
|
84
|
+
broadcast: false,
|
|
85
|
+
tx_as_hex: true,
|
|
86
|
+
transfers: [{
|
|
87
|
+
amount: 0,
|
|
88
|
+
asset: config_1.XELIS_ASSET,
|
|
89
|
+
destination: `xet:6eadzwf5xdacts6fs4y3csmnsmy4mcxewqt3xyygwfx0hm0tm32sqxdy9zk`
|
|
90
|
+
}],
|
|
91
|
+
}));
|
|
92
|
+
expect(err).toBeNull();
|
|
93
|
+
console.log(res);
|
|
94
|
+
expect(res);
|
|
95
|
+
});
|
|
96
|
+
test('buildTransactionFeeBuilder', async () => {
|
|
97
|
+
const [err, res] = await (0, await_to_js_1.to)(walletRPC.buildTransaction({
|
|
98
|
+
broadcast: false,
|
|
99
|
+
tx_as_hex: true,
|
|
100
|
+
transfers: [{
|
|
101
|
+
amount: 0,
|
|
102
|
+
asset: config_1.XELIS_ASSET,
|
|
103
|
+
destination: `xet:6eadzwf5xdacts6fs4y3csmnsmy4mcxewqt3xyygwfx0hm0tm32sqxdy9zk`
|
|
104
|
+
}],
|
|
105
|
+
fee: { extra: { multiplier: 2 } },
|
|
106
|
+
base_fee: { fixed: 1000 }
|
|
107
|
+
}));
|
|
108
|
+
expect(err).toBeNull();
|
|
109
|
+
console.log(res);
|
|
110
|
+
expect(res);
|
|
111
|
+
});
|
|
112
|
+
test('transferTransaction', async () => {
|
|
113
|
+
const [err, res] = await (0, await_to_js_1.to)(walletRPC.buildTransaction({
|
|
114
|
+
broadcast: true,
|
|
115
|
+
tx_as_hex: true,
|
|
116
|
+
transfers: [{
|
|
117
|
+
amount: 100,
|
|
118
|
+
asset: config_1.XELIS_ASSET,
|
|
119
|
+
destination: `xet:6eadzwf5xdacts6fs4y3csmnsmy4mcxewqt3xyygwfx0hm0tm32sqxdy9zk`
|
|
120
|
+
}],
|
|
121
|
+
}));
|
|
122
|
+
expect(err).toBeNull();
|
|
123
|
+
console.log(res);
|
|
124
|
+
expect(res);
|
|
125
|
+
});
|
|
126
|
+
test('burnTransaction', async () => {
|
|
127
|
+
const [err, res] = await (0, await_to_js_1.to)(walletRPC.buildTransaction({
|
|
128
|
+
broadcast: true,
|
|
129
|
+
tx_as_hex: true,
|
|
130
|
+
burn: {
|
|
131
|
+
amount: 500,
|
|
132
|
+
asset: config_1.XELIS_ASSET
|
|
133
|
+
}
|
|
134
|
+
}));
|
|
135
|
+
expect(err).toBeNull();
|
|
136
|
+
console.log(res);
|
|
137
|
+
expect(res);
|
|
138
|
+
});
|
|
139
|
+
const x_place_contract = `180003000027100003000000640008016700030000000a0008015f00080163000300000000000805456d7074790008074d6178203130300008094e6f2063616c6c6572000802636300040000000000000000030002000003ffffffff00080f4e6f2076616c696420706978656c730007000007010003000000010004000000000000000100080c636f6d6d69745f696e64657800080b706978656c5f636f756e740008056f776e6572000802747300061c0200000201000100000000002c090f1b0000000101000000002c2214010b0200000100000001001f14010b0200000100000001001f1401220200000201000002000100000003001812011c0004001c0101000003001812011c1401110200000005000100000003001813011c1401fd026d0200000100001800000006002b0007001830010100001800000001002e00080018300118e901020100010100182500000900183001010100182600020200185b01020300184f01020400010300000a00185c01000b00182700020500000c00020600000d0002070001000011121601000002080001080006000000002d092a0f8e00000001080006010000002d230f9d0000000e6c0000000e9d0000000108000602000e002b0fb50000000e6c0000000eb5000000010700010800180100010800060017010001020900010800060117020001020a00010900010a0017030002020b00010600010b00181d01020c00010c00000d00182700020d00010d00010800180100010600010b00010d00181e01070e6c000000130107001800000208000108000006002b000f0018300101060018240102090001090011120c020000020a00010a003d020b00020c00010300010c00185c01020d00010d00000d00182700020e00010b001112f9010000020f00001000021000000600021100011100010e001800002c0fdd010000010e00011100150600010f00060029090fb0010000010e00011100150601010f00060129220fd1010000010e0001110015010f002f0110000011002f0edd0100000ed1010000011100001200300e7c0100000110002a0ff4010000010e00010f001801000ef40100000e6801000013010300010c00010e00185e01070e3a010000130107000102000104001851011903020a0001030001050017040001010a00185e0107010300000a000105000013001c185e01070014000105000015000108000016000102000017000104001851011b04020b00001300010b0018e301000b001402`;
|
|
140
|
+
test('deploySmartContractTransaction', async () => {
|
|
141
|
+
// hello world smart contract
|
|
142
|
+
const [err, res] = await (0, await_to_js_1.to)(walletRPC.buildTransaction({
|
|
143
|
+
broadcast: true,
|
|
144
|
+
tx_as_hex: true,
|
|
145
|
+
deploy_contract: {
|
|
146
|
+
contract_version: "v1",
|
|
147
|
+
module: x_place_contract // "0200081868656c6c6f20776f726c642066726f6d20696e766f6b65210004000000000000000000010a000000182b010001001402"
|
|
148
|
+
}
|
|
149
|
+
}));
|
|
150
|
+
expect(err).toBeNull();
|
|
151
|
+
console.log(res);
|
|
152
|
+
expect(res);
|
|
153
|
+
});
|
|
154
|
+
test('deploySmartContractWithConstructor', async () => {
|
|
155
|
+
// hello world smart contract
|
|
156
|
+
const [err, res] = await (0, await_to_js_1.to)(walletRPC.buildTransaction({
|
|
157
|
+
broadcast: true,
|
|
158
|
+
tx_as_hex: true,
|
|
159
|
+
deploy_contract: {
|
|
160
|
+
contract_version: "v1",
|
|
161
|
+
module: "0300081d68656c6c6f20776f726c642066726f6d20636f6e7374727563746f72210004000000000000000000081868656c6c6f20776f726c642066726f6d20696e766f6b652100020a000000182b010001001403000a000200182b010001001402",
|
|
162
|
+
invoke: {
|
|
163
|
+
max_gas: 5000000,
|
|
164
|
+
deposits: {
|
|
165
|
+
"0000000000000000000000000000000000000000000000000000000000000000": {
|
|
166
|
+
amount: 100000000,
|
|
167
|
+
private: false
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}));
|
|
173
|
+
expect(err).toBeNull();
|
|
174
|
+
console.log(res);
|
|
175
|
+
expect(res);
|
|
176
|
+
});
|
|
177
|
+
test('deplySmartContractAsset', async () => {
|
|
178
|
+
// hello world smart contract
|
|
179
|
+
const [err, res] = await (0, await_to_js_1.to)(walletRPC.buildTransaction({
|
|
180
|
+
broadcast: true,
|
|
181
|
+
tx_as_hex: true,
|
|
182
|
+
deploy_contract: {
|
|
183
|
+
contract_version: "v1",
|
|
184
|
+
module: "0602020001010004000009184e72a0000004000000000000000000080948617368506f77657200080248500001080004000009184e72a00000013c000000020000000100000200000300000400010000186c010201000101000005001876010718d20118260000050001010018720118c90107000100140300",
|
|
185
|
+
invoke: {
|
|
186
|
+
max_gas: 100000000,
|
|
187
|
+
deposits: {
|
|
188
|
+
"0000000000000000000000000000000000000000000000000000000000000000": {
|
|
189
|
+
amount: 100000000,
|
|
190
|
+
private: false
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}));
|
|
196
|
+
expect(err).toBeNull();
|
|
197
|
+
console.log(res);
|
|
198
|
+
expect(res);
|
|
199
|
+
});
|
|
200
|
+
test('invokeSmartContractMint', async () => {
|
|
201
|
+
// hello world smart contract
|
|
202
|
+
const [err, res] = await (0, await_to_js_1.to)(walletRPC.buildTransaction({
|
|
203
|
+
broadcast: true,
|
|
204
|
+
tx_as_hex: true,
|
|
205
|
+
invoke_contract: {
|
|
206
|
+
contract: "4ee56bf69a18c03b5e5ee68f92a8bf73c0ba97801832dcf573231efaadc8548e",
|
|
207
|
+
entry_id: 1,
|
|
208
|
+
deposits: {},
|
|
209
|
+
max_gas: 1000000,
|
|
210
|
+
parameters: [{
|
|
211
|
+
type: "primitive",
|
|
212
|
+
value: { type: "u64", value: "1000" }
|
|
213
|
+
}],
|
|
214
|
+
permission: "none"
|
|
215
|
+
}
|
|
216
|
+
}));
|
|
217
|
+
expect(err).toBeNull();
|
|
218
|
+
console.log(res);
|
|
219
|
+
expect(res);
|
|
220
|
+
});
|
|
221
|
+
test('invokeSmartContractTransaction', async () => {
|
|
222
|
+
// hello world smart contract
|
|
223
|
+
const [err, res] = await (0, await_to_js_1.to)(walletRPC.buildTransaction({
|
|
224
|
+
broadcast: true,
|
|
225
|
+
tx_as_hex: true,
|
|
226
|
+
invoke_contract: {
|
|
227
|
+
contract: "16d69521a8b66e3098251d87e9e7e2ed430bac44d0bc56bc881d9bbfe2569297",
|
|
228
|
+
entry_id: 0,
|
|
229
|
+
deposits: {},
|
|
230
|
+
max_gas: 1000,
|
|
231
|
+
parameters: [],
|
|
232
|
+
permission: "none"
|
|
233
|
+
}
|
|
234
|
+
}));
|
|
235
|
+
expect(err).toBeNull();
|
|
236
|
+
console.log(res);
|
|
237
|
+
expect(res);
|
|
238
|
+
});
|
|
239
|
+
test('listTransactions', async () => {
|
|
240
|
+
const [err, res] = await (0, await_to_js_1.to)(walletRPC.listTransactions());
|
|
241
|
+
expect(err).toBeNull();
|
|
242
|
+
console.log(res);
|
|
243
|
+
expect(res);
|
|
244
|
+
});
|
|
245
|
+
test('isOnline', async () => {
|
|
246
|
+
const [err, res] = await (0, await_to_js_1.to)(walletRPC.isOnline());
|
|
247
|
+
expect(err).toBeNull();
|
|
248
|
+
console.log(res);
|
|
249
|
+
expect(res);
|
|
250
|
+
});
|
|
251
|
+
test('estimateFees', async () => {
|
|
252
|
+
const [err, res] = await (0, await_to_js_1.to)(walletRPC.estimateFees({
|
|
253
|
+
transfers: [{
|
|
254
|
+
amount: 0,
|
|
255
|
+
asset: config_1.XELIS_ASSET,
|
|
256
|
+
destination: `xet:6eadzwf5xdacts6fs4y3csmnsmy4mcxewqt3xyygwfx0hm0tm32sqxdy9zk`
|
|
257
|
+
}]
|
|
258
|
+
}));
|
|
259
|
+
expect(err).toBeNull();
|
|
260
|
+
console.log(res);
|
|
261
|
+
expect(res);
|
|
262
|
+
});
|
|
263
|
+
test('signData', async () => {
|
|
264
|
+
let data = element_1.Element.v("hello world");
|
|
265
|
+
const [err, publicKey] = await (0, await_to_js_1.to)(walletRPC.getAddress());
|
|
266
|
+
expect(err).toBeNull();
|
|
267
|
+
const [err2, sig] = await (0, await_to_js_1.to)(walletRPC.signData(data));
|
|
268
|
+
expect(err2).toBeNull();
|
|
269
|
+
});
|
|
270
|
+
});
|
package/dist/cjs/wallet/types.js
CHANGED
|
@@ -36,6 +36,9 @@ var RPCMethod;
|
|
|
36
36
|
RPCMethod["GetBalance"] = "get_balance";
|
|
37
37
|
RPCMethod["HasBalance"] = "has_balance";
|
|
38
38
|
RPCMethod["GetTrackedAssets"] = "get_tracked_assets";
|
|
39
|
+
RPCMethod["IsAssetTracked"] = "is_asset_tracked";
|
|
40
|
+
RPCMethod["TrackAsset"] = "track_asset";
|
|
41
|
+
RPCMethod["UntrackAsset"] = "untrack_asset";
|
|
39
42
|
RPCMethod["GetAssetPrecision"] = "get_asset_precision";
|
|
40
43
|
RPCMethod["GetAssets"] = "get_assets";
|
|
41
44
|
RPCMethod["GetAsset"] = "get_asset";
|
|
@@ -47,17 +50,22 @@ var RPCMethod;
|
|
|
47
50
|
RPCMethod["BuildUnsignedTransaction"] = "build_unsigned_transaction";
|
|
48
51
|
RPCMethod["FinalizeUnsignedTransaction"] = "finalize_unsigned_transaction";
|
|
49
52
|
RPCMethod["SignUnsignedTransaction"] = "sign_unsigned_transaction";
|
|
53
|
+
RPCMethod["GetPendingTransactions"] = "get_pending_transactions";
|
|
50
54
|
RPCMethod["ClearTxCache"] = "clear_tx_cache";
|
|
51
55
|
RPCMethod["ListTransactions"] = "list_transactions";
|
|
52
56
|
RPCMethod["IsOnline"] = "is_online";
|
|
53
57
|
RPCMethod["SetOnlineMode"] = "set_online_mode";
|
|
54
58
|
RPCMethod["SetOfflineMode"] = "set_offline_mode";
|
|
55
59
|
RPCMethod["SignData"] = "sign_data";
|
|
60
|
+
RPCMethod["VerifySignedData"] = "verify_signed_data";
|
|
56
61
|
RPCMethod["EstimateFees"] = "estimate_fees";
|
|
57
62
|
RPCMethod["EstimateExtraDataSize"] = "estimate_extra_data_size";
|
|
58
63
|
RPCMethod["NetworkInfo"] = "network_info";
|
|
59
64
|
RPCMethod["DecryptExtraData"] = "decrypt_extra_data";
|
|
60
65
|
RPCMethod["DecryptCiphertext"] = "decrypt_ciphertext";
|
|
66
|
+
RPCMethod["CreateOwnershipProof"] = "create_ownership_proof";
|
|
67
|
+
RPCMethod["CreateBalanceProof"] = "create_balance_proof";
|
|
68
|
+
RPCMethod["VerifyHumanReadableProof"] = "verify_human_readable_proof";
|
|
61
69
|
RPCMethod["GetMatchingKeys"] = "get_matching_keys";
|
|
62
70
|
RPCMethod["CountMatchingEntries"] = "count_matching_entries";
|
|
63
71
|
RPCMethod["GetValueFromKey"] = "get_value_from_key";
|
|
@@ -69,9 +77,10 @@ var RPCMethod;
|
|
|
69
77
|
})(RPCMethod = exports.RPCMethod || (exports.RPCMethod = {}));
|
|
70
78
|
var RPCEvent;
|
|
71
79
|
(function (RPCEvent) {
|
|
72
|
-
RPCEvent["NewTopoheight"] = "
|
|
80
|
+
RPCEvent["NewTopoheight"] = "new_topo_height";
|
|
73
81
|
RPCEvent["NewAsset"] = "new_asset";
|
|
74
82
|
RPCEvent["NewTransaction"] = "new_transaction";
|
|
83
|
+
RPCEvent["NewPendingTransaction"] = "new_pending_transaction";
|
|
75
84
|
RPCEvent["BalanceChanged"] = "balance_changed";
|
|
76
85
|
RPCEvent["Rescan"] = "rescan";
|
|
77
86
|
RPCEvent["HistorySynced"] = "history_synced";
|
|
@@ -53,6 +53,15 @@ class WalletMethods {
|
|
|
53
53
|
getTrackedAssets() {
|
|
54
54
|
return this.dataCall(types_1.RPCMethod.GetTrackedAssets);
|
|
55
55
|
}
|
|
56
|
+
isAssetTracked(asset) {
|
|
57
|
+
return this.dataCall(types_1.RPCMethod.IsAssetTracked, { asset });
|
|
58
|
+
}
|
|
59
|
+
trackAsset(params) {
|
|
60
|
+
return this.dataCall(types_1.RPCMethod.TrackAsset, params);
|
|
61
|
+
}
|
|
62
|
+
untrackAsset(params) {
|
|
63
|
+
return this.dataCall(types_1.RPCMethod.UntrackAsset, params);
|
|
64
|
+
}
|
|
56
65
|
getAssetPrecision(params) {
|
|
57
66
|
return this.dataCall(types_1.RPCMethod.GetAssetPrecision, params);
|
|
58
67
|
}
|
|
@@ -86,17 +95,20 @@ class WalletMethods {
|
|
|
86
95
|
finalizeUnsignedTransaction(params) {
|
|
87
96
|
return this.dataCall(types_1.RPCMethod.FinalizeUnsignedTransaction, params);
|
|
88
97
|
}
|
|
98
|
+
getPendingTransactions() {
|
|
99
|
+
return this.dataCall(types_1.RPCMethod.GetPendingTransactions);
|
|
100
|
+
}
|
|
89
101
|
clearTxCache() {
|
|
90
102
|
return this.dataCall(types_1.RPCMethod.ClearTxCache);
|
|
91
103
|
}
|
|
92
104
|
listTransactions(params) {
|
|
93
|
-
return this.dataCall(types_1.RPCMethod.
|
|
105
|
+
return this.dataCall(types_1.RPCMethod.ListTransactions, params);
|
|
94
106
|
}
|
|
95
107
|
isOnline() {
|
|
96
108
|
return this.dataCall(types_1.RPCMethod.IsOnline);
|
|
97
109
|
}
|
|
98
110
|
setOnlineMode(params) {
|
|
99
|
-
return this.dataCall(types_1.RPCMethod.
|
|
111
|
+
return this.dataCall(types_1.RPCMethod.SetOnlineMode, params);
|
|
100
112
|
}
|
|
101
113
|
setOfflineMode() {
|
|
102
114
|
return this.dataCall(types_1.RPCMethod.SetOfflineMode);
|
|
@@ -104,6 +116,9 @@ class WalletMethods {
|
|
|
104
116
|
signData(data) {
|
|
105
117
|
return this.dataCall(types_1.RPCMethod.SignData, data.toObject());
|
|
106
118
|
}
|
|
119
|
+
verifySignedData(params) {
|
|
120
|
+
return this.dataCall(types_1.RPCMethod.VerifySignedData, params);
|
|
121
|
+
}
|
|
107
122
|
estimateFees(params) {
|
|
108
123
|
return this.dataCall(types_1.RPCMethod.EstimateFees, params);
|
|
109
124
|
}
|
|
@@ -119,6 +134,15 @@ class WalletMethods {
|
|
|
119
134
|
decryptCiphertext(params) {
|
|
120
135
|
return this.dataCall(types_1.RPCMethod.DecryptCiphertext, params);
|
|
121
136
|
}
|
|
137
|
+
createOwnershipProof(params) {
|
|
138
|
+
return this.dataCall(types_1.RPCMethod.CreateOwnershipProof, params);
|
|
139
|
+
}
|
|
140
|
+
createBalanceProof(params) {
|
|
141
|
+
return this.dataCall(types_1.RPCMethod.CreateBalanceProof, params);
|
|
142
|
+
}
|
|
143
|
+
verifyHumanReadableProof(params) {
|
|
144
|
+
return this.dataCall(types_1.RPCMethod.VerifyHumanReadableProof, params);
|
|
145
|
+
}
|
|
122
146
|
getMatchingKeys(params) {
|
|
123
147
|
return this.dataCall(types_1.RPCMethod.GetMatchingKeys, params);
|
|
124
148
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const await_to_js_1 = require("await-to-js");
|
|
7
|
+
const config_1 = require("../config");
|
|
8
|
+
const websocket_1 = __importDefault(require("./websocket"));
|
|
9
|
+
describe('WalletWS', () => {
|
|
10
|
+
test('getAddress', async () => {
|
|
11
|
+
const walletWS = new websocket_1.default(config_1.LOCAL_WALLET_WS, `test`, `test`);
|
|
12
|
+
walletWS.socket.addEventListener(`open`, async () => {
|
|
13
|
+
const [err2, res] = await (0, await_to_js_1.to)(walletWS.methods.getAddress());
|
|
14
|
+
expect(err2).toBeNull();
|
|
15
|
+
console.log(res);
|
|
16
|
+
expect(res);
|
|
17
|
+
walletWS.socket.close();
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
});
|