@dashevo/dapi-client 4.2.0-dev.1 → 4.2.0-dev.11
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.
|
@@ -5,14 +5,32 @@ const TimeStatus = require('./TimeStatus');
|
|
|
5
5
|
const StateSyncStatus = require('./StateSyncStatus');
|
|
6
6
|
const NetworkStatus = require('./NetworkStatus');
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Read a value out of an optional protobuf sub-message.
|
|
10
|
+
*
|
|
11
|
+
* Every message-typed field in `GetStatusResponseV0` is optional on the wire, and DAPI
|
|
12
|
+
* omits whole sections when the underlying data is unavailable: `state_sync` is absent
|
|
13
|
+
* unless the node is state syncing, `chain`/`node`/`network` are absent when Tenderdash
|
|
14
|
+
* is unreachable, and `protocol.drive` is absent when Drive is unreachable. The generated
|
|
15
|
+
* getters return `undefined` for an absent sub-message, so they must never be chained
|
|
16
|
+
* without a guard.
|
|
17
|
+
*
|
|
18
|
+
* @param {object|undefined} message - protobuf sub-message, possibly absent
|
|
19
|
+
* @param {function(object): *} read - reader invoked when the sub-message is present
|
|
20
|
+
* @returns {*} the read value, or `undefined` when the sub-message is absent
|
|
21
|
+
*/
|
|
22
|
+
function readOptional(message, read) {
|
|
23
|
+
return message ? read(message) : undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
8
26
|
class GetStatusResponse {
|
|
9
27
|
/**
|
|
10
28
|
* @param {VersionStatus} version - status versions
|
|
11
|
-
* @param {NodeStatus} node - node status
|
|
12
|
-
* @param {ChainStatus} chain - chain status
|
|
13
|
-
* @param {NetworkStatus} network - network status
|
|
14
|
-
* @param {StateSyncStatus} stateSync - state sync status
|
|
15
|
-
* @param {TimeStatus} time - time status
|
|
29
|
+
* @param {NodeStatus|null} node - node status, null if unavailable
|
|
30
|
+
* @param {ChainStatus|null} chain - chain status, null if unavailable
|
|
31
|
+
* @param {NetworkStatus|null} network - network status, null if unavailable
|
|
32
|
+
* @param {StateSyncStatus|null} stateSync - state sync status, null if not state syncing
|
|
33
|
+
* @param {TimeStatus|null} time - time status, null if unavailable
|
|
16
34
|
*/
|
|
17
35
|
constructor(version, node, chain, network, stateSync, time) {
|
|
18
36
|
this.version = version;
|
|
@@ -31,35 +49,35 @@ class GetStatusResponse {
|
|
|
31
49
|
}
|
|
32
50
|
|
|
33
51
|
/**
|
|
34
|
-
* @returns {NodeStatus} node info status
|
|
52
|
+
* @returns {NodeStatus|null} node info status, null if unavailable
|
|
35
53
|
*/
|
|
36
54
|
getNodeStatus() {
|
|
37
55
|
return this.node;
|
|
38
56
|
}
|
|
39
57
|
|
|
40
58
|
/**
|
|
41
|
-
* @returns {ChainStatus} chain status
|
|
59
|
+
* @returns {ChainStatus|null} chain status, null if unavailable
|
|
42
60
|
*/
|
|
43
61
|
getChainStatus() {
|
|
44
62
|
return this.chain;
|
|
45
63
|
}
|
|
46
64
|
|
|
47
65
|
/**
|
|
48
|
-
* @returns {NetworkStatus} network status
|
|
66
|
+
* @returns {NetworkStatus|null} network status, null if unavailable
|
|
49
67
|
*/
|
|
50
68
|
getNetworkStatus() {
|
|
51
69
|
return this.network;
|
|
52
70
|
}
|
|
53
71
|
|
|
54
72
|
/**
|
|
55
|
-
* @returns {StateSyncStatus} state sync status
|
|
73
|
+
* @returns {StateSyncStatus|null} state sync status, null if not state syncing
|
|
56
74
|
*/
|
|
57
75
|
getStateSyncStatus() {
|
|
58
76
|
return this.stateSync;
|
|
59
77
|
}
|
|
60
78
|
|
|
61
79
|
/**
|
|
62
|
-
* @returns {TimeStatus} time status
|
|
80
|
+
* @returns {TimeStatus|null} time status, null if unavailable
|
|
63
81
|
*/
|
|
64
82
|
getTimeStatus() {
|
|
65
83
|
return this.time;
|
|
@@ -72,85 +90,75 @@ class GetStatusResponse {
|
|
|
72
90
|
static createFromProto(proto) {
|
|
73
91
|
const v0 = proto.getV0();
|
|
74
92
|
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
const driveCurrentProtocol = v0.getVersion().getProtocol().getDrive().getCurrent();
|
|
81
|
-
const driveLatestProtocol = v0.getVersion().getProtocol().getDrive().getLatest();
|
|
82
|
-
const driveNextEpochProtocol = v0.getVersion().getProtocol().getDrive().getNextEpoch();
|
|
93
|
+
const versionProto = v0.getVersion();
|
|
94
|
+
const softwareProto = readOptional(versionProto, (v) => v.getSoftware());
|
|
95
|
+
const protocolProto = readOptional(versionProto, (v) => v.getProtocol());
|
|
96
|
+
const tenderdashProtocolProto = readOptional(protocolProto, (p) => p.getTenderdash());
|
|
97
|
+
const driveProtocolProto = readOptional(protocolProto, (p) => p.getDrive());
|
|
83
98
|
|
|
84
99
|
const version = new VersionStatus(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
const nodeId = Buffer.from(v0.getNode().getId()).toString('hex');
|
|
96
|
-
const proTxHash = Buffer.from(v0.getNode().getProTxHash()).toString('hex');
|
|
97
|
-
|
|
98
|
-
const node = new NodeStatus(nodeId, proTxHash);
|
|
99
|
-
|
|
100
|
-
const catchingUp = v0.getChain().getCatchingUp();
|
|
101
|
-
const latestBlockHash = Buffer.from(v0.getChain().getLatestBlockHash()).toString('hex');
|
|
102
|
-
const latestAppHash = Buffer.from(v0.getChain().getLatestAppHash()).toString('hex');
|
|
103
|
-
const latestBlockHeight = BigInt(v0.getChain().getLatestBlockHeight());
|
|
104
|
-
const earliestBlockHash = Buffer.from(v0.getChain().getEarliestBlockHash()).toString('hex');
|
|
105
|
-
const earliestAppHash = Buffer.from(v0.getChain().getEarliestAppHash()).toString('hex');
|
|
106
|
-
const earliestBlockHeight = BigInt(v0.getChain().getEarliestBlockHeight());
|
|
107
|
-
const maxPeerBlockHeight = BigInt(v0.getChain().getMaxPeerBlockHeight());
|
|
108
|
-
const coreChainLockedHeight = v0.getChain().getCoreChainLockedHeight();
|
|
109
|
-
|
|
110
|
-
const chain = new ChainStatus(
|
|
111
|
-
catchingUp,
|
|
112
|
-
latestBlockHash,
|
|
113
|
-
latestAppHash,
|
|
114
|
-
latestBlockHeight,
|
|
115
|
-
earliestBlockHash,
|
|
116
|
-
earliestAppHash,
|
|
117
|
-
earliestBlockHeight,
|
|
118
|
-
maxPeerBlockHeight,
|
|
119
|
-
coreChainLockedHeight,
|
|
100
|
+
readOptional(softwareProto, (s) => s.getDapi()),
|
|
101
|
+
readOptional(softwareProto, (s) => s.getDrive()),
|
|
102
|
+
readOptional(softwareProto, (s) => s.getTenderdash()),
|
|
103
|
+
readOptional(tenderdashProtocolProto, (t) => t.getP2p()),
|
|
104
|
+
readOptional(tenderdashProtocolProto, (t) => t.getBlock()),
|
|
105
|
+
readOptional(driveProtocolProto, (d) => d.getCurrent()),
|
|
106
|
+
readOptional(driveProtocolProto, (d) => d.getLatest()),
|
|
107
|
+
readOptional(driveProtocolProto, (d) => d.getNextEpoch()),
|
|
120
108
|
);
|
|
121
109
|
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const
|
|
110
|
+
const nodeProto = v0.getNode();
|
|
111
|
+
|
|
112
|
+
const node = nodeProto ? new NodeStatus(
|
|
113
|
+
Buffer.from(nodeProto.getId()).toString('hex'),
|
|
114
|
+
Buffer.from(nodeProto.getProTxHash()).toString('hex'),
|
|
115
|
+
) : null;
|
|
116
|
+
|
|
117
|
+
const chainProto = v0.getChain();
|
|
118
|
+
|
|
119
|
+
const chain = chainProto ? new ChainStatus(
|
|
120
|
+
chainProto.getCatchingUp(),
|
|
121
|
+
Buffer.from(chainProto.getLatestBlockHash()).toString('hex'),
|
|
122
|
+
Buffer.from(chainProto.getLatestAppHash()).toString('hex'),
|
|
123
|
+
BigInt(chainProto.getLatestBlockHeight()),
|
|
124
|
+
Buffer.from(chainProto.getEarliestBlockHash()).toString('hex'),
|
|
125
|
+
Buffer.from(chainProto.getEarliestAppHash()).toString('hex'),
|
|
126
|
+
BigInt(chainProto.getEarliestBlockHeight()),
|
|
127
|
+
BigInt(chainProto.getMaxPeerBlockHeight()),
|
|
128
|
+
chainProto.getCoreChainLockedHeight(),
|
|
129
|
+
) : null;
|
|
130
|
+
|
|
131
|
+
const networkProto = v0.getNetwork();
|
|
132
|
+
|
|
133
|
+
const network = networkProto ? new NetworkStatus(
|
|
134
|
+
networkProto.getChainId(),
|
|
135
|
+
networkProto.getPeersCount(),
|
|
136
|
+
networkProto.getListening(),
|
|
137
|
+
) : null;
|
|
138
|
+
|
|
139
|
+
// DAPI omits the whole state sync section on nodes that are not state syncing,
|
|
140
|
+
// so an absent section means "no state sync information", not "all zeroes".
|
|
141
|
+
const stateSyncProto = v0.getStateSync();
|
|
142
|
+
|
|
143
|
+
const stateSync = stateSyncProto ? new StateSyncStatus(
|
|
144
|
+
BigInt(stateSyncProto.getTotalSyncedTime()),
|
|
145
|
+
BigInt(stateSyncProto.getRemainingTime()),
|
|
146
|
+
stateSyncProto.getTotalSnapshots(),
|
|
147
|
+
BigInt(stateSyncProto.getChunkProcessAvgTime()),
|
|
148
|
+
BigInt(stateSyncProto.getSnapshotHeight()),
|
|
149
|
+
BigInt(stateSyncProto.getSnapshotChunksCount()),
|
|
150
|
+
BigInt(stateSyncProto.getBackfilledBlocks()),
|
|
151
|
+
BigInt(stateSyncProto.getBackfillBlocksTotal()),
|
|
152
|
+
) : null;
|
|
153
|
+
|
|
154
|
+
const timeProto = v0.getTime();
|
|
155
|
+
|
|
156
|
+
const time = timeProto ? new TimeStatus(
|
|
157
|
+
BigInt(timeProto.getLocal()),
|
|
158
|
+
BigInt(timeProto.getBlock()),
|
|
159
|
+
BigInt(timeProto.getGenesis()),
|
|
160
|
+
timeProto.getEpoch(),
|
|
161
|
+
) : null;
|
|
154
162
|
|
|
155
163
|
return new GetStatusResponse(
|
|
156
164
|
version,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashevo/dapi-client",
|
|
3
|
-
"version": "4.2.0-dev.
|
|
3
|
+
"version": "4.2.0-dev.11",
|
|
4
4
|
"description": "Client library used to access Dash DAPI endpoints",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"contributors": [
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
}
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@dashevo/dapi-grpc": "4.2.0-dev.
|
|
30
|
-
"@dashevo/dash-spv": "5.2.0-dev.
|
|
29
|
+
"@dashevo/dapi-grpc": "4.2.0-dev.11",
|
|
30
|
+
"@dashevo/dash-spv": "5.2.0-dev.11",
|
|
31
31
|
"@dashevo/dashcore-lib": "~0.22.0",
|
|
32
|
-
"@dashevo/grpc-common": "4.2.0-dev.
|
|
33
|
-
"@dashevo/wasm-dpp": "4.2.0-dev.
|
|
32
|
+
"@dashevo/grpc-common": "4.2.0-dev.11",
|
|
33
|
+
"@dashevo/wasm-dpp": "4.2.0-dev.11",
|
|
34
34
|
"cbor": "^8.0.0",
|
|
35
35
|
"google-protobuf": "^3.12.2",
|
|
36
36
|
"undici": "^6.0.0",
|