@tchain/tcabci-read-js-client 1.0.1 → 1.0.3
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/README.md +3 -1
- package/client.js +24 -2
- package/client_test.js +40 -3
- package/constants.js +25 -1
- package/errors.js +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ Read Node WebSocket Address: [wss://read-node-01.transferchain.io/ws](wss://read
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
9
|
```shell
|
|
10
|
-
$ npm
|
|
10
|
+
$ npm i @tchain/tcabci-read-js-client
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Example
|
|
@@ -15,6 +15,8 @@ $ npm install tcabci-read-js-client
|
|
|
15
15
|
**Subscribe, Listen and Unsubscribe Example**
|
|
16
16
|
|
|
17
17
|
```js
|
|
18
|
+
const tcAbciClient = require("@tchain/tcabci-read-js-client")
|
|
19
|
+
|
|
18
20
|
const client = new tcAbciClient()
|
|
19
21
|
|
|
20
22
|
client.Start()
|
package/client.js
CHANGED
|
@@ -4,9 +4,11 @@ const {
|
|
|
4
4
|
INVALID_ARGUMENTS,
|
|
5
5
|
NOT_SUBSCRIBED,
|
|
6
6
|
ADDRESSES_IS_EMPTY,
|
|
7
|
-
BLOCK_NOT_FOUND
|
|
7
|
+
BLOCK_NOT_FOUND,
|
|
8
|
+
TRANSACTION_TYPE_NOT_VALID,
|
|
9
|
+
TRANSACTION_NOT_BROADCAST
|
|
8
10
|
} = require("./errors")
|
|
9
|
-
const {MESSAGE_TYPE, READ_NODE_ADDRESS, READ_NODE_WS_ADDRESS} = require("./constants")
|
|
11
|
+
const {MESSAGE_TYPE, READ_NODE_ADDRESS, READ_NODE_WS_ADDRESS, TX_TYPE} = require("./constants")
|
|
10
12
|
const Transaction = require("./transaction")
|
|
11
13
|
const Message = require("./message")
|
|
12
14
|
const {toJSON} = require("./util")
|
|
@@ -137,6 +139,26 @@ class TCAbciClient {
|
|
|
137
139
|
subscribed: this.#subscribed,
|
|
138
140
|
}
|
|
139
141
|
}
|
|
142
|
+
Broadcast({id, version, type, data, sender_addr, recipient_addr, sign, fee}) {
|
|
143
|
+
if(Object.values(TX_TYPE).indexOf(type) < 0) {
|
|
144
|
+
throw TRANSACTION_TYPE_NOT_VALID
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return this.#httpClient.post(
|
|
148
|
+
"/v1/broadcast",
|
|
149
|
+
{
|
|
150
|
+
id,
|
|
151
|
+
version,
|
|
152
|
+
type,
|
|
153
|
+
data,
|
|
154
|
+
sender_addr,
|
|
155
|
+
recipient_addr,
|
|
156
|
+
sign,
|
|
157
|
+
fee
|
|
158
|
+
}
|
|
159
|
+
).then(res => { return { data: res.data.data } })
|
|
160
|
+
.catch(e => { throw TRANSACTION_NOT_BROADCAST })
|
|
161
|
+
}
|
|
140
162
|
|
|
141
163
|
#wsClient() {
|
|
142
164
|
if (typeof window !== "undefined") {
|
package/client_test.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const tcAbciClient = require("./client")
|
|
2
2
|
const unitJS = require("unit.js")
|
|
3
|
-
const {INVALID_ARGUMENTS, INVALID_URL} = require("./errors")
|
|
3
|
+
const {INVALID_ARGUMENTS, INVALID_URL, TRANSACTION_TYPE_NOT_VALID} = require("./errors")
|
|
4
|
+
const { TX_TYPE } = require("./constants")
|
|
4
5
|
const {randomString} = require("./util")
|
|
5
6
|
|
|
6
7
|
describe("TCAbciClient TESTS", () => {
|
|
@@ -70,13 +71,13 @@ describe("TCAbciClient TESTS", () => {
|
|
|
70
71
|
|
|
71
72
|
it('should return transaction search result',(done) => {
|
|
72
73
|
const client = new tcAbciClient()
|
|
73
|
-
client.TxSearch({
|
|
74
|
+
client.TxSearch({
|
|
74
75
|
heightOperator: ">=",
|
|
75
76
|
height: 0,
|
|
76
77
|
recipientAddrs: ["2mSCzresfg8Gwu7LZ9k9BTWkQAcQEkvYHFUSCZE2ubM4QV89PTeSYwQDqBas3ykq2emHEK6VRvxdgoe1vrhBbQGN"],
|
|
77
78
|
limit: 1,
|
|
78
79
|
offset: 0,
|
|
79
|
-
orderBy: "ASC"
|
|
80
|
+
orderBy: "ASC"
|
|
80
81
|
})
|
|
81
82
|
.then(data => {
|
|
82
83
|
unitJS.value(data.txs).hasLength(1)
|
|
@@ -88,4 +89,40 @@ describe("TCAbciClient TESTS", () => {
|
|
|
88
89
|
})
|
|
89
90
|
})
|
|
90
91
|
|
|
92
|
+
it('should not broadcast transaction if type is incorrect',(done) => {
|
|
93
|
+
const client = new tcAbciClient()
|
|
94
|
+
try {
|
|
95
|
+
client.Broadcast({
|
|
96
|
+
type: "dummy type",
|
|
97
|
+
data: "",
|
|
98
|
+
sender_addr: "",
|
|
99
|
+
recipient_addr: ""
|
|
100
|
+
})
|
|
101
|
+
} catch (err) {
|
|
102
|
+
unitJS.assert.equal(TRANSACTION_TYPE_NOT_VALID, err)
|
|
103
|
+
done()
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it('should not broadcast transaction',(done) => {
|
|
108
|
+
const client = new tcAbciClient()
|
|
109
|
+
client.Broadcast({
|
|
110
|
+
id: "dummy id",
|
|
111
|
+
version: 0,
|
|
112
|
+
type: TX_TYPE.TX_TYPE_ADDRESS,
|
|
113
|
+
data: btoa(JSON.stringify({data: ""})),
|
|
114
|
+
sender_addr: "2mSCzresfg8Gwu7LZ9k9BTWkQAcQEkvYHFUSCZE2ubM4QV89PTeSYwQDqBas3ykq2emHEK6VRvxdgoe1vrhBbQGN",
|
|
115
|
+
recipient_addr: "2mSCzresfg8Gwu7LZ9k9BTWkQAcQEkvYHFUSCZE2ubM4QV89PTeSYwQDqBas3ykq2emHEK6VRvxdgoe1vrhBbQGN",
|
|
116
|
+
sign: btoa("dummy sign"),
|
|
117
|
+
fee: 0
|
|
118
|
+
})
|
|
119
|
+
.then(data => {
|
|
120
|
+
unitJS.assert.notEqual(data.data.hash, "")
|
|
121
|
+
done()
|
|
122
|
+
})
|
|
123
|
+
.catch(err => {
|
|
124
|
+
done(err)
|
|
125
|
+
})
|
|
126
|
+
})
|
|
127
|
+
|
|
91
128
|
})
|
package/constants.js
CHANGED
|
@@ -5,5 +5,29 @@ module.exports = {
|
|
|
5
5
|
},
|
|
6
6
|
CHARACTERS: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
|
7
7
|
READ_NODE_ADDRESS: "https://read-node-01.transferchain.io",
|
|
8
|
-
READ_NODE_WS_ADDRESS: "wss://read-node-01.transferchain.io/ws"
|
|
8
|
+
READ_NODE_WS_ADDRESS: "wss://read-node-01.transferchain.io/ws",
|
|
9
|
+
TX_TYPE: {
|
|
10
|
+
TX_TYPE_MASTER: "initial_storage",
|
|
11
|
+
TX_TYPE_ADDRESS: "interim_storage",
|
|
12
|
+
TX_TYPE_ADDRESSES: "interim_storages",
|
|
13
|
+
TX_TYPE_MESSAGE: "message",
|
|
14
|
+
TX_TYPE_MESSAGE_SENT: "inherit_message",
|
|
15
|
+
TX_TYPE_MESSAGE_THREAD_DELETE: "inherit_message_recv",
|
|
16
|
+
TX_TYPE_TRANSFER: "transfer",
|
|
17
|
+
TX_TYPE_TRANSFER_CANCEL: "transfer_Cancel",
|
|
18
|
+
TX_TYPE_TRANSFER_SENT: "transfer_sent",
|
|
19
|
+
TX_TYPE_TRANSFER_RECEIVE_DELETE: "transfer_receive_delete",
|
|
20
|
+
TX_TYPE_STORAGE: "storage",
|
|
21
|
+
TX_TYPE_STORAGE_DELETE: "storage_delete",
|
|
22
|
+
TX_TYPE_BACKUP: "backup",
|
|
23
|
+
TX_TYPE_CONTACT: "interim_message",
|
|
24
|
+
TX_TYPE_FILE_VIRTUAL: "fs_virt",
|
|
25
|
+
TX_TYPE_FILE_FS: "fs_real",
|
|
26
|
+
TX_TYPE_RFILE_VIRTUAL: "fs_rvirt",
|
|
27
|
+
TX_TYPE_RFILE_FS: "fs_rreal",
|
|
28
|
+
TX_TYPE_REQUEST: "request",
|
|
29
|
+
TX_TYPE_REQUEST_IN: "request_in",
|
|
30
|
+
TX_TYPE_REQUEST_UPLOAD: "request_upload",
|
|
31
|
+
TX_TYPE_REQUEST_CANCEL: "request_Cancel"
|
|
32
|
+
}
|
|
9
33
|
}
|
package/errors.js
CHANGED
|
@@ -8,5 +8,7 @@ module.exports = {
|
|
|
8
8
|
NOT_SUBSCRIBED: new Error("Not subscribed"),
|
|
9
9
|
ALREADY_SUBSCRIBED: new Error("Already subscribed"),
|
|
10
10
|
ADDRESSES_IS_EMPTY: new Error("Addresses is empty"),
|
|
11
|
-
BLOCK_NOT_FOUND: new Error("Block does not exist")
|
|
11
|
+
BLOCK_NOT_FOUND: new Error("Block does not exist"),
|
|
12
|
+
TRANSACTION_TYPE_NOT_VALID: new Error("Transaction type is not valid"),
|
|
13
|
+
TRANSACTION_NOT_BROADCAST: new Error("Transaction can not be broadcast")
|
|
12
14
|
}
|