@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
@@ -0,0 +1,10 @@
1
+ import { TxStatus } from '../api/api-alephium';
2
+ import { Subscription, SubscribeOptions } from '../utils';
3
+ export declare class TxStatusSubscription extends Subscription<TxStatus> {
4
+ readonly txId: string;
5
+ readonly fromGroup?: number;
6
+ readonly toGroup?: number;
7
+ constructor(options: SubscribeOptions<TxStatus>, txId: string, fromGroup?: number, toGroup?: number);
8
+ polling(): Promise<void>;
9
+ }
10
+ export declare function subscribeToTxStatus(options: SubscribeOptions<TxStatus>, txId: string, fromGroup?: number, toGroup?: number): TxStatusSubscription;
@@ -0,0 +1,48 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.subscribeToTxStatus = exports.TxStatusSubscription = void 0;
21
+ const utils_1 = require("../utils");
22
+ class TxStatusSubscription extends utils_1.Subscription {
23
+ constructor(options, txId, fromGroup, toGroup) {
24
+ super(options);
25
+ this.txId = txId;
26
+ this.fromGroup = fromGroup;
27
+ this.toGroup = toGroup;
28
+ this.startPolling();
29
+ }
30
+ async polling() {
31
+ try {
32
+ const txStatus = await this.provider.transactions.getTransactionsStatus({
33
+ txId: this.txId,
34
+ fromGroup: this.fromGroup,
35
+ toGroup: this.toGroup
36
+ });
37
+ await this.messageCallback(txStatus);
38
+ }
39
+ catch (err) {
40
+ await this.errorCallback(err, this);
41
+ }
42
+ }
43
+ }
44
+ exports.TxStatusSubscription = TxStatusSubscription;
45
+ function subscribeToTxStatus(options, txId, fromGroup, toGroup) {
46
+ return new TxStatusSubscription(options, txId, fromGroup, toGroup);
47
+ }
48
+ exports.subscribeToTxStatus = subscribeToTxStatus;
@@ -2,5 +2,5 @@ export * from './address';
2
2
  export * from './bs58';
3
3
  export * from './djb2';
4
4
  export * from './password-crypto';
5
- export * from './transaction';
6
5
  export * from './utils';
6
+ export * from './subscription';
@@ -31,5 +31,5 @@ __exportStar(require("./address"), exports);
31
31
  __exportStar(require("./bs58"), exports);
32
32
  __exportStar(require("./djb2"), exports);
33
33
  __exportStar(require("./password-crypto"), exports);
34
- __exportStar(require("./transaction"), exports);
35
34
  __exportStar(require("./utils"), exports);
35
+ __exportStar(require("./subscription"), exports);
@@ -0,0 +1,24 @@
1
+ import EventEmitter from 'eventemitter3';
2
+ import { NodeProvider } from '../api';
3
+ declare type MessageCallback<Message> = (message: Message) => Promise<void>;
4
+ declare type ErrorCallback<Message> = (error: any, subscription: Subscription<Message>) => Promise<void>;
5
+ export interface SubscribeOptions<Message> {
6
+ provider: NodeProvider;
7
+ pollingInterval: number;
8
+ messageCallback: MessageCallback<Message>;
9
+ errorCallback: ErrorCallback<Message>;
10
+ }
11
+ export declare abstract class Subscription<Message> {
12
+ provider: NodeProvider;
13
+ pollingInterval: number;
14
+ protected messageCallback: MessageCallback<Message>;
15
+ protected errorCallback: ErrorCallback<Message>;
16
+ protected task: ReturnType<typeof setTimeout> | undefined;
17
+ protected eventEmitter: EventEmitter;
18
+ protected cancelled: boolean;
19
+ constructor(options: SubscribeOptions<Message>);
20
+ startPolling(): void;
21
+ unsubscribe(): void;
22
+ abstract polling(): Promise<void>;
23
+ }
24
+ export {};
@@ -0,0 +1,52 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
20
+ return (mod && mod.__esModule) ? mod : { "default": mod };
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.Subscription = void 0;
24
+ const eventemitter3_1 = __importDefault(require("eventemitter3"));
25
+ class Subscription {
26
+ constructor(options) {
27
+ this.provider = options.provider;
28
+ this.pollingInterval = options.pollingInterval;
29
+ this.messageCallback = options.messageCallback;
30
+ this.errorCallback = options.errorCallback;
31
+ this.task = undefined;
32
+ this.cancelled = false;
33
+ this.eventEmitter = new eventemitter3_1.default();
34
+ }
35
+ startPolling() {
36
+ this.eventEmitter.on('tick', async () => {
37
+ await this.polling();
38
+ if (!this.cancelled) {
39
+ this.task = setTimeout(() => this.eventEmitter.emit('tick'), this.pollingInterval);
40
+ }
41
+ });
42
+ this.eventEmitter.emit('tick');
43
+ }
44
+ unsubscribe() {
45
+ this.eventEmitter.removeAllListeners();
46
+ this.cancelled = true;
47
+ if (typeof this.task !== 'undefined') {
48
+ clearTimeout(this.task);
49
+ }
50
+ }
51
+ }
52
+ exports.Subscription = Subscription;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alephium/web3",
3
- "version": "0.1.0-rc.3",
3
+ "version": "0.1.0-rc.3-hc",
4
4
  "description": "A JS/TS library to interact with the Alephium platform",
5
5
  "license": "GPL",
6
6
  "main": "dist/src/index.js",
@@ -27,14 +27,14 @@
27
27
  },
28
28
  "author": "Alephium dev <dev@alephium.org>",
29
29
  "config": {
30
- "alephium_version": "1.4.0-rc3",
31
- "explorer_backend_version": "1.7.0-leman2"
30
+ "alephium_version": "token-balance",
31
+ "explorer_backend_version": "1.7.0"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "rm -rf dist/* && npx tsc --build . && webpack",
35
35
  "bundle": "webpack",
36
36
  "update-schemas": "npm run update-schema:alephium && npm run update-schema:explorer",
37
- "update-schema:alephium": "npx swagger-typescript-api -t ./configs -o ./src/api -n api-alephium.ts -p https://raw.githubusercontent.com/alephium/alephium/v${npm_package_config_alephium_version}/api/src/main/resources/openapi.json",
37
+ "update-schema:alephium": "npx swagger-typescript-api -t ./configs -o ./src/api -n api-alephium.ts -p https://raw.githubusercontent.com/alephium/alephium/${npm_package_config_alephium_version}/api/src/main/resources/openapi.json",
38
38
  "update-schema:explorer": "npx swagger-typescript-api -t ./configs -o ./src/api -n api-explorer.ts -p https://raw.githubusercontent.com/alephium/explorer-backend/v${npm_package_config_explorer_backend_version}/app/src/main/resources/explorer-backend-openapi.json",
39
39
  "check-versions": "node scripts/check-versions.js ${npm_package_config_alephium_version} ${npm_package_config_explorer_backend_version}",
40
40
  "dev": "tsnd --respawn lib/index.ts",
@@ -53,6 +53,7 @@ export interface AssetInput {
53
53
  }
54
54
 
55
55
  export interface AssetOutput {
56
+ /** @format int32 */
56
57
  hint: number
57
58
 
58
59
  /** @format 32-byte-hash */
@@ -95,6 +96,10 @@ export interface Balance {
95
96
 
96
97
  /** @format x.x ALPH */
97
98
  lockedBalanceHint: string
99
+ tokenBalances?: Token[]
100
+ lockedTokenBalances?: Token[]
101
+
102
+ /** @format int32 */
98
103
  utxoNum: number
99
104
  warning?: string
100
105
  }
@@ -125,8 +130,14 @@ export interface BlockEntry {
125
130
 
126
131
  /** @format int64 */
127
132
  timestamp: number
133
+
134
+ /** @format int32 */
128
135
  chainFrom: number
136
+
137
+ /** @format int32 */
129
138
  chainTo: number
139
+
140
+ /** @format int32 */
130
141
  height: number
131
142
  deps: string[]
132
143
  transactions: Transaction[]
@@ -151,8 +162,14 @@ export interface BlockHeaderEntry {
151
162
 
152
163
  /** @format int64 */
153
164
  timestamp: number
165
+
166
+ /** @format int32 */
154
167
  chainFrom: number
168
+
169
+ /** @format int32 */
155
170
  chainTo: number
171
+
172
+ /** @format int32 */
156
173
  height: number
157
174
  deps: string[]
158
175
  }
@@ -160,7 +177,11 @@ export interface BlockHeaderEntry {
160
177
  export interface BrokerInfo {
161
178
  /** @format clique-id */
162
179
  cliqueId: string
180
+
181
+ /** @format int32 */
163
182
  brokerId: number
183
+
184
+ /** @format int32 */
164
185
  brokerNum: number
165
186
 
166
187
  /** @format inet-socket-address */
@@ -189,7 +210,10 @@ export interface BuildDeployContractTx {
189
210
  }
190
211
 
191
212
  export interface BuildDeployContractTxResult {
213
+ /** @format int32 */
192
214
  fromGroup: number
215
+
216
+ /** @format int32 */
193
217
  toGroup: number
194
218
  unsignedTx: string
195
219
 
@@ -225,7 +249,10 @@ export interface BuildExecuteScriptTx {
225
249
  }
226
250
 
227
251
  export interface BuildExecuteScriptTxResult {
252
+ /** @format int32 */
228
253
  fromGroup: number
254
+
255
+ /** @format int32 */
229
256
  toGroup: number
230
257
  unsignedTx: string
231
258
 
@@ -259,6 +286,8 @@ export interface BuildMultisig {
259
286
 
260
287
  export interface BuildMultisigAddress {
261
288
  keys: string[]
289
+
290
+ /** @format int32 */
262
291
  mrequired: number
263
292
  }
264
293
 
@@ -286,7 +315,11 @@ export interface BuildSweepAddressTransactions {
286
315
 
287
316
  export interface BuildSweepAddressTransactionsResult {
288
317
  unsignedTxs: SweepAddressTransaction[]
318
+
319
+ /** @format int32 */
289
320
  fromGroup: number
321
+
322
+ /** @format int32 */
290
323
  toGroup: number
291
324
  }
292
325
 
@@ -314,11 +347,16 @@ export interface BuildTransactionResult {
314
347
 
315
348
  /** @format 32-byte-hash */
316
349
  txId: string
350
+
351
+ /** @format int32 */
317
352
  fromGroup: number
353
+
354
+ /** @format int32 */
318
355
  toGroup: number
319
356
  }
320
357
 
321
358
  export interface CallContract {
359
+ /** @format int32 */
322
360
  group: number
323
361
 
324
362
  /** @format block-hash */
@@ -329,6 +367,8 @@ export interface CallContract {
329
367
 
330
368
  /** @format address */
331
369
  address: string
370
+
371
+ /** @format int32 */
332
372
  methodIndex: number
333
373
  args?: Val[]
334
374
  existingContracts?: string[]
@@ -337,6 +377,8 @@ export interface CallContract {
337
377
 
338
378
  export interface CallContractResult {
339
379
  returns: Val[]
380
+
381
+ /** @format int32 */
340
382
  gasUsed: number
341
383
  contracts: ContractState[]
342
384
  txInputs: string[]
@@ -345,13 +387,20 @@ export interface CallContractResult {
345
387
  }
346
388
 
347
389
  export interface ChainInfo {
390
+ /** @format int32 */
348
391
  currentHeight: number
349
392
  }
350
393
 
351
394
  export interface ChainParams {
352
395
  networkId: number
396
+
397
+ /** @format int32 */
353
398
  numZerosAtLeastInHash: number
399
+
400
+ /** @format int32 */
354
401
  groupNumPerBroker: number
402
+
403
+ /** @format int32 */
355
404
  groups: number
356
405
  }
357
406
 
@@ -379,9 +428,17 @@ export interface CompileScriptResult {
379
428
  export interface Confirmed {
380
429
  /** @format block-hash */
381
430
  blockHash: string
431
+
432
+ /** @format int32 */
382
433
  txIndex: number
434
+
435
+ /** @format int32 */
383
436
  chainConfirmations: number
437
+
438
+ /** @format int32 */
384
439
  fromGroupConfirmations: number
440
+
441
+ /** @format int32 */
385
442
  toGroupConfirmations: number
386
443
  type: string
387
444
  }
@@ -396,6 +453,8 @@ export interface ContractEvent {
396
453
 
397
454
  /** @format 32-byte-hash */
398
455
  txId: string
456
+
457
+ /** @format int32 */
399
458
  eventIndex: number
400
459
  fields: Val[]
401
460
  }
@@ -406,21 +465,28 @@ export interface ContractEventByTxId {
406
465
 
407
466
  /** @format address */
408
467
  contractAddress: string
468
+
469
+ /** @format int32 */
409
470
  eventIndex: number
410
471
  fields: Val[]
411
472
  }
412
473
 
413
474
  export interface ContractEvents {
414
475
  events: ContractEvent[]
476
+
477
+ /** @format int32 */
415
478
  nextStart: number
416
479
  }
417
480
 
418
481
  export interface ContractEventsByTxId {
419
482
  events: ContractEventByTxId[]
483
+
484
+ /** @format int32 */
420
485
  nextStart: number
421
486
  }
422
487
 
423
488
  export interface ContractOutput {
489
+ /** @format int32 */
424
490
  hint: number
425
491
 
426
492
  /** @format 32-byte-hash */
@@ -456,7 +522,10 @@ export interface DecodeUnsignedTx {
456
522
  }
457
523
 
458
524
  export interface DecodeUnsignedTxResult {
525
+ /** @format int32 */
459
526
  fromGroup: number
527
+
528
+ /** @format int32 */
460
529
  toGroup: number
461
530
  unsignedTx: UnsignedTx
462
531
  }
@@ -496,6 +565,7 @@ export interface FieldsSig {
496
565
  }
497
566
 
498
567
  export interface FixedAssetOutput {
568
+ /** @format int32 */
499
569
  hint: number
500
570
 
501
571
  /** @format 32-byte-hash */
@@ -524,6 +594,7 @@ export interface FunctionSig {
524
594
  }
525
595
 
526
596
  export interface Group {
597
+ /** @format int32 */
527
598
  group: number
528
599
  }
529
600
 
@@ -534,7 +605,11 @@ export interface HashesAtHeight {
534
605
  export interface InterCliquePeerInfo {
535
606
  /** @format clique-id */
536
607
  cliqueId: string
608
+
609
+ /** @format int32 */
537
610
  brokerId: number
611
+
612
+ /** @format int32 */
538
613
  groupNumPerBroker: number
539
614
 
540
615
  /** @format inet-socket-address */
@@ -581,6 +656,7 @@ export interface NotFound {
581
656
  export type Output = AssetOutput | ContractOutput
582
657
 
583
658
  export interface OutputRef {
659
+ /** @format int32 */
584
660
  hint: number
585
661
 
586
662
  /** @format 32-byte-hash */
@@ -590,8 +666,14 @@ export interface OutputRef {
590
666
  export interface PeerAddress {
591
667
  /** @format inet-address */
592
668
  address: string
669
+
670
+ /** @format int32 */
593
671
  restPort: number
672
+
673
+ /** @format int32 */
594
674
  wsPort: number
675
+
676
+ /** @format int32 */
595
677
  minerApiPort: number
596
678
  }
597
679
 
@@ -604,6 +686,7 @@ export interface PeerMisbehavior {
604
686
  export type PeerStatus = Banned | Penalty
605
687
 
606
688
  export interface Penalty {
689
+ /** @format int32 */
607
690
  value: number
608
691
  type: string
609
692
  }
@@ -614,8 +697,13 @@ export interface Reachable {
614
697
  }
615
698
 
616
699
  export interface ReleaseVersion {
700
+ /** @format int32 */
617
701
  major: number
702
+
703
+ /** @format int32 */
618
704
  minor: number
705
+
706
+ /** @format int32 */
619
707
  patch: number
620
708
  }
621
709
 
@@ -667,7 +755,11 @@ export interface SubmitTransaction {
667
755
  export interface SubmitTxResult {
668
756
  /** @format 32-byte-hash */
669
757
  txId: string
758
+
759
+ /** @format int32 */
670
760
  fromGroup: number
761
+
762
+ /** @format int32 */
671
763
  toGroup: number
672
764
  }
673
765
 
@@ -683,6 +775,8 @@ export interface Sweep {
683
775
 
684
776
  /** @format uint256 */
685
777
  gasPrice?: string
778
+
779
+ /** @format int32 */
686
780
  utxosLimit?: number
687
781
  }
688
782
 
@@ -699,6 +793,7 @@ export interface SweepAddressTransaction {
699
793
  }
700
794
 
701
795
  export interface TestContract {
796
+ /** @format int32 */
702
797
  group?: number
703
798
 
704
799
  /** @format block-hash */
@@ -714,6 +809,8 @@ export interface TestContract {
714
809
  bytecode: string
715
810
  initialFields?: Val[]
716
811
  initialAsset?: AssetState
812
+
813
+ /** @format int32 */
717
814
  methodIndex?: number
718
815
  args?: Val[]
719
816
  existingContracts?: ContractState[]
@@ -727,6 +824,8 @@ export interface TestContractResult {
727
824
  /** @format 32-byte-hash */
728
825
  codeHash: string
729
826
  returns: Val[]
827
+
828
+ /** @format int32 */
730
829
  gasUsed: number
731
830
  contracts: ContractState[]
732
831
  txInputs: string[]
@@ -771,6 +870,8 @@ export interface Transfer {
771
870
 
772
871
  /** @format uint256 */
773
872
  gasPrice?: string
873
+
874
+ /** @format int32 */
774
875
  utxosLimit?: number
775
876
  }
776
877
 
@@ -824,7 +925,10 @@ export interface Unban {
824
925
  }
825
926
 
826
927
  export interface UnconfirmedTransactions {
928
+ /** @format int32 */
827
929
  fromGroup: number
930
+
931
+ /** @format int32 */
828
932
  toGroup: number
829
933
  unconfirmedTransactions: TransactionTemplate[]
830
934
  }
@@ -842,6 +946,8 @@ export interface UnsignedTx {
842
946
 
843
947
  /** @format script */
844
948
  scriptOpt?: string
949
+
950
+ /** @format int32 */
845
951
  gasAmount: number
846
952
 
847
953
  /** @format uint256 */
@@ -875,6 +981,7 @@ export interface ValByteVec {
875
981
  }
876
982
 
877
983
  export interface ValI256 {
984
+ /** @format bigint */
878
985
  value: string
879
986
  type: string
880
987
  }
@@ -1157,7 +1264,7 @@ export class HttpClient<SecurityDataType = unknown> {
1157
1264
 
1158
1265
  /**
1159
1266
  * @title Alephium API
1160
- * @version 1.4.0
1267
+ * @version 1.4.1
1161
1268
  * @baseUrl {protocol}://{host}:{port}
1162
1269
  */
1163
1270
  export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {