viz-js-lib 0.11.0 → 0.12.4
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/.qoder/docs/spec/viz-dns-nameserver-spec.md +982 -0
- package/.qoder/docs/viz-cpp-node-docs/data-types.md +322 -0
- package/.qoder/docs/viz-cpp-node-docs/index.md +160 -0
- package/.qoder/docs/viz-cpp-node-docs/op-account-market.md +236 -0
- package/.qoder/docs/viz-cpp-node-docs/op-account.md +199 -0
- package/.qoder/docs/viz-cpp-node-docs/op-award.md +162 -0
- package/.qoder/docs/viz-cpp-node-docs/op-committee.md +193 -0
- package/.qoder/docs/viz-cpp-node-docs/op-content.md +157 -0
- package/.qoder/docs/viz-cpp-node-docs/op-escrow.md +224 -0
- package/.qoder/docs/viz-cpp-node-docs/op-invite.md +219 -0
- package/.qoder/docs/viz-cpp-node-docs/op-proposal.md +229 -0
- package/.qoder/docs/viz-cpp-node-docs/op-recovery.md +188 -0
- package/.qoder/docs/viz-cpp-node-docs/op-subscription.md +146 -0
- package/.qoder/docs/viz-cpp-node-docs/op-transfer-vesting.md +224 -0
- package/.qoder/docs/viz-cpp-node-docs/op-witness.md +252 -0
- package/.qoder/docs/viz-cpp-node-docs/plugins.md +887 -0
- package/.qoder/docs/viz-cpp-node-docs/virtual-operations.md +513 -0
- package/.qoder/repowiki/en/content/API Reference/API Reference.md +724 -0
- package/.qoder/repowiki/en/content/API Reference/Configuration Options.md +410 -0
- package/.qoder/repowiki/en/content/API Reference/Core API Methods.md +547 -0
- package/.qoder/repowiki/en/content/API Reference/Streaming APIs.md +380 -0
- package/.qoder/repowiki/en/content/API Reference/Transport Layer.md +341 -0
- package/.qoder/repowiki/en/content/API Reference/VIZ Blockchain Operations Coverage Status.md +427 -0
- package/.qoder/repowiki/en/content/Authentication & Cryptography/Authentication & Cryptography.md +430 -0
- package/.qoder/repowiki/en/content/Authentication & Cryptography/Digital Signatures.md +462 -0
- package/.qoder/repowiki/en/content/Authentication & Cryptography/Key Management.md +456 -0
- package/.qoder/repowiki/en/content/Authentication & Cryptography/Memo Encryption.md +331 -0
- package/.qoder/repowiki/en/content/Authentication & Cryptography/Security Practices.md +488 -0
- package/.qoder/repowiki/en/content/Broadcast Transactions/Broadcast Transactions.md +432 -0
- package/.qoder/repowiki/en/content/Broadcast Transactions/Network Broadcasting.md +418 -0
- package/.qoder/repowiki/en/content/Broadcast Transactions/Operation Construction.md +352 -0
- package/.qoder/repowiki/en/content/Broadcast Transactions/Transaction Preparation.md +353 -0
- package/.qoder/repowiki/en/content/Broadcast Transactions/Transaction Signing.md +404 -0
- package/.qoder/repowiki/en/content/Data Serialization/Data Serialization.md +540 -0
- package/.qoder/repowiki/en/content/Data Serialization/Encoding & Decoding.md +463 -0
- package/.qoder/repowiki/en/content/Data Serialization/Object Templates.md +413 -0
- package/.qoder/repowiki/en/content/Data Serialization/Type System.md +514 -0
- package/.qoder/repowiki/en/content/Data Serialization/Validation Rules.md +439 -0
- package/.qoder/repowiki/en/content/Examples & Tutorials.md +485 -0
- package/.qoder/repowiki/en/content/Getting Started.md +345 -0
- package/.qoder/repowiki/en/content/Testing & Development.md +637 -0
- package/.qoder/repowiki/en/content/Utilities & Helpers.md +557 -0
- package/.qoder/repowiki/en/meta/repowiki-metadata.json +1 -0
- package/VIZ-JS-LIB-COVERAGE-STATUS.md +356 -0
- package/config.json +3 -1
- package/dist/statistics.html +1 -1
- package/dist/viz-tests.min.js +32 -42
- package/dist/viz-tests.min.js.gz +0 -0
- package/dist/viz.min.js +8 -18
- package/dist/viz.min.js.gz +0 -0
- package/lib/api/methods.js +24 -0
- package/lib/auth/serializer/src/ChainTypes.js +2 -1
- package/lib/auth/serializer/src/operations.js +35 -2
- package/lib/broadcast/index.js +29 -15
- package/lib/broadcast/operations.js +4 -0
- package/lib/dns.js +658 -0
- package/lib/index.js +3 -1
- package/package.json +3 -2
- package/test/dns.test.js +395 -0
- package/webpack/makeConfig.js +3 -0
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
# Network Broadcasting
|
|
2
|
+
|
|
3
|
+
<cite>
|
|
4
|
+
**Referenced Files in This Document**
|
|
5
|
+
- [src/broadcast/index.js](file://src/broadcast/index.js)
|
|
6
|
+
- [src/broadcast/helpers.js](file://src/broadcast/helpers.js)
|
|
7
|
+
- [src/broadcast/operations.js](file://src/broadcast/operations.js)
|
|
8
|
+
- [src/api/index.js](file://src/api/index.js)
|
|
9
|
+
- [src/api/methods.js](file://src/api/methods.js)
|
|
10
|
+
- [src/api/transports/base.js](file://src/api/transports/base.js)
|
|
11
|
+
- [src/api/transports/http.js](file://src/api/transports/http.js)
|
|
12
|
+
- [src/api/transports/ws.js](file://src/api/transports/ws.js)
|
|
13
|
+
- [src/config.js](file://src/config.js)
|
|
14
|
+
- [config.json](file://config.json)
|
|
15
|
+
- [test/broadcast.test.js](file://test/broadcast.test.js)
|
|
16
|
+
- [examples/broadcast.html](file://examples/broadcast.html)
|
|
17
|
+
</cite>
|
|
18
|
+
|
|
19
|
+
## Table of Contents
|
|
20
|
+
1. [Introduction](#introduction)
|
|
21
|
+
2. [Project Structure](#project-structure)
|
|
22
|
+
3. [Core Components](#core-components)
|
|
23
|
+
4. [Architecture Overview](#architecture-overview)
|
|
24
|
+
5. [Detailed Component Analysis](#detailed-component-analysis)
|
|
25
|
+
6. [Dependency Analysis](#dependency-analysis)
|
|
26
|
+
7. [Performance Considerations](#performance-considerations)
|
|
27
|
+
8. [Troubleshooting Guide](#troubleshooting-guide)
|
|
28
|
+
9. [Conclusion](#conclusion)
|
|
29
|
+
10. [Appendices](#appendices)
|
|
30
|
+
|
|
31
|
+
## Introduction
|
|
32
|
+
This document explains the network broadcasting functionality in the VIZ JavaScript library. It focuses on how transactions are prepared, signed, and broadcast to the network, how broadcast modes are selected, and how callbacks and promises are handled. It also documents the differences between broadcast modes, error handling patterns, response processing, network configuration options, and practical examples for successful broadcasts, error scenarios, and monitoring broadcast status.
|
|
33
|
+
|
|
34
|
+
## Project Structure
|
|
35
|
+
The broadcasting feature spans several modules:
|
|
36
|
+
- Broadcast orchestration and generation: src/broadcast/index.js, src/broadcast/operations.js
|
|
37
|
+
- Helpers for account authority operations: src/broadcast/helpers.js
|
|
38
|
+
- API client and method registry: src/api/index.js, src/api/methods.js
|
|
39
|
+
- Transport layer (HTTP/WebSocket): src/api/transports/base.js, src/api/transports/http.js, src/api/transports/ws.js
|
|
40
|
+
- Configuration: src/config.js, config.json
|
|
41
|
+
- Tests and examples: test/broadcast.test.js, examples/broadcast.html
|
|
42
|
+
|
|
43
|
+
```mermaid
|
|
44
|
+
graph TB
|
|
45
|
+
subgraph "Broadcast Layer"
|
|
46
|
+
BR["src/broadcast/index.js"]
|
|
47
|
+
OPS["src/broadcast/operations.js"]
|
|
48
|
+
HELP["src/broadcast/helpers.js"]
|
|
49
|
+
end
|
|
50
|
+
subgraph "API Layer"
|
|
51
|
+
API["src/api/index.js"]
|
|
52
|
+
MTH["src/api/methods.js"]
|
|
53
|
+
end
|
|
54
|
+
subgraph "Transports"
|
|
55
|
+
BASE["src/api/transports/base.js"]
|
|
56
|
+
HTTP["src/api/transports/http.js"]
|
|
57
|
+
WS["src/api/transports/ws.js"]
|
|
58
|
+
end
|
|
59
|
+
CFG["src/config.js"]
|
|
60
|
+
CONF["config.json"]
|
|
61
|
+
BR --> API
|
|
62
|
+
BR --> CFG
|
|
63
|
+
BR --> OPS
|
|
64
|
+
BR --> HELP
|
|
65
|
+
API --> MTH
|
|
66
|
+
API --> BASE
|
|
67
|
+
BASE --> HTTP
|
|
68
|
+
BASE --> WS
|
|
69
|
+
CFG --> CONF
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Diagram sources**
|
|
73
|
+
- [src/broadcast/index.js](file://src/broadcast/index.js#L1-L137)
|
|
74
|
+
- [src/broadcast/operations.js](file://src/broadcast/operations.js#L1-L475)
|
|
75
|
+
- [src/broadcast/helpers.js](file://src/broadcast/helpers.js#L1-L82)
|
|
76
|
+
- [src/api/index.js](file://src/api/index.js#L1-L271)
|
|
77
|
+
- [src/api/methods.js](file://src/api/methods.js#L1-L475)
|
|
78
|
+
- [src/api/transports/base.js](file://src/api/transports/base.js#L1-L34)
|
|
79
|
+
- [src/api/transports/http.js](file://src/api/transports/http.js#L1-L53)
|
|
80
|
+
- [src/api/transports/ws.js](file://src/api/transports/ws.js#L1-L136)
|
|
81
|
+
- [src/config.js](file://src/config.js#L1-L10)
|
|
82
|
+
- [config.json](file://config.json#L1-L7)
|
|
83
|
+
|
|
84
|
+
**Section sources**
|
|
85
|
+
- [src/broadcast/index.js](file://src/broadcast/index.js#L1-L137)
|
|
86
|
+
- [src/api/index.js](file://src/api/index.js#L1-L271)
|
|
87
|
+
- [src/api/transports/base.js](file://src/api/transports/base.js#L1-L34)
|
|
88
|
+
|
|
89
|
+
## Core Components
|
|
90
|
+
- Broadcaster.send: Central method that signs a transaction and broadcasts it via either synchronous or callback-enabled broadcast APIs depending on configuration.
|
|
91
|
+
- Transaction preparation: _prepareTransaction fetches dynamic global properties, sets expiration, and computes reference block fields using either the last irreversible block or a recent block header.
|
|
92
|
+
- Operation wrappers: Generated methods (e.g., vote, content, transfer) wrap Broadcaster.send with operation-specific parameters and metadata handling.
|
|
93
|
+
- API client: VIZ class manages transport selection, request lifecycle, and streaming utilities.
|
|
94
|
+
- Transports: HTTP and WebSocket transports implement request/response handling, connection lifecycle, and error propagation.
|
|
95
|
+
- Configuration: Global config controls the broadcast mode and network endpoint.
|
|
96
|
+
|
|
97
|
+
Key responsibilities:
|
|
98
|
+
- Signing and broadcasting: src/broadcast/index.js
|
|
99
|
+
- Operation definitions: src/broadcast/operations.js
|
|
100
|
+
- Account authority helpers: src/broadcast/helpers.js
|
|
101
|
+
- API method registry and transport wiring: src/api/index.js, src/api/methods.js
|
|
102
|
+
- Transport implementations: src/api/transports/http.js, src/api/transports/ws.js
|
|
103
|
+
- Configuration: src/config.js, config.json
|
|
104
|
+
|
|
105
|
+
**Section sources**
|
|
106
|
+
- [src/broadcast/index.js](file://src/broadcast/index.js#L24-L84)
|
|
107
|
+
- [src/broadcast/operations.js](file://src/broadcast/operations.js#L1-L475)
|
|
108
|
+
- [src/api/index.js](file://src/api/index.js#L21-L236)
|
|
109
|
+
- [src/api/methods.js](file://src/api/methods.js#L366-L379)
|
|
110
|
+
- [src/api/transports/http.js](file://src/api/transports/http.js#L43-L52)
|
|
111
|
+
- [src/api/transports/ws.js](file://src/api/transports/ws.js#L18-L94)
|
|
112
|
+
- [src/config.js](file://src/config.js#L1-L10)
|
|
113
|
+
- [config.json](file://config.json#L1-L7)
|
|
114
|
+
|
|
115
|
+
## Architecture Overview
|
|
116
|
+
The broadcast pipeline integrates transaction preparation, signing, and network broadcast through the configured transport. The mode selection is controlled by a configuration flag that chooses between synchronous and callback-enabled broadcast methods.
|
|
117
|
+
|
|
118
|
+
```mermaid
|
|
119
|
+
sequenceDiagram
|
|
120
|
+
participant App as "Application"
|
|
121
|
+
participant BR as "Broadcaster.send"
|
|
122
|
+
participant PREP as "_prepareTransaction"
|
|
123
|
+
participant AUTH as "nodeAuth.signTransaction"
|
|
124
|
+
participant API as "nodeApi.broadcast*"
|
|
125
|
+
participant TR as "Transport (HTTP/WS)"
|
|
126
|
+
participant NET as "VIZ Node"
|
|
127
|
+
App->>BR : "send(tx, privKeys, callback)"
|
|
128
|
+
BR->>PREP : "prepare transaction"
|
|
129
|
+
PREP-->>BR : "tx with ref_block and expiration"
|
|
130
|
+
BR->>AUTH : "signTransaction(tx, privKeys)"
|
|
131
|
+
AUTH-->>BR : "signedTx"
|
|
132
|
+
BR->>API : "broadcastTransactionWithCallbackAsync or broadcastTransactionAsync"
|
|
133
|
+
API->>TR : "transport.send(...)"
|
|
134
|
+
TR->>NET : "JSON-RPC call"
|
|
135
|
+
NET-->>TR : "result or error"
|
|
136
|
+
TR-->>API : "result or error"
|
|
137
|
+
API-->>BR : "result"
|
|
138
|
+
BR-->>App : "callback(err, tx)"
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**Diagram sources**
|
|
142
|
+
- [src/broadcast/index.js](file://src/broadcast/index.js#L24-L47)
|
|
143
|
+
- [src/api/methods.js](file://src/api/methods.js#L366-L379)
|
|
144
|
+
- [src/api/transports/http.js](file://src/api/transports/http.js#L43-L52)
|
|
145
|
+
- [src/api/transports/ws.js](file://src/api/transports/ws.js#L64-L94)
|
|
146
|
+
|
|
147
|
+
## Detailed Component Analysis
|
|
148
|
+
|
|
149
|
+
### Broadcaster.send and Mode Selection
|
|
150
|
+
- Purpose: Prepare, sign, and broadcast a transaction. Selects broadcast mode based on configuration.
|
|
151
|
+
- Mode selection:
|
|
152
|
+
- If the configuration flag for callback-enabled broadcast is true, it uses the callback-enabled broadcast method; otherwise, it uses the synchronous broadcast method.
|
|
153
|
+
- Callback handling:
|
|
154
|
+
- Returns a promise that is converted to Node-style callback semantics using a promisification utility.
|
|
155
|
+
- Transaction preparation:
|
|
156
|
+
- Fetches dynamic global properties and sets expiration and reference block fields.
|
|
157
|
+
- Uses the last irreversible block when available; otherwise derives reference block from a recent block header.
|
|
158
|
+
|
|
159
|
+
```mermaid
|
|
160
|
+
flowchart TD
|
|
161
|
+
Start(["send(tx, privKeys, callback)"]) --> Prep["_prepareTransaction(tx)"]
|
|
162
|
+
Prep --> Sign["nodeAuth.signTransaction(tx, privKeys)"]
|
|
163
|
+
Sign --> Mode{"broadcast_transaction_with_callback?"}
|
|
164
|
+
Mode --> |Yes| CallCB["nodeApi.broadcastTransactionWithCallbackAsync(...)"]
|
|
165
|
+
Mode --> |No| CallSync["nodeApi.broadcastTransactionAsync(...)"]
|
|
166
|
+
CallCB --> Done(["return signed tx"])
|
|
167
|
+
CallSync --> Done
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**Diagram sources**
|
|
171
|
+
- [src/broadcast/index.js](file://src/broadcast/index.js#L24-L47)
|
|
172
|
+
- [src/config.js](file://src/config.js#L5-L5)
|
|
173
|
+
- [config.json](file://config.json#L5-L5)
|
|
174
|
+
|
|
175
|
+
**Section sources**
|
|
176
|
+
- [src/broadcast/index.js](file://src/broadcast/index.js#L24-L47)
|
|
177
|
+
- [src/broadcast/index.js](file://src/broadcast/index.js#L49-L84)
|
|
178
|
+
- [src/config.js](file://src/config.js#L5-L5)
|
|
179
|
+
- [config.json](file://config.json#L5-L5)
|
|
180
|
+
|
|
181
|
+
### Transaction Preparation (_prepareTransaction)
|
|
182
|
+
- Retrieves dynamic global properties to compute chain time and expiration.
|
|
183
|
+
- Sets reference block fields:
|
|
184
|
+
- If last irreversible block reference is available, uses it.
|
|
185
|
+
- Otherwise, computes reference from a block header two behind the head block.
|
|
186
|
+
- Applies expiration as a small offset from chain time.
|
|
187
|
+
|
|
188
|
+
```mermaid
|
|
189
|
+
flowchart TD
|
|
190
|
+
A["getDynamicGlobalPropertiesAsync()"] --> B{"last_irreversible_block_ref_num present?"}
|
|
191
|
+
B --> |Yes| C["use last_irreversible_block_ref_num/prefix"]
|
|
192
|
+
B --> |No| D["compute ref from head_block_number - 2"]
|
|
193
|
+
C --> E["set expiration = chainTime + offset"]
|
|
194
|
+
D --> F["fetch block header and derive prefix"]
|
|
195
|
+
F --> E
|
|
196
|
+
E --> G["return merged tx"]
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
**Diagram sources**
|
|
200
|
+
- [src/broadcast/index.js](file://src/broadcast/index.js#L49-L84)
|
|
201
|
+
|
|
202
|
+
**Section sources**
|
|
203
|
+
- [src/broadcast/index.js](file://src/broadcast/index.js#L49-L84)
|
|
204
|
+
|
|
205
|
+
### Operation Wrappers and Helpers
|
|
206
|
+
- Generated wrappers:
|
|
207
|
+
- For each operation definition, Broadcaster generates methods that assemble the operation object and call Broadcaster.send.
|
|
208
|
+
- Handles optional metadata serialization and permlink derivation for content operations.
|
|
209
|
+
- Helpers:
|
|
210
|
+
- Utilities to add/remove account authorities and update account authorities atomically.
|
|
211
|
+
|
|
212
|
+
```mermaid
|
|
213
|
+
classDiagram
|
|
214
|
+
class Broadcaster {
|
|
215
|
+
+send(tx, privKeys, callback)
|
|
216
|
+
+_prepareTransaction(tx)
|
|
217
|
+
+vote(...)
|
|
218
|
+
+content(...)
|
|
219
|
+
+transfer(...)
|
|
220
|
+
+...
|
|
221
|
+
}
|
|
222
|
+
class Operations {
|
|
223
|
+
+definitions
|
|
224
|
+
}
|
|
225
|
+
class Helpers {
|
|
226
|
+
+addAccountAuth(...)
|
|
227
|
+
+removeAccountAuth(...)
|
|
228
|
+
}
|
|
229
|
+
Broadcaster --> Operations : "uses"
|
|
230
|
+
Broadcaster --> Helpers : "uses"
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
**Diagram sources**
|
|
234
|
+
- [src/broadcast/index.js](file://src/broadcast/index.js#L88-L129)
|
|
235
|
+
- [src/broadcast/operations.js](file://src/broadcast/operations.js#L1-L475)
|
|
236
|
+
- [src/broadcast/helpers.js](file://src/broadcast/helpers.js#L5-L81)
|
|
237
|
+
|
|
238
|
+
**Section sources**
|
|
239
|
+
- [src/broadcast/index.js](file://src/broadcast/index.js#L88-L129)
|
|
240
|
+
- [src/broadcast/operations.js](file://src/broadcast/operations.js#L1-L475)
|
|
241
|
+
- [src/broadcast/helpers.js](file://src/broadcast/helpers.js#L5-L81)
|
|
242
|
+
|
|
243
|
+
### API Client and Transport Layer
|
|
244
|
+
- VIZ API client:
|
|
245
|
+
- Manages transport selection based on URL scheme (HTTP/WS).
|
|
246
|
+
- Provides request lifecycle hooks and streaming utilities.
|
|
247
|
+
- HTTP transport:
|
|
248
|
+
- JSON-RPC over HTTP using cross-fetch.
|
|
249
|
+
- Parses errors and returns results.
|
|
250
|
+
- WebSocket transport:
|
|
251
|
+
- Maintains connection state, tracks in-flight requests, and handles messages.
|
|
252
|
+
- Emits performance metrics and propagates errors consistently.
|
|
253
|
+
|
|
254
|
+
```mermaid
|
|
255
|
+
classDiagram
|
|
256
|
+
class VIZ {
|
|
257
|
+
+start()
|
|
258
|
+
+stop()
|
|
259
|
+
+send(api, data, callback)
|
|
260
|
+
+streamBlockNumber(...)
|
|
261
|
+
+streamBlock(...)
|
|
262
|
+
+streamTransactions(...)
|
|
263
|
+
+streamOperations(...)
|
|
264
|
+
}
|
|
265
|
+
class Transport {
|
|
266
|
+
+setOptions(options)
|
|
267
|
+
+listenTo(target, event, callback)
|
|
268
|
+
+send(api, data, callback)
|
|
269
|
+
+start()
|
|
270
|
+
+stop()
|
|
271
|
+
}
|
|
272
|
+
class HttpTransport {
|
|
273
|
+
+send(api, data, callback)
|
|
274
|
+
}
|
|
275
|
+
class WsTransport {
|
|
276
|
+
+start()
|
|
277
|
+
+stop()
|
|
278
|
+
+send(api, data, callback)
|
|
279
|
+
+onMessage(msg)
|
|
280
|
+
}
|
|
281
|
+
VIZ --> Transport : "uses"
|
|
282
|
+
Transport <|-- HttpTransport
|
|
283
|
+
Transport <|-- WsTransport
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
**Diagram sources**
|
|
287
|
+
- [src/api/index.js](file://src/api/index.js#L21-L236)
|
|
288
|
+
- [src/api/transports/base.js](file://src/api/transports/base.js#L4-L31)
|
|
289
|
+
- [src/api/transports/http.js](file://src/api/transports/http.js#L43-L52)
|
|
290
|
+
- [src/api/transports/ws.js](file://src/api/transports/ws.js#L18-L94)
|
|
291
|
+
|
|
292
|
+
**Section sources**
|
|
293
|
+
- [src/api/index.js](file://src/api/index.js#L34-L62)
|
|
294
|
+
- [src/api/index.js](file://src/api/index.js#L98-L119)
|
|
295
|
+
- [src/api/transports/http.js](file://src/api/transports/http.js#L17-L41)
|
|
296
|
+
- [src/api/transports/http.js](file://src/api/transports/http.js#L43-L52)
|
|
297
|
+
- [src/api/transports/ws.js](file://src/api/transports/ws.js#L64-L94)
|
|
298
|
+
- [src/api/transports/ws.js](file://src/api/transports/ws.js#L111-L134)
|
|
299
|
+
|
|
300
|
+
### Broadcast Method Definitions
|
|
301
|
+
- The API method registry defines broadcast methods under the network broadcast API.
|
|
302
|
+
- Two primary broadcast methods are used by the broadcaster:
|
|
303
|
+
- Synchronous broadcast
|
|
304
|
+
- Callback-enabled broadcast
|
|
305
|
+
|
|
306
|
+
These are consumed by Broadcaster.send to choose the appropriate mode.
|
|
307
|
+
|
|
308
|
+
**Section sources**
|
|
309
|
+
- [src/api/methods.js](file://src/api/methods.js#L366-L379)
|
|
310
|
+
|
|
311
|
+
### Configuration Options
|
|
312
|
+
- broadcast_transaction_with_callback: Controls whether to use callback-enabled broadcast.
|
|
313
|
+
- websocket: Endpoint URL for transport selection.
|
|
314
|
+
- address_prefix and chain_id: Chain identifiers used elsewhere in the library.
|
|
315
|
+
|
|
316
|
+
**Section sources**
|
|
317
|
+
- [src/config.js](file://src/config.js#L5-L5)
|
|
318
|
+
- [config.json](file://config.json#L1-L7)
|
|
319
|
+
|
|
320
|
+
## Dependency Analysis
|
|
321
|
+
The broadcaster depends on:
|
|
322
|
+
- API client for dynamic properties and block retrieval
|
|
323
|
+
- Authentication module for signing
|
|
324
|
+
- Configuration for mode selection
|
|
325
|
+
- Transport layer for network communication
|
|
326
|
+
|
|
327
|
+
```mermaid
|
|
328
|
+
graph LR
|
|
329
|
+
BR["src/broadcast/index.js"] --> API["src/api/index.js"]
|
|
330
|
+
BR --> CFG["src/config.js"]
|
|
331
|
+
BR --> OPS["src/broadcast/operations.js"]
|
|
332
|
+
API --> MTH["src/api/methods.js"]
|
|
333
|
+
API --> TR_BASE["src/api/transports/base.js"]
|
|
334
|
+
TR_BASE --> TR_HTTP["src/api/transports/http.js"]
|
|
335
|
+
TR_BASE --> TR_WS["src/api/transports/ws.js"]
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
**Diagram sources**
|
|
339
|
+
- [src/broadcast/index.js](file://src/broadcast/index.js#L1-L12)
|
|
340
|
+
- [src/api/index.js](file://src/api/index.js#L1-L10)
|
|
341
|
+
- [src/api/methods.js](file://src/api/methods.js#L1-L475)
|
|
342
|
+
- [src/api/transports/base.js](file://src/api/transports/base.js#L1-L34)
|
|
343
|
+
- [src/api/transports/http.js](file://src/api/transports/http.js#L1-L53)
|
|
344
|
+
- [src/api/transports/ws.js](file://src/api/transports/ws.js#L1-L136)
|
|
345
|
+
|
|
346
|
+
**Section sources**
|
|
347
|
+
- [src/broadcast/index.js](file://src/broadcast/index.js#L1-L12)
|
|
348
|
+
- [src/api/index.js](file://src/api/index.js#L1-L10)
|
|
349
|
+
|
|
350
|
+
## Performance Considerations
|
|
351
|
+
- Transport selection:
|
|
352
|
+
- WebSocket transport supports persistent connections and lower latency for streaming and frequent requests.
|
|
353
|
+
- HTTP transport is simpler but incurs overhead per request.
|
|
354
|
+
- Request batching and concurrency:
|
|
355
|
+
- The API client maintains in-flight counters and request maps to track outstanding calls.
|
|
356
|
+
- Monitoring:
|
|
357
|
+
- Both transports emit performance events for tracked methods, enabling observability.
|
|
358
|
+
|
|
359
|
+
[No sources needed since this section provides general guidance]
|
|
360
|
+
|
|
361
|
+
## Troubleshooting Guide
|
|
362
|
+
Common issues and resolutions:
|
|
363
|
+
- Incorrect transport URL:
|
|
364
|
+
- Ensure the websocket configuration matches the intended protocol (HTTP/WS).
|
|
365
|
+
- Missing or invalid private key:
|
|
366
|
+
- Verify the private key corresponds to the required role for the operation.
|
|
367
|
+
- Expiration or reference block errors:
|
|
368
|
+
- Confirm the transaction expiration is reasonable and reference block fields are derived from recent blocks.
|
|
369
|
+
- Callback vs. promise usage:
|
|
370
|
+
- The broadcaster returns a promise that can be converted to Node-style callbacks; ensure consistent handling.
|
|
371
|
+
- Transport errors:
|
|
372
|
+
- WebSocket errors propagate to pending requests; reconnect and retry as needed.
|
|
373
|
+
|
|
374
|
+
**Section sources**
|
|
375
|
+
- [src/api/transports/ws.js](file://src/api/transports/ws.js#L96-L109)
|
|
376
|
+
- [src/api/transports/http.js](file://src/api/transports/http.js#L27-L41)
|
|
377
|
+
- [src/broadcast/index.js](file://src/broadcast/index.js#L24-L47)
|
|
378
|
+
|
|
379
|
+
## Conclusion
|
|
380
|
+
The VIZ JavaScript library’s broadcasting subsystem provides a robust, configurable mechanism to prepare, sign, and broadcast transactions. Mode selection is controlled by configuration, while the transport layer abstracts HTTP and WebSocket communications. Operation wrappers simplify constructing transactions for common actions, and helpers support account authority management. Proper configuration and understanding of broadcast modes enable reliable and observable transaction submission.
|
|
381
|
+
|
|
382
|
+
[No sources needed since this section summarizes without analyzing specific files]
|
|
383
|
+
|
|
384
|
+
## Appendices
|
|
385
|
+
|
|
386
|
+
### Practical Examples
|
|
387
|
+
|
|
388
|
+
- Successful broadcast with callback:
|
|
389
|
+
- Demonstrates voting with a posting key and handling the result via callback.
|
|
390
|
+
- Reference: [examples/broadcast.html](file://examples/broadcast.html#L15-L25)
|
|
391
|
+
|
|
392
|
+
- Successful broadcast with promise:
|
|
393
|
+
- Demonstrates content creation using asynchronous methods.
|
|
394
|
+
- Reference: [test/broadcast.test.js](file://test/broadcast.test.js#L75-L98)
|
|
395
|
+
|
|
396
|
+
- Custom JSON broadcast:
|
|
397
|
+
- Demonstrates broadcasting custom JSON operations with required authorities.
|
|
398
|
+
- Reference: [examples/broadcast.html](file://examples/broadcast.html#L74-L83)
|
|
399
|
+
|
|
400
|
+
- Error scenario:
|
|
401
|
+
- Typical error propagation from transport and API layers.
|
|
402
|
+
- Reference: [src/api/transports/http.js](file://src/api/transports/http.js#L27-L41), [src/api/transports/ws.js](file://src/api/transports/ws.js#L111-L134)
|
|
403
|
+
|
|
404
|
+
- Monitoring broadcast status:
|
|
405
|
+
- Use callback-enabled broadcast mode to receive confirmation callbacks when enabled via configuration.
|
|
406
|
+
- Reference: [src/broadcast/index.js](file://src/broadcast/index.js#L41-L43), [config.json](file://config.json#L5-L5)
|
|
407
|
+
|
|
408
|
+
### API and Method References
|
|
409
|
+
- Broadcast methods:
|
|
410
|
+
- Synchronous broadcast: [src/api/methods.js](file://src/api/methods.js#L366-L379)
|
|
411
|
+
- Callback-enabled broadcast: [src/api/methods.js](file://src/api/methods.js#L370-L374)
|
|
412
|
+
|
|
413
|
+
- Transport methods:
|
|
414
|
+
- HTTP: [src/api/transports/http.js](file://src/api/transports/http.js#L43-L52)
|
|
415
|
+
- WebSocket: [src/api/transports/ws.js](file://src/api/transports/ws.js#L64-L94)
|
|
416
|
+
|
|
417
|
+
- Configuration:
|
|
418
|
+
- [src/config.js](file://src/config.js#L5-L5), [config.json](file://config.json#L5-L5)
|