@tchain/tcabci-read-js-client 1.3.11 → 1.3.13
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/client.js +11 -4
- package/client_test.js +2 -0
- package/errors.js +2 -0
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const ReconnectingWebSocket = require('reconnecting-websocket/dist/reconnecting-websocket-cjs')
|
|
2
2
|
const {
|
|
3
3
|
NOT_CONNECTED,
|
|
4
|
+
ERR_NETWORK,
|
|
4
5
|
ALREADY_CONNECTED,
|
|
5
6
|
INVALID_ARGUMENTS,
|
|
6
7
|
NOT_SUBSCRIBED,
|
|
@@ -18,7 +19,7 @@ class TCAbciClient {
|
|
|
18
19
|
subscribed = false
|
|
19
20
|
subscribedAddresses = []
|
|
20
21
|
connected = false
|
|
21
|
-
version = "v1.3.
|
|
22
|
+
version = "v1.3.13"
|
|
22
23
|
errorCb = null
|
|
23
24
|
listenCb = null
|
|
24
25
|
ws = null
|
|
@@ -126,17 +127,21 @@ class TCAbciClient {
|
|
|
126
127
|
sender_addrs: senderAddrs,
|
|
127
128
|
typ: typ,
|
|
128
129
|
})
|
|
129
|
-
.then(res => {
|
|
130
|
+
.then((res) => {
|
|
130
131
|
return {
|
|
132
|
+
first_block_height: res.data.data.first_block_height,
|
|
133
|
+
first_transaction: res.data.data.first_transaction,
|
|
131
134
|
last_block_height: res.data.data.last_block_height,
|
|
132
135
|
last_transaction: res.data.data.last_transaction,
|
|
133
136
|
total_count: res.data.total_count,
|
|
134
137
|
}
|
|
135
138
|
})
|
|
136
139
|
.catch(e => {
|
|
137
|
-
switch (e
|
|
140
|
+
switch (e?.response?.status ?? e?.status ?? e?.code) {
|
|
138
141
|
case 400:
|
|
139
142
|
throw INVALID_ARGUMENTS
|
|
143
|
+
case 'ERR_NETWORK':
|
|
144
|
+
throw ERR_NETWORK
|
|
140
145
|
default:
|
|
141
146
|
throw e
|
|
142
147
|
}
|
|
@@ -162,9 +167,11 @@ class TCAbciClient {
|
|
|
162
167
|
}
|
|
163
168
|
})
|
|
164
169
|
.catch(e => {
|
|
165
|
-
switch (e
|
|
170
|
+
switch (e?.response?.status ?? e?.status ?? e?.code) {
|
|
166
171
|
case 400:
|
|
167
172
|
throw INVALID_ARGUMENTS
|
|
173
|
+
case 'ERR_NETWORK':
|
|
174
|
+
throw ERR_NETWORK
|
|
168
175
|
default:
|
|
169
176
|
throw e
|
|
170
177
|
}
|
package/client_test.js
CHANGED
|
@@ -148,6 +148,8 @@ describe("TCAbciClient TESTS", () => {
|
|
|
148
148
|
recipientAddrs: ["2mSCzresfg8Gwu7LZ9k9BTWkQAcQEkvYHFUSCZE2ubM4QV89PTeSYwQDqBas3ykq2emHEK6VRvxdgoe1vrhBbQGN"],
|
|
149
149
|
})
|
|
150
150
|
.then(data => {
|
|
151
|
+
unitJS.value(data.first_block_height).isGreaterThan(0)
|
|
152
|
+
unitJS.value(data.first_transaction).isNotEmpty()
|
|
151
153
|
unitJS.value(data.last_block_height).isGreaterThan(0)
|
|
152
154
|
unitJS.value(data.total_count).isGreaterThan(0)
|
|
153
155
|
unitJS.value(data.last_transaction).isNotEmpty()
|
package/errors.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const ALREADY_CONNECTED = new Error("Already connected"),
|
|
2
2
|
NOT_CONNECTED = new Error("Not connected"),
|
|
3
|
+
ERR_NETWORK = new Error("Network Error"),
|
|
3
4
|
INVALID_ARGUMENTS = new Error("Check your arguments"),
|
|
4
5
|
INVALID_ARGUMENT_WITH_CS = (val) => {
|
|
5
6
|
return new Error(INVALID_ARGUMENTS + " " + val)
|
|
@@ -14,6 +15,7 @@ const ALREADY_CONNECTED = new Error("Already connected"),
|
|
|
14
15
|
module.exports = {
|
|
15
16
|
ALREADY_CONNECTED,
|
|
16
17
|
NOT_CONNECTED,
|
|
18
|
+
ERR_NETWORK,
|
|
17
19
|
INVALID_ARGUMENTS,
|
|
18
20
|
INVALID_ARGUMENT_WITH_CS,
|
|
19
21
|
NOT_SUBSCRIBED,
|