@alephium/web3 0.1.0-rc.3 → 0.1.0-rc.3-hc

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.
Files changed (33) hide show
  1. package/dev/user.conf +1 -0
  2. package/dist/alephium-web3.min.js +1 -1
  3. package/dist/alephium-web3.min.js.map +1 -1
  4. package/dist/src/api/api-alephium.d.ts +63 -1
  5. package/dist/src/api/api-alephium.js +1 -1
  6. package/dist/src/api/api-explorer.d.ts +33 -6
  7. package/dist/src/contract/events.d.ts +7 -25
  8. package/dist/src/contract/events.js +18 -31
  9. package/dist/src/index.d.ts +1 -0
  10. package/dist/src/index.js +1 -0
  11. package/dist/src/transaction/index.d.ts +2 -0
  12. package/dist/src/transaction/index.js +31 -0
  13. package/dist/src/{utils/transaction.d.ts → transaction/sign-verify.d.ts} +0 -0
  14. package/dist/src/{utils/transaction.js → transaction/sign-verify.js} +1 -1
  15. package/dist/src/transaction/status.d.ts +10 -0
  16. package/dist/src/transaction/status.js +48 -0
  17. package/dist/src/utils/index.d.ts +1 -1
  18. package/dist/src/utils/index.js +1 -1
  19. package/dist/src/utils/subscription.d.ts +24 -0
  20. package/dist/src/utils/subscription.js +52 -0
  21. package/package.json +4 -4
  22. package/src/api/api-alephium.ts +108 -1
  23. package/src/api/api-explorer.ts +50 -6
  24. package/src/contract/events.ts +21 -48
  25. package/src/index.ts +1 -0
  26. package/src/transaction/index.ts +20 -0
  27. package/src/{utils/transaction.test.ts → transaction/sign-verify.test.ts} +1 -1
  28. package/src/{utils/transaction.ts → transaction/sign-verify.ts} +1 -1
  29. package/src/transaction/status.ts +58 -0
  30. package/src/utils/index.ts +1 -1
  31. package/src/utils/subscription.ts +72 -0
  32. package/test/events.test.ts +13 -14
  33. package/test/transaction.test.ts +72 -0
@@ -31,6 +31,7 @@ export interface AssetInput {
31
31
  unlockScript: string;
32
32
  }
33
33
  export interface AssetOutput {
34
+ /** @format int32 */
34
35
  hint: number;
35
36
  /** @format 32-byte-hash */
36
37
  key: string;
@@ -62,6 +63,9 @@ export interface Balance {
62
63
  lockedBalance: string;
63
64
  /** @format x.x ALPH */
64
65
  lockedBalanceHint: string;
66
+ tokenBalances?: Token[];
67
+ lockedTokenBalances?: Token[];
68
+ /** @format int32 */
65
69
  utxoNum: number;
66
70
  warning?: string;
67
71
  }
@@ -86,8 +90,11 @@ export interface BlockEntry {
86
90
  hash: string;
87
91
  /** @format int64 */
88
92
  timestamp: number;
93
+ /** @format int32 */
89
94
  chainFrom: number;
95
+ /** @format int32 */
90
96
  chainTo: number;
97
+ /** @format int32 */
91
98
  height: number;
92
99
  deps: string[];
93
100
  transactions: Transaction[];
@@ -106,15 +113,20 @@ export interface BlockHeaderEntry {
106
113
  hash: string;
107
114
  /** @format int64 */
108
115
  timestamp: number;
116
+ /** @format int32 */
109
117
  chainFrom: number;
118
+ /** @format int32 */
110
119
  chainTo: number;
120
+ /** @format int32 */
111
121
  height: number;
112
122
  deps: string[];
113
123
  }
114
124
  export interface BrokerInfo {
115
125
  /** @format clique-id */
116
126
  cliqueId: string;
127
+ /** @format int32 */
117
128
  brokerId: number;
129
+ /** @format int32 */
118
130
  brokerNum: number;
119
131
  /** @format inet-socket-address */
120
132
  address: string;
@@ -135,7 +147,9 @@ export interface BuildDeployContractTx {
135
147
  gasPrice?: string;
136
148
  }
137
149
  export interface BuildDeployContractTxResult {
150
+ /** @format int32 */
138
151
  fromGroup: number;
152
+ /** @format int32 */
139
153
  toGroup: number;
140
154
  unsignedTx: string;
141
155
  /** @format gas */
@@ -161,7 +175,9 @@ export interface BuildExecuteScriptTx {
161
175
  gasPrice?: string;
162
176
  }
163
177
  export interface BuildExecuteScriptTxResult {
178
+ /** @format int32 */
164
179
  fromGroup: number;
180
+ /** @format int32 */
165
181
  toGroup: number;
166
182
  unsignedTx: string;
167
183
  /** @format gas */
@@ -187,6 +203,7 @@ export interface BuildMultisig {
187
203
  }
188
204
  export interface BuildMultisigAddress {
189
205
  keys: string[];
206
+ /** @format int32 */
190
207
  mrequired: number;
191
208
  }
192
209
  export interface BuildMultisigAddressResult {
@@ -207,7 +224,9 @@ export interface BuildSweepAddressTransactions {
207
224
  }
208
225
  export interface BuildSweepAddressTransactionsResult {
209
226
  unsignedTxs: SweepAddressTransaction[];
227
+ /** @format int32 */
210
228
  fromGroup: number;
229
+ /** @format int32 */
211
230
  toGroup: number;
212
231
  }
213
232
  export interface BuildTransaction {
@@ -228,10 +247,13 @@ export interface BuildTransactionResult {
228
247
  gasPrice: string;
229
248
  /** @format 32-byte-hash */
230
249
  txId: string;
250
+ /** @format int32 */
231
251
  fromGroup: number;
252
+ /** @format int32 */
232
253
  toGroup: number;
233
254
  }
234
255
  export interface CallContract {
256
+ /** @format int32 */
235
257
  group: number;
236
258
  /** @format block-hash */
237
259
  worldStateBlockHash?: string;
@@ -239,6 +261,7 @@ export interface CallContract {
239
261
  txId?: string;
240
262
  /** @format address */
241
263
  address: string;
264
+ /** @format int32 */
242
265
  methodIndex: number;
243
266
  args?: Val[];
244
267
  existingContracts?: string[];
@@ -246,6 +269,7 @@ export interface CallContract {
246
269
  }
247
270
  export interface CallContractResult {
248
271
  returns: Val[];
272
+ /** @format int32 */
249
273
  gasUsed: number;
250
274
  contracts: ContractState[];
251
275
  txInputs: string[];
@@ -253,12 +277,16 @@ export interface CallContractResult {
253
277
  events: ContractEventByTxId[];
254
278
  }
255
279
  export interface ChainInfo {
280
+ /** @format int32 */
256
281
  currentHeight: number;
257
282
  }
258
283
  export interface ChainParams {
259
284
  networkId: number;
285
+ /** @format int32 */
260
286
  numZerosAtLeastInHash: number;
287
+ /** @format int32 */
261
288
  groupNumPerBroker: number;
289
+ /** @format int32 */
262
290
  groups: number;
263
291
  }
264
292
  export interface ChangeActiveAddress {
@@ -281,9 +309,13 @@ export interface CompileScriptResult {
281
309
  export interface Confirmed {
282
310
  /** @format block-hash */
283
311
  blockHash: string;
312
+ /** @format int32 */
284
313
  txIndex: number;
314
+ /** @format int32 */
285
315
  chainConfirmations: number;
316
+ /** @format int32 */
286
317
  fromGroupConfirmations: number;
318
+ /** @format int32 */
287
319
  toGroupConfirmations: number;
288
320
  type: string;
289
321
  }
@@ -295,6 +327,7 @@ export interface ContractEvent {
295
327
  blockHash: string;
296
328
  /** @format 32-byte-hash */
297
329
  txId: string;
330
+ /** @format int32 */
298
331
  eventIndex: number;
299
332
  fields: Val[];
300
333
  }
@@ -303,18 +336,22 @@ export interface ContractEventByTxId {
303
336
  blockHash: string;
304
337
  /** @format address */
305
338
  contractAddress: string;
339
+ /** @format int32 */
306
340
  eventIndex: number;
307
341
  fields: Val[];
308
342
  }
309
343
  export interface ContractEvents {
310
344
  events: ContractEvent[];
345
+ /** @format int32 */
311
346
  nextStart: number;
312
347
  }
313
348
  export interface ContractEventsByTxId {
314
349
  events: ContractEventByTxId[];
350
+ /** @format int32 */
315
351
  nextStart: number;
316
352
  }
317
353
  export interface ContractOutput {
354
+ /** @format int32 */
318
355
  hint: number;
319
356
  /** @format 32-byte-hash */
320
357
  key: string;
@@ -341,7 +378,9 @@ export interface DecodeUnsignedTx {
341
378
  unsignedTx: string;
342
379
  }
343
380
  export interface DecodeUnsignedTxResult {
381
+ /** @format int32 */
344
382
  fromGroup: number;
383
+ /** @format int32 */
345
384
  toGroup: number;
346
385
  unsignedTx: UnsignedTx;
347
386
  }
@@ -372,6 +411,7 @@ export interface FieldsSig {
372
411
  types: string[];
373
412
  }
374
413
  export interface FixedAssetOutput {
414
+ /** @format int32 */
375
415
  hint: number;
376
416
  /** @format 32-byte-hash */
377
417
  key: string;
@@ -393,6 +433,7 @@ export interface FunctionSig {
393
433
  returnTypes: string[];
394
434
  }
395
435
  export interface Group {
436
+ /** @format int32 */
396
437
  group: number;
397
438
  }
398
439
  export interface HashesAtHeight {
@@ -401,7 +442,9 @@ export interface HashesAtHeight {
401
442
  export interface InterCliquePeerInfo {
402
443
  /** @format clique-id */
403
444
  cliqueId: string;
445
+ /** @format int32 */
404
446
  brokerId: number;
447
+ /** @format int32 */
405
448
  groupNumPerBroker: number;
406
449
  /** @format inet-socket-address */
407
450
  address: string;
@@ -436,6 +479,7 @@ export interface NotFound {
436
479
  }
437
480
  export declare type Output = AssetOutput | ContractOutput;
438
481
  export interface OutputRef {
482
+ /** @format int32 */
439
483
  hint: number;
440
484
  /** @format 32-byte-hash */
441
485
  key: string;
@@ -443,8 +487,11 @@ export interface OutputRef {
443
487
  export interface PeerAddress {
444
488
  /** @format inet-address */
445
489
  address: string;
490
+ /** @format int32 */
446
491
  restPort: number;
492
+ /** @format int32 */
447
493
  wsPort: number;
494
+ /** @format int32 */
448
495
  minerApiPort: number;
449
496
  }
450
497
  export interface PeerMisbehavior {
@@ -454,6 +501,7 @@ export interface PeerMisbehavior {
454
501
  }
455
502
  export declare type PeerStatus = Banned | Penalty;
456
503
  export interface Penalty {
504
+ /** @format int32 */
457
505
  value: number;
458
506
  type: string;
459
507
  }
@@ -462,8 +510,11 @@ export interface Reachable {
462
510
  type: string;
463
511
  }
464
512
  export interface ReleaseVersion {
513
+ /** @format int32 */
465
514
  major: number;
515
+ /** @format int32 */
466
516
  minor: number;
517
+ /** @format int32 */
467
518
  patch: number;
468
519
  }
469
520
  export interface RevealMnemonic {
@@ -504,7 +555,9 @@ export interface SubmitTransaction {
504
555
  export interface SubmitTxResult {
505
556
  /** @format 32-byte-hash */
506
557
  txId: string;
558
+ /** @format int32 */
507
559
  fromGroup: number;
560
+ /** @format int32 */
508
561
  toGroup: number;
509
562
  }
510
563
  export interface Sweep {
@@ -516,6 +569,7 @@ export interface Sweep {
516
569
  gasAmount?: number;
517
570
  /** @format uint256 */
518
571
  gasPrice?: string;
572
+ /** @format int32 */
519
573
  utxosLimit?: number;
520
574
  }
521
575
  export interface SweepAddressTransaction {
@@ -528,6 +582,7 @@ export interface SweepAddressTransaction {
528
582
  gasPrice: string;
529
583
  }
530
584
  export interface TestContract {
585
+ /** @format int32 */
531
586
  group?: number;
532
587
  /** @format block-hash */
533
588
  blockHash?: string;
@@ -539,6 +594,7 @@ export interface TestContract {
539
594
  bytecode: string;
540
595
  initialFields?: Val[];
541
596
  initialAsset?: AssetState;
597
+ /** @format int32 */
542
598
  methodIndex?: number;
543
599
  args?: Val[];
544
600
  existingContracts?: ContractState[];
@@ -550,6 +606,7 @@ export interface TestContractResult {
550
606
  /** @format 32-byte-hash */
551
607
  codeHash: string;
552
608
  returns: Val[];
609
+ /** @format int32 */
553
610
  gasUsed: number;
554
611
  contracts: ContractState[];
555
612
  txInputs: string[];
@@ -586,6 +643,7 @@ export interface Transfer {
586
643
  gas?: number;
587
644
  /** @format uint256 */
588
645
  gasPrice?: string;
646
+ /** @format int32 */
589
647
  utxosLimit?: number;
590
648
  }
591
649
  export interface TransferResult {
@@ -625,7 +683,9 @@ export interface Unban {
625
683
  type: string;
626
684
  }
627
685
  export interface UnconfirmedTransactions {
686
+ /** @format int32 */
628
687
  fromGroup: number;
688
+ /** @format int32 */
629
689
  toGroup: number;
630
690
  unconfirmedTransactions: TransactionTemplate[];
631
691
  }
@@ -640,6 +700,7 @@ export interface UnsignedTx {
640
700
  networkId: number;
641
701
  /** @format script */
642
702
  scriptOpt?: string;
703
+ /** @format int32 */
643
704
  gasAmount: number;
644
705
  /** @format uint256 */
645
706
  gasPrice: string;
@@ -666,6 +727,7 @@ export interface ValByteVec {
666
727
  type: string;
667
728
  }
668
729
  export interface ValI256 {
730
+ /** @format bigint */
669
731
  value: string;
670
732
  type: string;
671
733
  }
@@ -774,7 +836,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
774
836
  }
775
837
  /**
776
838
  * @title Alephium API
777
- * @version 1.4.0
839
+ * @version 1.4.1
778
840
  * @baseUrl {protocol}://{host}:{port}
779
841
  */
780
842
  export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
@@ -158,7 +158,7 @@ class HttpClient {
158
158
  exports.HttpClient = HttpClient;
159
159
  /**
160
160
  * @title Alephium API
161
- * @version 1.4.0
161
+ * @version 1.4.1
162
162
  * @baseUrl {protocol}://{host}:{port}
163
163
  */
164
164
  class Api extends HttpClient {
@@ -9,30 +9,39 @@ export interface AddressInfo {
9
9
  balance: string;
10
10
  /** @format uint256 */
11
11
  lockedBalance: string;
12
+ /** @format int32 */
12
13
  txNumber: number;
13
14
  }
14
15
  export interface BadRequest {
15
16
  detail: string;
16
17
  }
17
18
  export interface BlockEntryLite {
19
+ /** @format block-hash */
18
20
  hash: string;
19
21
  /** @format int64 */
20
22
  timestamp: number;
23
+ /** @format int32 */
21
24
  chainFrom: number;
25
+ /** @format int32 */
22
26
  chainTo: number;
27
+ /** @format int32 */
23
28
  height: number;
29
+ /** @format int32 */
24
30
  txNumber: number;
25
31
  mainChain: boolean;
26
32
  /** @format bigint */
27
33
  hashRate: string;
28
34
  }
29
35
  export interface ConfirmedTransaction {
36
+ /** @format 32-byte-hash */
30
37
  hash: string;
38
+ /** @format block-hash */
31
39
  blockHash: string;
32
40
  /** @format int64 */
33
41
  timestamp: number;
34
42
  inputs?: Input[];
35
43
  outputs?: Output[];
44
+ /** @format int32 */
36
45
  gasAmount: number;
37
46
  /** @format uint256 */
38
47
  gasPrice: string;
@@ -45,12 +54,13 @@ export interface ExplorerInfo {
45
54
  export interface Hashrate {
46
55
  /** @format int64 */
47
56
  timestamp: number;
48
- hashrate: string;
49
- value: string;
57
+ hashrate: number;
58
+ value: number;
50
59
  }
51
60
  export interface Input {
52
61
  outputRef: OutputRef;
53
62
  unlockScript?: string;
63
+ /** @format 32-byte-hash */
54
64
  txHashRef: string;
55
65
  address: string;
56
66
  /** @format uint256 */
@@ -60,6 +70,7 @@ export interface InternalServerError {
60
70
  detail: string;
61
71
  }
62
72
  export interface ListBlocks {
73
+ /** @format int32 */
63
74
  total: number;
64
75
  blocks?: BlockEntryLite[];
65
76
  }
@@ -68,6 +79,7 @@ export interface NotFound {
68
79
  resource: string;
69
80
  }
70
81
  export interface Output {
82
+ /** @format int32 */
71
83
  hint: number;
72
84
  /** @format 32-byte-hash */
73
85
  key: string;
@@ -76,21 +88,27 @@ export interface Output {
76
88
  address: string;
77
89
  /** @format int64 */
78
90
  lockTime?: number;
91
+ /** @format 32-byte-hash */
79
92
  spent?: string;
80
93
  }
81
94
  export interface OutputRef {
95
+ /** @format int32 */
82
96
  hint: number;
83
97
  /** @format 32-byte-hash */
84
98
  key: string;
85
99
  }
86
100
  export interface PerChainCount {
101
+ /** @format int32 */
87
102
  chainFrom: number;
103
+ /** @format int32 */
88
104
  chainTo: number;
89
105
  /** @format int64 */
90
106
  count: number;
91
107
  }
92
108
  export interface PerChainDuration {
109
+ /** @format int32 */
93
110
  chainFrom: number;
111
+ /** @format int32 */
94
112
  chainTo: number;
95
113
  /** @format int64 */
96
114
  duration: number;
@@ -98,7 +116,9 @@ export interface PerChainDuration {
98
116
  value: number;
99
117
  }
100
118
  export interface PerChainHeight {
119
+ /** @format int32 */
101
120
  chainFrom: number;
121
+ /** @format int32 */
102
122
  chainTo: number;
103
123
  /** @format int64 */
104
124
  height: number;
@@ -134,12 +154,15 @@ export interface TokenSupply {
134
154
  maximum: string;
135
155
  }
136
156
  export interface Transaction {
157
+ /** @format 32-byte-hash */
137
158
  hash: string;
159
+ /** @format block-hash */
138
160
  blockHash: string;
139
161
  /** @format int64 */
140
162
  timestamp: number;
141
163
  inputs?: Input[];
142
164
  outputs?: Output[];
165
+ /** @format int32 */
143
166
  gasAmount: number;
144
167
  /** @format uint256 */
145
168
  gasPrice: string;
@@ -160,11 +183,15 @@ export interface Unauthorized {
160
183
  detail: string;
161
184
  }
162
185
  export interface UnconfirmedTransaction {
186
+ /** @format 32-byte-hash */
163
187
  hash: string;
188
+ /** @format int32 */
164
189
  chainFrom: number;
190
+ /** @format int32 */
165
191
  chainTo: number;
166
192
  inputs?: UInput[];
167
193
  outputs?: UOutput[];
194
+ /** @format int32 */
168
195
  gasAmount: number;
169
196
  /** @format uint256 */
170
197
  gasPrice: string;
@@ -351,7 +378,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
351
378
  * @name GetInfosSupplyTotalAlph
352
379
  * @request GET:/infos/supply/total-alph
353
380
  */
354
- getInfosSupplyTotalAlph: (params?: RequestParams) => Promise<string>;
381
+ getInfosSupplyTotalAlph: (params?: RequestParams) => Promise<number>;
355
382
  /**
356
383
  * @description Get the ALPH circulating supply
357
384
  *
@@ -359,7 +386,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
359
386
  * @name GetInfosSupplyCirculatingAlph
360
387
  * @request GET:/infos/supply/circulating-alph
361
388
  */
362
- getInfosSupplyCirculatingAlph: (params?: RequestParams) => Promise<string>;
389
+ getInfosSupplyCirculatingAlph: (params?: RequestParams) => Promise<number>;
363
390
  /**
364
391
  * @description Get the ALPH reserved supply
365
392
  *
@@ -367,7 +394,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
367
394
  * @name GetInfosSupplyReservedAlph
368
395
  * @request GET:/infos/supply/reserved-alph
369
396
  */
370
- getInfosSupplyReservedAlph: (params?: RequestParams) => Promise<string>;
397
+ getInfosSupplyReservedAlph: (params?: RequestParams) => Promise<number>;
371
398
  /**
372
399
  * @description Get the ALPH locked supply
373
400
  *
@@ -375,7 +402,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
375
402
  * @name GetInfosSupplyLockedAlph
376
403
  * @request GET:/infos/supply/locked-alph
377
404
  */
378
- getInfosSupplyLockedAlph: (params?: RequestParams) => Promise<string>;
405
+ getInfosSupplyLockedAlph: (params?: RequestParams) => Promise<number>;
379
406
  /**
380
407
  * @description Get the total number of transactions
381
408
  *
@@ -1,29 +1,11 @@
1
- import { node } from '../api';
2
- import { NodeProvider } from '../api';
3
- declare type EventCallback = (event: node.ContractEvent) => Promise<void>;
4
- declare type ErrorCallback = (error: any, subscription: Subscription) => Promise<void>;
5
- export interface SubscribeOptions {
6
- provider: NodeProvider;
7
- contractAddress: string;
8
- fromCount?: number;
9
- pollingInterval: number;
10
- eventCallback: EventCallback;
11
- errorCallback: ErrorCallback;
12
- }
13
- export declare class Subscription {
14
- provider: NodeProvider;
1
+ import { ContractEvent } from '../api/api-alephium';
2
+ import { Subscription, SubscribeOptions } from '../utils';
3
+ export declare class EventSubscription extends Subscription<ContractEvent> {
15
4
  readonly contractAddress: string;
16
- pollingInterval: number;
17
5
  private fromCount;
18
- private eventCallback;
19
- private errorCallback;
20
- private task;
21
- private cancelled;
22
- private eventEmitter;
23
- constructor(options: SubscribeOptions);
24
- unsubscribe(): void;
6
+ constructor(options: SubscribeOptions<ContractEvent>, contractAddress: string, fromCount?: number);
7
+ startPolling(): void;
25
8
  currentEventCount(): number;
26
- private fetchEvents;
9
+ polling(): Promise<void>;
27
10
  }
28
- export declare function subscribe(options: SubscribeOptions): Subscription;
29
- export {};
11
+ export declare function subscribeToEvents(options: SubscribeOptions<ContractEvent>, contractAddress: string, fromCount?: number): EventSubscription;
@@ -16,39 +16,26 @@ GNU Lesser General Public License for more details.
16
16
  You should have received a copy of the GNU Lesser General Public License
17
17
  along with the library. If not, see <http://www.gnu.org/licenses/>.
18
18
  */
19
- var __importDefault = (this && this.__importDefault) || function (mod) {
20
- return (mod && mod.__esModule) ? mod : { "default": mod };
21
- };
22
19
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.subscribe = exports.Subscription = void 0;
24
- const eventemitter3_1 = __importDefault(require("eventemitter3"));
25
- class Subscription {
26
- constructor(options) {
27
- this.provider = options.provider;
28
- this.contractAddress = options.contractAddress;
29
- this.fromCount = typeof options.fromCount === 'undefined' ? 0 : options.fromCount;
30
- this.pollingInterval = options.pollingInterval;
31
- this.eventCallback = options.eventCallback;
32
- this.errorCallback = options.errorCallback;
33
- this.task = undefined;
34
- this.cancelled = false;
35
- this.eventEmitter = new eventemitter3_1.default();
20
+ exports.subscribeToEvents = exports.EventSubscription = void 0;
21
+ const utils_1 = require("../utils");
22
+ class EventSubscription extends utils_1.Subscription {
23
+ constructor(options, contractAddress, fromCount) {
24
+ super(options);
25
+ this.contractAddress = contractAddress;
26
+ this.fromCount = typeof fromCount === 'undefined' ? 0 : fromCount;
27
+ this.startPolling();
28
+ }
29
+ startPolling() {
36
30
  this.eventEmitter.on('tick', async () => {
37
- await this.fetchEvents();
31
+ await this.polling();
38
32
  });
39
33
  this.eventEmitter.emit('tick');
40
34
  }
41
- unsubscribe() {
42
- this.eventEmitter.removeAllListeners();
43
- this.cancelled = true;
44
- if (typeof this.task !== 'undefined') {
45
- clearTimeout(this.task);
46
- }
47
- }
48
35
  currentEventCount() {
49
36
  return this.fromCount;
50
37
  }
51
- async fetchEvents() {
38
+ async polling() {
52
39
  try {
53
40
  const events = await this.provider.events.getEventsContractContractaddress(this.contractAddress, {
54
41
  start: this.fromCount
@@ -60,18 +47,18 @@ class Subscription {
60
47
  this.task = setTimeout(() => this.eventEmitter.emit('tick'), this.pollingInterval);
61
48
  return;
62
49
  }
63
- const promises = events.events.map((event) => this.eventCallback(event));
50
+ const promises = events.events.map((event) => this.messageCallback(event));
64
51
  await Promise.all(promises);
65
52
  this.fromCount = events.nextStart;
66
- await this.fetchEvents();
53
+ await this.polling();
67
54
  }
68
55
  catch (err) {
69
56
  await this.errorCallback(err, this);
70
57
  }
71
58
  }
72
59
  }
73
- exports.Subscription = Subscription;
74
- function subscribe(options) {
75
- return new Subscription(options);
60
+ exports.EventSubscription = EventSubscription;
61
+ function subscribeToEvents(options, contractAddress, fromCount) {
62
+ return new EventSubscription(options, contractAddress, fromCount);
76
63
  }
77
- exports.subscribe = subscribe;
64
+ exports.subscribeToEvents = subscribeToEvents;
@@ -2,4 +2,5 @@ export * from './api';
2
2
  export * from './contract';
3
3
  export * from './signer';
4
4
  export * from './utils';
5
+ export * from './transaction';
5
6
  export * from './constants';
package/dist/src/index.js CHANGED
@@ -31,4 +31,5 @@ __exportStar(require("./api"), exports);
31
31
  __exportStar(require("./contract"), exports);
32
32
  __exportStar(require("./signer"), exports);
33
33
  __exportStar(require("./utils"), exports);
34
+ __exportStar(require("./transaction"), exports);
34
35
  __exportStar(require("./constants"), exports);
@@ -0,0 +1,2 @@
1
+ export * from './sign-verify';
2
+ export * from './status';
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ /*
3
+ Copyright 2018 - 2022 The Alephium Authors
4
+ This file is part of the alephium project.
5
+
6
+ The library is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU Lesser General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ The library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public License
17
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
22
+ }) : (function(o, m, k, k2) {
23
+ if (k2 === undefined) k2 = k;
24
+ o[k2] = m[k];
25
+ }));
26
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
27
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ __exportStar(require("./sign-verify"), exports);
31
+ __exportStar(require("./status"), exports);
@@ -38,7 +38,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.transactionVerifySignature = exports.transactionSign = void 0;
40
40
  const elliptic_1 = require("elliptic");
41
- const utils = __importStar(require("./utils"));
41
+ const utils = __importStar(require("../utils"));
42
42
  const ec = new elliptic_1.ec('secp256k1');
43
43
  function transactionSign(txHash, privateKey) {
44
44
  const keyPair = ec.keyFromPrivate(privateKey);