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