@alephium/web3 0.2.0-test.1 → 0.2.2

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 (128) hide show
  1. package/.eslintignore +2 -2
  2. package/README.md +2 -135
  3. package/dist/alephium-web3.min.js +1 -1
  4. package/dist/alephium-web3.min.js.LICENSE.txt +0 -17
  5. package/dist/alephium-web3.min.js.map +1 -1
  6. package/dist/src/api/api-alephium.d.ts +116 -18
  7. package/dist/src/api/api-alephium.js +146 -81
  8. package/dist/src/api/api-explorer.d.ts +178 -51
  9. package/dist/src/api/api-explorer.js +172 -37
  10. package/dist/src/api/index.d.ts +40 -5
  11. package/dist/src/api/index.js +115 -7
  12. package/dist/src/api/types.d.ts +23 -0
  13. package/dist/src/api/types.js +235 -0
  14. package/dist/src/api/utils.d.ts +6 -0
  15. package/dist/{scripts/rename-gitignore.js → src/api/utils.js} +11 -6
  16. package/dist/src/contract/contract.d.ts +69 -55
  17. package/dist/src/contract/contract.js +241 -387
  18. package/dist/src/contract/events.d.ts +4 -4
  19. package/dist/src/contract/events.js +2 -1
  20. package/dist/src/contract/index.js +5 -1
  21. package/dist/src/contract/ralph.d.ts +5 -4
  22. package/dist/src/contract/ralph.js +27 -1
  23. package/dist/src/global.d.ts +6 -2
  24. package/dist/src/global.js +19 -3
  25. package/dist/src/index.d.ts +2 -1
  26. package/dist/src/index.js +23 -2
  27. package/dist/src/signer/index.d.ts +0 -1
  28. package/dist/src/signer/index.js +5 -2
  29. package/dist/src/signer/signer.d.ts +59 -60
  30. package/dist/src/signer/signer.js +99 -70
  31. package/dist/src/transaction/index.d.ts +0 -1
  32. package/dist/src/transaction/index.js +5 -2
  33. package/dist/src/transaction/status.d.ts +2 -1
  34. package/dist/src/transaction/status.js +2 -1
  35. package/dist/src/utils/bs58.d.ts +1 -0
  36. package/dist/src/utils/bs58.js +13 -1
  37. package/dist/src/utils/index.d.ts +0 -1
  38. package/dist/src/utils/index.js +5 -2
  39. package/dist/src/utils/subscription.d.ts +0 -2
  40. package/dist/src/utils/subscription.js +0 -2
  41. package/dist/src/utils/utils.d.ts +4 -9
  42. package/dist/src/utils/utils.js +20 -24
  43. package/jest-config.json +11 -0
  44. package/package.json +11 -45
  45. package/src/api/api-alephium.ts +163 -26
  46. package/src/api/api-explorer.ts +247 -54
  47. package/src/api/index.ts +140 -6
  48. package/src/api/types.ts +229 -0
  49. package/{scripts/rename-gitignore.js → src/api/utils.ts} +7 -6
  50. package/src/contract/contract.ts +405 -432
  51. package/src/contract/events.ts +6 -5
  52. package/src/contract/ralph.ts +29 -4
  53. package/src/global.ts +23 -3
  54. package/src/index.ts +7 -1
  55. package/src/signer/index.ts +0 -1
  56. package/src/signer/signer.ts +165 -135
  57. package/src/transaction/index.ts +0 -1
  58. package/src/transaction/status.ts +5 -2
  59. package/src/utils/bs58.ts +11 -0
  60. package/src/utils/index.ts +0 -1
  61. package/src/utils/subscription.ts +0 -4
  62. package/src/utils/utils.ts +11 -19
  63. package/webpack.config.js +3 -0
  64. package/.eslintrc.json +0 -21
  65. package/LICENSE +0 -165
  66. package/contracts/add/add.ral +0 -13
  67. package/contracts/greeter/greeter.ral +0 -7
  68. package/contracts/greeter/greeter_interface.ral +0 -4
  69. package/contracts/greeter_main.ral +0 -7
  70. package/contracts/main.ral +0 -4
  71. package/contracts/sub/sub.ral +0 -10
  72. package/contracts/test/metadata.ral +0 -18
  73. package/contracts/test/warnings.ral +0 -8
  74. package/dev/user.conf +0 -29
  75. package/dist/scripts/create-project.d.ts +0 -2
  76. package/dist/scripts/create-project.js +0 -125
  77. package/dist/scripts/rename-gitignore.d.ts +0 -1
  78. package/dist/scripts/start-devnet.d.ts +0 -1
  79. package/dist/scripts/start-devnet.js +0 -131
  80. package/dist/scripts/stop-devnet.d.ts +0 -1
  81. package/dist/scripts/stop-devnet.js +0 -32
  82. package/dist/src/signer/node-wallet.d.ts +0 -11
  83. package/dist/src/signer/node-wallet.js +0 -57
  84. package/dist/src/test/index.d.ts +0 -6
  85. package/dist/src/test/index.js +0 -41
  86. package/dist/src/test/privatekey-wallet.d.ts +0 -11
  87. package/dist/src/test/privatekey-wallet.js +0 -68
  88. package/dist/src/transaction/sign-verify.d.ts +0 -2
  89. package/dist/src/transaction/sign-verify.js +0 -58
  90. package/dist/src/utils/password-crypto.d.ts +0 -2
  91. package/dist/src/utils/password-crypto.js +0 -69
  92. package/gitignore +0 -9
  93. package/scripts/create-project.ts +0 -137
  94. package/scripts/start-devnet.js +0 -141
  95. package/scripts/stop-devnet.js +0 -32
  96. package/src/contract/ralph.test.ts +0 -178
  97. package/src/fixtures/address.json +0 -36
  98. package/src/fixtures/balance.json +0 -9
  99. package/src/fixtures/self-clique.json +0 -19
  100. package/src/fixtures/transaction.json +0 -13
  101. package/src/fixtures/transactions.json +0 -179
  102. package/src/signer/fixtures/genesis.json +0 -26
  103. package/src/signer/fixtures/wallets.json +0 -26
  104. package/src/signer/node-wallet.ts +0 -65
  105. package/src/test/index.ts +0 -31
  106. package/src/test/privatekey-wallet.ts +0 -57
  107. package/src/transaction/sign-verify.test.ts +0 -50
  108. package/src/transaction/sign-verify.ts +0 -39
  109. package/src/utils/address.test.ts +0 -47
  110. package/src/utils/djb2.test.ts +0 -35
  111. package/src/utils/password-crypto.test.ts +0 -27
  112. package/src/utils/password-crypto.ts +0 -77
  113. package/src/utils/utils.test.ts +0 -161
  114. package/templates/base/README.md +0 -34
  115. package/templates/base/package.json +0 -35
  116. package/templates/base/src/greeter.ts +0 -42
  117. package/templates/base/tsconfig.json +0 -19
  118. package/templates/react/README.md +0 -34
  119. package/templates/react/config-overrides.js +0 -18
  120. package/templates/react/package.json +0 -66
  121. package/templates/react/src/App.tsx +0 -42
  122. package/templates/react/src/artifacts/greeter.ral.json +0 -26
  123. package/templates/react/src/artifacts/greeter_main.ral.json +0 -22
  124. package/templates/shared/.eslintrc.json +0 -12
  125. package/templates/shared/scripts/header.js +0 -0
  126. package/test/contract.test.ts +0 -213
  127. package/test/events.test.ts +0 -141
  128. package/test/transaction.test.ts +0 -73
@@ -124,6 +124,11 @@ export interface Banned {
124
124
  type: string
125
125
  }
126
126
 
127
+ export interface BlockAndEvents {
128
+ block: BlockEntry
129
+ events: ContractEventByBlockHash[]
130
+ }
131
+
127
132
  export interface BlockEntry {
128
133
  /** @format block-hash */
129
134
  hash: string
@@ -174,6 +179,14 @@ export interface BlockHeaderEntry {
174
179
  deps: string[]
175
180
  }
176
181
 
182
+ export interface BlocksAndEventsPerTimeStampRange {
183
+ blocksAndEvents: BlockAndEvents[][]
184
+ }
185
+
186
+ export interface BlocksPerTimeStampRange {
187
+ blocks: BlockEntry[][]
188
+ }
189
+
177
190
  export interface BrokerInfo {
178
191
  /** @format clique-id */
179
192
  cliqueId: string
@@ -422,10 +435,16 @@ export interface ChangeActiveAddress {
422
435
  }
423
436
 
424
437
  export interface CompileContractResult {
438
+ version: string
439
+ name: string
425
440
  bytecode: string
441
+ bytecodeDebugPatch: string
426
442
 
427
443
  /** @format 32-byte-hash */
428
444
  codeHash: string
445
+
446
+ /** @format 32-byte-hash */
447
+ codeHashDebug: string
429
448
  fields: FieldsSig
430
449
  functions: FunctionSig[]
431
450
  events: EventSig[]
@@ -438,12 +457,24 @@ export interface CompileProjectResult {
438
457
  }
439
458
 
440
459
  export interface CompileScriptResult {
460
+ version: string
461
+ name: string
441
462
  bytecodeTemplate: string
463
+ bytecodeDebugPatch: string
442
464
  fields: FieldsSig
443
465
  functions: FunctionSig[]
444
466
  warnings: string[]
445
467
  }
446
468
 
469
+ export interface CompilerOptions {
470
+ ignoreUnusedConstantsWarnings?: boolean
471
+ ignoreUnusedVariablesWarnings?: boolean
472
+ ignoreUnusedFieldsWarnings?: boolean
473
+ ignoreUnusedPrivateFunctionsWarnings?: boolean
474
+ ignoreUpdateFieldsCheckWarnings?: boolean
475
+ ignoreExternalCallCheckWarnings?: boolean
476
+ }
477
+
447
478
  export interface Confirmed {
448
479
  /** @format block-hash */
449
480
  blockHash: string
@@ -464,6 +495,7 @@ export interface Confirmed {
464
495
 
465
496
  export interface Contract {
466
497
  code: string
498
+ compilerOptions?: CompilerOptions
467
499
  }
468
500
 
469
501
  export interface ContractEvent {
@@ -478,6 +510,18 @@ export interface ContractEvent {
478
510
  fields: Val[]
479
511
  }
480
512
 
513
+ export interface ContractEventByBlockHash {
514
+ /** @format 32-byte-hash */
515
+ txId: string
516
+
517
+ /** @format address */
518
+ contractAddress: string
519
+
520
+ /** @format int32 */
521
+ eventIndex: number
522
+ fields: Val[]
523
+ }
524
+
481
525
  export interface ContractEventByTxId {
482
526
  /** @format block-hash */
483
527
  blockHash: string
@@ -497,11 +541,12 @@ export interface ContractEvents {
497
541
  nextStart: number
498
542
  }
499
543
 
544
+ export interface ContractEventsByBlockHash {
545
+ events: ContractEventByBlockHash[]
546
+ }
547
+
500
548
  export interface ContractEventsByTxId {
501
549
  events: ContractEventByTxId[]
502
-
503
- /** @format int32 */
504
- nextStart: number
505
550
  }
506
551
 
507
552
  export interface ContractOutput {
@@ -536,6 +581,12 @@ export interface ContractState {
536
581
  asset: AssetState
537
582
  }
538
583
 
584
+ export interface DebugMessage {
585
+ /** @format address */
586
+ contractAddress: string
587
+ message: string
588
+ }
589
+
539
590
  export interface DecodeUnsignedTx {
540
591
  unsignedTx: string
541
592
  }
@@ -572,10 +623,6 @@ export interface EventSig {
572
623
  fieldTypes: string[]
573
624
  }
574
625
 
575
- export interface FetchResponse {
576
- blocks: BlockEntry[][]
577
- }
578
-
579
626
  export interface FieldsSig {
580
627
  names: string[]
581
628
  types: string[]
@@ -714,6 +761,7 @@ export interface Penalty {
714
761
 
715
762
  export interface Project {
716
763
  code: string
764
+ compilerOptions?: CompilerOptions
717
765
  }
718
766
 
719
767
  export interface Reachable {
@@ -742,6 +790,7 @@ export interface RevealMnemonicResult {
742
790
 
743
791
  export interface Script {
744
792
  code: string
793
+ compilerOptions?: CompilerOptions
745
794
  }
746
795
 
747
796
  export interface SelfClique {
@@ -859,6 +908,7 @@ export interface TestContractResult {
859
908
  txInputs: string[]
860
909
  txOutputs: Output[]
861
910
  events: ContractEventByTxId[]
911
+ debugMessages: DebugMessage[]
862
912
  }
863
913
 
864
914
  export interface TestInputAsset {
@@ -1071,16 +1121,7 @@ export interface WalletUnlock {
1071
1121
  }
1072
1122
 
1073
1123
  import 'cross-fetch/polyfill'
1074
-
1075
- function convertHttpResponse<T>(
1076
- response: HttpResponse<T, { detail: string }> | HttpResponse<T, { detail: string }>
1077
- ): T {
1078
- if (response.error) {
1079
- throw new Error(response.error.detail)
1080
- } else {
1081
- return response.data
1082
- }
1083
- }
1124
+ import { convertHttpResponse } from './utils'
1084
1125
 
1085
1126
  export type QueryParamsType = Record<string | number, any>
1086
1127
  export type ResponseFormat = keyof Omit<Body, 'body' | 'bodyUsed'>
@@ -1284,7 +1325,6 @@ export class HttpClient<SecurityDataType = unknown> {
1284
1325
  this.abortControllers.delete(cancelToken)
1285
1326
  }
1286
1327
 
1287
- if (!response.ok) throw data
1288
1328
  return data
1289
1329
  })
1290
1330
  }
@@ -1292,7 +1332,7 @@ export class HttpClient<SecurityDataType = unknown> {
1292
1332
 
1293
1333
  /**
1294
1334
  * @title Alephium API
1295
- * @version 1.5.0
1335
+ * @version 1.5.3
1296
1336
  * @baseUrl ../
1297
1337
  */
1298
1338
  export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
@@ -1843,13 +1883,36 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
1843
1883
  * No description
1844
1884
  *
1845
1885
  * @tags Blockflow
1846
- * @name GetBlockflow
1886
+ * @name GetBlockflowBlocks
1847
1887
  * @summary List blocks on the given time interval
1848
- * @request GET:/blockflow
1888
+ * @request GET:/blockflow/blocks
1889
+ */
1890
+ getBlockflowBlocks: (query: { fromTs: number; toTs?: number }, params: RequestParams = {}) =>
1891
+ this.request<
1892
+ BlocksPerTimeStampRange,
1893
+ BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable
1894
+ >({
1895
+ path: `/blockflow/blocks`,
1896
+ method: 'GET',
1897
+ query: query,
1898
+ format: 'json',
1899
+ ...params
1900
+ }).then(convertHttpResponse),
1901
+
1902
+ /**
1903
+ * No description
1904
+ *
1905
+ * @tags Blockflow
1906
+ * @name GetBlockflowBlocksWithEvents
1907
+ * @summary List blocks with events on the given time interval
1908
+ * @request GET:/blockflow/blocks-with-events
1849
1909
  */
1850
- getBlockflow: (query: { fromTs: number; toTs?: number }, params: RequestParams = {}) =>
1851
- this.request<FetchResponse, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
1852
- path: `/blockflow`,
1910
+ getBlockflowBlocksWithEvents: (query: { fromTs: number; toTs?: number }, params: RequestParams = {}) =>
1911
+ this.request<
1912
+ BlocksAndEventsPerTimeStampRange,
1913
+ BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable
1914
+ >({
1915
+ path: `/blockflow/blocks-with-events`,
1853
1916
  method: 'GET',
1854
1917
  query: query,
1855
1918
  format: 'json',
@@ -1872,6 +1935,22 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
1872
1935
  ...params
1873
1936
  }).then(convertHttpResponse),
1874
1937
 
1938
+ /**
1939
+ * No description
1940
+ *
1941
+ * @tags Blockflow
1942
+ * @name GetBlockflowBlocksWithEventsBlockHash
1943
+ * @summary Get a block and events with hash
1944
+ * @request GET:/blockflow/blocks-with-events/{block_hash}
1945
+ */
1946
+ getBlockflowBlocksWithEventsBlockHash: (blockHash: string, params: RequestParams = {}) =>
1947
+ this.request<BlockAndEvents, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
1948
+ path: `/blockflow/blocks-with-events/${blockHash}`,
1949
+ method: 'GET',
1950
+ format: 'json',
1951
+ ...params
1952
+ }).then(convertHttpResponse),
1953
+
1875
1954
  /**
1876
1955
  * No description
1877
1956
  *
@@ -2089,6 +2168,27 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
2089
2168
  ...params
2090
2169
  }).then(convertHttpResponse),
2091
2170
 
2171
+ /**
2172
+ * No description
2173
+ *
2174
+ * @tags Transactions
2175
+ * @name GetTransactionsDetailsTxid
2176
+ * @summary Get transaction details
2177
+ * @request GET:/transactions/details/{txId}
2178
+ */
2179
+ getTransactionsDetailsTxid: (
2180
+ txId: string,
2181
+ query?: { fromGroup?: number; toGroup?: number },
2182
+ params: RequestParams = {}
2183
+ ) =>
2184
+ this.request<Transaction, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
2185
+ path: `/transactions/details/${txId}`,
2186
+ method: 'GET',
2187
+ query: query,
2188
+ format: 'json',
2189
+ ...params
2190
+ }).then(convertHttpResponse),
2191
+
2092
2192
  /**
2093
2193
  * No description
2094
2194
  *
@@ -2385,6 +2485,23 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
2385
2485
  ...params
2386
2486
  }).then(convertHttpResponse),
2387
2487
 
2488
+ /**
2489
+ * No description
2490
+ *
2491
+ * @tags Miners
2492
+ * @name PostMinersCpuMiningMineOneBlock
2493
+ * @summary Mine a block on CPU miner. !!! for test only !!!
2494
+ * @request POST:/miners/cpu-mining/mine-one-block
2495
+ */
2496
+ postMinersCpuMiningMineOneBlock: (query: { fromGroup: number; toGroup: number }, params: RequestParams = {}) =>
2497
+ this.request<boolean, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
2498
+ path: `/miners/cpu-mining/mine-one-block`,
2499
+ method: 'POST',
2500
+ query: query,
2501
+ format: 'json',
2502
+ ...params
2503
+ }).then(convertHttpResponse),
2504
+
2388
2505
  /**
2389
2506
  * No description
2390
2507
  *
@@ -2429,7 +2546,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
2429
2546
  */
2430
2547
  getEventsContractContractaddress: (
2431
2548
  contractAddress: string,
2432
- query: { start: number; end?: number; group?: number },
2549
+ query: { start: number; limit?: number; group?: number },
2433
2550
  params: RequestParams = {}
2434
2551
  ) =>
2435
2552
  this.request<ContractEvents, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
@@ -2461,7 +2578,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
2461
2578
  *
2462
2579
  * @tags Events
2463
2580
  * @name GetEventsTxIdTxid
2464
- * @summary Get events for a TxScript
2581
+ * @summary Get contract events for a transaction
2465
2582
  * @request GET:/events/tx-id/{txId}
2466
2583
  */
2467
2584
  getEventsTxIdTxid: (txId: string, query?: { group?: number }, params: RequestParams = {}) =>
@@ -2474,6 +2591,26 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
2474
2591
  query: query,
2475
2592
  format: 'json',
2476
2593
  ...params
2594
+ }).then(convertHttpResponse),
2595
+
2596
+ /**
2597
+ * No description
2598
+ *
2599
+ * @tags Events
2600
+ * @name GetEventsBlockHashBlockhash
2601
+ * @summary Get contract events for a block
2602
+ * @request GET:/events/block-hash/{blockHash}
2603
+ */
2604
+ getEventsBlockHashBlockhash: (blockHash: string, query?: { group?: number }, params: RequestParams = {}) =>
2605
+ this.request<
2606
+ ContractEventsByBlockHash,
2607
+ BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable
2608
+ >({
2609
+ path: `/events/block-hash/${blockHash}`,
2610
+ method: 'GET',
2611
+ query: query,
2612
+ format: 'json',
2613
+ ...params
2477
2614
  }).then(convertHttpResponse)
2478
2615
  }
2479
2616
  }