@xelis/sdk 0.7.0 → 0.8.0
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/create_esm_pkg.js +13 -0
- package/dist/cjs/config.js +38 -0
- package/dist/cjs/daemon/rpc.js +143 -0
- package/dist/cjs/daemon/types.js +74 -0
- package/dist/cjs/daemon/websocket.js +236 -0
- package/dist/cjs/lib/rpc.js +89 -0
- package/dist/cjs/lib/types.js +2 -0
- package/dist/cjs/lib/websocket.js +283 -0
- package/dist/cjs/react/daemon.js +176 -0
- package/dist/cjs/wallet/rpc.js +131 -0
- package/dist/cjs/wallet/types.js +29 -0
- package/dist/cjs/wallet/websocket.js +92 -0
- package/dist/cjs/xswd/types.js +9 -0
- package/dist/cjs/xswd/websocket.js +38 -0
- package/dist/esm/config.js +35 -0
- package/dist/esm/daemon/rpc.js +140 -0
- package/dist/esm/daemon/websocket.js +233 -0
- package/dist/esm/lib/rpc.js +86 -0
- package/dist/esm/lib/websocket.js +277 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/react/daemon.js +144 -0
- package/dist/esm/wallet/rpc.js +128 -0
- package/dist/esm/wallet/websocket.js +89 -0
- package/dist/esm/xswd/websocket.js +35 -0
- package/jest.config.js +6 -0
- package/package.json +12 -3
- package/tsconfig.cjs.json +7 -0
- package/tsconfig.esm.json +7 -0
- package/tsconfig.json +17 -0
- package/tsconfig.types.json +8 -0
- package/config.js +0 -25
- package/daemon/rpc.js +0 -119
- package/daemon/websocket.js +0 -171
- package/lib/rpc.js +0 -38
- package/lib/websocket.js +0 -202
- package/react/daemon.js +0 -82
- package/wallet/rpc.js +0 -67
- package/wallet/websocket.js +0 -66
- package/xswd/websocket.js +0 -16
- /package/{daemon → dist/esm/daemon}/types.js +0 -0
- /package/{lib → dist/esm/lib}/types.js +0 -0
- /package/{wallet → dist/esm/wallet}/types.js +0 -0
- /package/{xswd → dist/esm/xswd}/types.js +0 -0
- /package/{config.d.ts → dist/types/config.d.ts} +0 -0
- /package/{daemon → dist/types/daemon}/rpc.d.ts +0 -0
- /package/{daemon → dist/types/daemon}/types.d.ts +0 -0
- /package/{daemon → dist/types/daemon}/websocket.d.ts +0 -0
- /package/{lib → dist/types/lib}/rpc.d.ts +0 -0
- /package/{lib → dist/types/lib}/types.d.ts +0 -0
- /package/{lib → dist/types/lib}/websocket.d.ts +0 -0
- /package/{react → dist/types/react}/daemon.d.ts +0 -0
- /package/{wallet → dist/types/wallet}/rpc.d.ts +0 -0
- /package/{wallet → dist/types/wallet}/types.d.ts +0 -0
- /package/{wallet → dist/types/wallet}/websocket.d.ts +0 -0
- /package/{xswd → dist/types/xswd}/types.d.ts +0 -0
- /package/{xswd → dist/types/xswd}/websocket.d.ts +0 -0
package/react/daemon.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import React, { createContext, useContext, useEffect, useState } from 'react';
|
|
2
|
-
import to from 'await-to-js';
|
|
3
|
-
import DaemonWS from '../daemon/websocket';
|
|
4
|
-
export const INITIATING = -1;
|
|
5
|
-
const daemon = new DaemonWS();
|
|
6
|
-
const Context = createContext({
|
|
7
|
-
err: undefined,
|
|
8
|
-
daemon,
|
|
9
|
-
readyState: INITIATING
|
|
10
|
-
});
|
|
11
|
-
export const NodeSocketProvider = (props) => {
|
|
12
|
-
const { children, endpoint, timeout } = props;
|
|
13
|
-
const [readyState, setReadyState] = useState(INITIATING);
|
|
14
|
-
const [err, setErr] = useState();
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
const connect = async () => {
|
|
17
|
-
setErr(undefined);
|
|
18
|
-
const [err, _] = await to(daemon.connect(endpoint));
|
|
19
|
-
if (err)
|
|
20
|
-
setErr(err);
|
|
21
|
-
};
|
|
22
|
-
connect();
|
|
23
|
-
}, [endpoint]);
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
if (!timeout)
|
|
26
|
-
return;
|
|
27
|
-
daemon.timeout = timeout;
|
|
28
|
-
}, [timeout]);
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
if (!daemon.socket)
|
|
31
|
-
return;
|
|
32
|
-
setReadyState(daemon.socket.readyState);
|
|
33
|
-
const onOpen = () => {
|
|
34
|
-
if (!daemon.socket)
|
|
35
|
-
return;
|
|
36
|
-
setReadyState(daemon.socket.readyState);
|
|
37
|
-
setErr(undefined);
|
|
38
|
-
};
|
|
39
|
-
const onClose = (event) => {
|
|
40
|
-
if (!daemon.socket)
|
|
41
|
-
return;
|
|
42
|
-
setReadyState(daemon.socket.readyState);
|
|
43
|
-
setErr(new Error(event.reason));
|
|
44
|
-
};
|
|
45
|
-
const onError = (err) => {
|
|
46
|
-
if (!daemon.socket)
|
|
47
|
-
return;
|
|
48
|
-
setReadyState(daemon.socket.readyState);
|
|
49
|
-
setErr(new Error(err.message));
|
|
50
|
-
};
|
|
51
|
-
daemon.socket.addEventListener(`open`, onOpen);
|
|
52
|
-
daemon.socket.addEventListener(`close`, onClose);
|
|
53
|
-
daemon.socket.addEventListener(`error`, onError);
|
|
54
|
-
return () => {
|
|
55
|
-
if (!daemon.socket)
|
|
56
|
-
return;
|
|
57
|
-
daemon.socket.removeEventListener(`open`, onOpen);
|
|
58
|
-
daemon.socket.removeEventListener(`close`, onClose);
|
|
59
|
-
daemon.socket.removeEventListener(`error`, onError);
|
|
60
|
-
};
|
|
61
|
-
}, [daemon.socket]);
|
|
62
|
-
return React.createElement(Context.Provider, { value: { daemon, err, readyState } }, children);
|
|
63
|
-
};
|
|
64
|
-
export const useNodeSocketSubscribe = ({ event, onLoad, onData }, dependencies) => {
|
|
65
|
-
const nodeSocket = useNodeSocket();
|
|
66
|
-
useEffect(() => {
|
|
67
|
-
if (nodeSocket.readyState !== WebSocket.OPEN)
|
|
68
|
-
return;
|
|
69
|
-
if (typeof onLoad === `function`)
|
|
70
|
-
onLoad();
|
|
71
|
-
let closeEvent;
|
|
72
|
-
const listen = async () => {
|
|
73
|
-
closeEvent = await nodeSocket.daemon.listenEvent(event, onData);
|
|
74
|
-
};
|
|
75
|
-
listen();
|
|
76
|
-
return () => {
|
|
77
|
-
closeEvent && closeEvent();
|
|
78
|
-
};
|
|
79
|
-
}, [nodeSocket, ...dependencies]);
|
|
80
|
-
};
|
|
81
|
-
export const useNodeSocket = () => useContext(Context);
|
|
82
|
-
export default useNodeSocket;
|
package/wallet/rpc.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { Base64 } from 'js-base64';
|
|
2
|
-
import { RPCMethod } from './types';
|
|
3
|
-
import { RPC as BaseRPC } from '../lib/rpc';
|
|
4
|
-
export class RPC extends BaseRPC {
|
|
5
|
-
constructor(endpoint, username, password) {
|
|
6
|
-
super(endpoint);
|
|
7
|
-
const authValue = Base64.encode(`${username}:${password}`);
|
|
8
|
-
this.auth = `Basic ${authValue}`;
|
|
9
|
-
}
|
|
10
|
-
async post(method, params) {
|
|
11
|
-
const headers = new Headers();
|
|
12
|
-
headers.set(`Authorization`, this.auth);
|
|
13
|
-
return super.post(method, params, headers);
|
|
14
|
-
}
|
|
15
|
-
getVersion() {
|
|
16
|
-
return this.post(RPCMethod.GetVersion);
|
|
17
|
-
}
|
|
18
|
-
getNetwork() {
|
|
19
|
-
return this.post(RPCMethod.GetNetwork);
|
|
20
|
-
}
|
|
21
|
-
getNonce() {
|
|
22
|
-
return this.post(RPCMethod.GetNonce);
|
|
23
|
-
}
|
|
24
|
-
getTopoheight() {
|
|
25
|
-
return this.post(RPCMethod.GetTopoheight);
|
|
26
|
-
}
|
|
27
|
-
getAddress(params = {}) {
|
|
28
|
-
return this.post(RPCMethod.GetAddress, params);
|
|
29
|
-
}
|
|
30
|
-
splitAddress(params) {
|
|
31
|
-
return this.post(RPCMethod.SplitAddress, params);
|
|
32
|
-
}
|
|
33
|
-
rescan() {
|
|
34
|
-
return this.post(RPCMethod.Rescan);
|
|
35
|
-
}
|
|
36
|
-
getBalance(asset) {
|
|
37
|
-
return this.post(RPCMethod.GetBalance, { asset });
|
|
38
|
-
}
|
|
39
|
-
hasBalance(asset) {
|
|
40
|
-
return this.post(RPCMethod.HasBalance, { asset });
|
|
41
|
-
}
|
|
42
|
-
getTrackedAssets() {
|
|
43
|
-
return this.post(RPCMethod.GetTrackedAssets);
|
|
44
|
-
}
|
|
45
|
-
getAssetPrecision(params) {
|
|
46
|
-
return this.post(RPCMethod.GetAssetPrecision, params);
|
|
47
|
-
}
|
|
48
|
-
getTransaction(hash) {
|
|
49
|
-
return this.post(RPCMethod.GetTransaction, { hash });
|
|
50
|
-
}
|
|
51
|
-
buildTransaction(params) {
|
|
52
|
-
return this.post(RPCMethod.BuildTransaction, params);
|
|
53
|
-
}
|
|
54
|
-
listTransactions(params) {
|
|
55
|
-
return this.post(RPCMethod.ListTransactions, params);
|
|
56
|
-
}
|
|
57
|
-
isOnline() {
|
|
58
|
-
return this.post(RPCMethod.IsOnline);
|
|
59
|
-
}
|
|
60
|
-
signData(data) {
|
|
61
|
-
return this.post(RPCMethod.SignData, data);
|
|
62
|
-
}
|
|
63
|
-
estimateFees(txData) {
|
|
64
|
-
return this.post(RPCMethod.EstimateFees, { tx_type: txData });
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
export default RPC;
|
package/wallet/websocket.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { WS as BaseWS } from '../lib/websocket';
|
|
2
|
-
import { RPCMethod } from './types';
|
|
3
|
-
export class WalletMethods {
|
|
4
|
-
constructor(ws, prefix = "") {
|
|
5
|
-
this.ws = ws;
|
|
6
|
-
this.prefix = prefix;
|
|
7
|
-
}
|
|
8
|
-
dataCall(method, params) {
|
|
9
|
-
return this.ws.dataCall(this.prefix + method, params);
|
|
10
|
-
}
|
|
11
|
-
getVersion() {
|
|
12
|
-
return this.dataCall(RPCMethod.GetVersion);
|
|
13
|
-
}
|
|
14
|
-
getNetwork() {
|
|
15
|
-
return this.dataCall(RPCMethod.GetNetwork);
|
|
16
|
-
}
|
|
17
|
-
getNonce() {
|
|
18
|
-
return this.dataCall(RPCMethod.GetNonce);
|
|
19
|
-
}
|
|
20
|
-
getTopoheight() {
|
|
21
|
-
return this.dataCall(RPCMethod.GetTopoheight);
|
|
22
|
-
}
|
|
23
|
-
getAddress(params = {}) {
|
|
24
|
-
return this.dataCall(RPCMethod.GetAddress, params);
|
|
25
|
-
}
|
|
26
|
-
splitAddress(params) {
|
|
27
|
-
return this.dataCall(RPCMethod.SplitAddress, params);
|
|
28
|
-
}
|
|
29
|
-
rescan() {
|
|
30
|
-
return this.dataCall(RPCMethod.Rescan);
|
|
31
|
-
}
|
|
32
|
-
getBalance(asset) {
|
|
33
|
-
return this.dataCall(RPCMethod.GetBalance, { asset });
|
|
34
|
-
}
|
|
35
|
-
getTrackedAssets() {
|
|
36
|
-
return this.dataCall(RPCMethod.GetTrackedAssets);
|
|
37
|
-
}
|
|
38
|
-
getAssetPrecision(params) {
|
|
39
|
-
return this.dataCall(RPCMethod.GetAssetPrecision, params);
|
|
40
|
-
}
|
|
41
|
-
getTransaction(hash) {
|
|
42
|
-
return this.dataCall(RPCMethod.GetTransaction, { hash });
|
|
43
|
-
}
|
|
44
|
-
buildTransaction(params) {
|
|
45
|
-
return this.dataCall(RPCMethod.BuildTransaction, params);
|
|
46
|
-
}
|
|
47
|
-
listTransactions(params) {
|
|
48
|
-
return this.dataCall(RPCMethod.GetTransaction, params);
|
|
49
|
-
}
|
|
50
|
-
isOnline() {
|
|
51
|
-
return this.dataCall(RPCMethod.IsOnline);
|
|
52
|
-
}
|
|
53
|
-
signData(data) {
|
|
54
|
-
return this.dataCall(RPCMethod.SignData, data);
|
|
55
|
-
}
|
|
56
|
-
estimateFees(txData) {
|
|
57
|
-
return this.dataCall(RPCMethod.EstimateFees, { tx_type: txData });
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
export class WS extends BaseWS {
|
|
61
|
-
constructor(username, password) {
|
|
62
|
-
super({ auth: `${username}:${password}` });
|
|
63
|
-
this.methods = new WalletMethods(this);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
export default WS;
|
package/xswd/websocket.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { WS as BaseWS } from '../lib/websocket';
|
|
2
|
-
import { DaemonMethods } from '../daemon/websocket';
|
|
3
|
-
import { WalletMethods } from '../wallet/websocket';
|
|
4
|
-
export class WS extends BaseWS {
|
|
5
|
-
constructor() {
|
|
6
|
-
super();
|
|
7
|
-
this.timeout = 0;
|
|
8
|
-
this.daemon = new DaemonMethods(this, "node.");
|
|
9
|
-
this.wallet = new WalletMethods(this, "wallet.");
|
|
10
|
-
}
|
|
11
|
-
authorize(app) {
|
|
12
|
-
const data = JSON.stringify(app);
|
|
13
|
-
return this.call("", {}, data);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export default WS;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|