@alephium/web3 0.40.0 → 0.42.0

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 (68) hide show
  1. package/dist/alephium-web3.min.js +1 -1
  2. package/dist/alephium-web3.min.js.map +1 -1
  3. package/dist/src/api/node-provider.d.ts +2 -0
  4. package/dist/src/api/node-provider.js +12 -6
  5. package/dist/src/api/utils.d.ts +1 -1
  6. package/dist/src/block/block.d.ts +28 -0
  7. package/dist/src/block/block.js +131 -0
  8. package/dist/src/block/index.d.ts +1 -0
  9. package/dist/src/block/index.js +22 -0
  10. package/dist/src/codec/contract-output-codec.js +4 -4
  11. package/dist/src/codec/lockup-script-codec.js +2 -2
  12. package/dist/src/codec/method-codec.d.ts +3 -1
  13. package/dist/src/codec/method-codec.js +27 -2
  14. package/dist/src/codec/script-codec.d.ts +11 -6
  15. package/dist/src/codec/script-codec.js +13 -2
  16. package/dist/src/codec/transaction-codec.js +2 -2
  17. package/dist/src/codec/unlock-script-codec.d.ts +2 -2
  18. package/dist/src/codec/unsigned-tx-codec.d.ts +2 -2
  19. package/dist/src/contract/contract.d.ts +23 -101
  20. package/dist/src/contract/contract.js +52 -538
  21. package/dist/src/contract/events.d.ts +1 -2
  22. package/dist/src/contract/events.js +28 -14
  23. package/dist/src/index.d.ts +1 -0
  24. package/dist/src/index.js +1 -0
  25. package/dist/src/signer/tx-builder.js +4 -4
  26. package/dist/src/transaction/index.d.ts +1 -0
  27. package/dist/src/transaction/index.js +1 -0
  28. package/dist/src/transaction/status.js +28 -4
  29. package/dist/src/transaction/utils.d.ts +2 -0
  30. package/dist/src/transaction/utils.js +34 -0
  31. package/dist/src/utils/address.js +29 -16
  32. package/dist/src/utils/exchange.js +25 -15
  33. package/dist/src/utils/number.d.ts +1 -1
  34. package/dist/src/utils/sign.js +6 -6
  35. package/dist/src/utils/subscription.d.ts +4 -4
  36. package/dist/src/utils/subscription.js +1 -1
  37. package/package.json +3 -3
  38. package/src/api/node-provider.ts +8 -1
  39. package/src/api/utils.ts +1 -1
  40. package/src/block/block.ts +139 -0
  41. package/src/block/index.ts +19 -0
  42. package/src/codec/contract-output-codec.ts +1 -1
  43. package/src/codec/lockup-script-codec.ts +3 -3
  44. package/src/codec/method-codec.ts +41 -3
  45. package/src/codec/script-codec.ts +23 -5
  46. package/src/codec/transaction-codec.ts +1 -1
  47. package/src/codec/unlock-script-codec.ts +2 -2
  48. package/src/codec/unsigned-tx-codec.ts +2 -2
  49. package/src/contract/contract.ts +72 -779
  50. package/src/contract/events.ts +6 -18
  51. package/src/index.ts +1 -0
  52. package/src/signer/tx-builder.ts +2 -2
  53. package/src/transaction/index.ts +1 -0
  54. package/src/transaction/status.ts +4 -4
  55. package/src/transaction/utils.ts +38 -0
  56. package/src/utils/address.ts +15 -2
  57. package/src/utils/exchange.ts +32 -10
  58. package/src/utils/number.ts +1 -1
  59. package/src/utils/sign.ts +1 -1
  60. package/src/utils/subscription.ts +4 -4
  61. package/std/fungible_token_interface.ral +1 -0
  62. package/std/nft_collection_interface.ral +1 -0
  63. package/std/nft_collection_with_royalty_interface.ral +1 -0
  64. package/std/nft_interface.ral +1 -0
  65. package/webpack.config.js +0 -1
  66. package/dist/src/utils/error.d.ts +0 -15
  67. package/dist/src/utils/error.js +0 -66
  68. package/src/utils/error.ts +0 -77
@@ -16,33 +16,24 @@ You should have received a copy of the GNU Lesser General Public License
16
16
  along with the library. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
 
19
- import { web3 } from '..'
19
+ import * as web3 from '../global'
20
20
  import { node } from '../api'
21
21
  import { Subscription, SubscribeOptions } from '../utils'
22
22
 
23
23
  export interface EventSubscribeOptions<Message> extends SubscribeOptions<Message> {
24
- onEventCountChanged?: (eventCount: number) => Promise<void>
24
+ onEventCountChanged?: (eventCount: number) => Promise<void> | void
25
25
  }
26
26
 
27
27
  export class EventSubscription extends Subscription<node.ContractEvent> {
28
28
  readonly contractAddress: string
29
29
  private fromCount: number
30
- private onEventCountChanged?: (eventCount: number) => Promise<void>
30
+ private onEventCountChanged?: (eventCount: number) => Promise<void> | void
31
31
 
32
32
  constructor(options: EventSubscribeOptions<node.ContractEvent>, contractAddress: string, fromCount?: number) {
33
33
  super(options)
34
34
  this.contractAddress = contractAddress
35
35
  this.fromCount = typeof fromCount === 'undefined' ? 0 : fromCount
36
36
  this.onEventCountChanged = options.onEventCountChanged
37
-
38
- this.startPolling()
39
- }
40
-
41
- override startPolling(): void {
42
- this.eventEmitter.on('tick', async () => {
43
- await this.polling()
44
- })
45
- this.eventEmitter.emit('tick')
46
37
  }
47
38
 
48
39
  currentEventCount(): number {
@@ -54,12 +45,7 @@ export class EventSubscription extends Subscription<node.ContractEvent> {
54
45
  const events = await web3.getCurrentNodeProvider().events.getEventsContractContractaddress(this.contractAddress, {
55
46
  start: this.fromCount
56
47
  })
57
- if (this.cancelled) {
58
- return
59
- }
60
-
61
48
  if (this.fromCount === events.nextStart) {
62
- this.task = setTimeout(() => this.eventEmitter.emit('tick'), this.pollingInterval)
63
49
  return
64
50
  }
65
51
 
@@ -83,5 +69,7 @@ export function subscribeToEvents(
83
69
  contractAddress: string,
84
70
  fromCount?: number
85
71
  ): EventSubscription {
86
- return new EventSubscription(options, contractAddress, fromCount)
72
+ const subscription = new EventSubscription(options, contractAddress, fromCount)
73
+ subscription.subscribe()
74
+ return subscription
87
75
  }
package/src/index.ts CHANGED
@@ -32,3 +32,4 @@ export * as web3 from './global'
32
32
  export * as codec from './codec'
33
33
  export * as utils from './utils'
34
34
  export * from './debug'
35
+ export * from './block'
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Lesser General Public License
16
16
  along with the library. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
 
19
- import { utils } from '..'
19
+ import { binToHex, contractIdFromAddress } from '../utils'
20
20
  import { fromApiNumber256, node, NodeProvider, toApiNumber256Optional, toApiTokens } from '../api'
21
21
  import { addressFromPublicKey } from '../utils'
22
22
  import { toApiDestinations } from './signer'
@@ -90,7 +90,7 @@ export abstract class TransactionBuilder {
90
90
  ...rest
91
91
  }
92
92
  const response = await this.nodeProvider.contracts.postContractsUnsignedTxDeployContract(data)
93
- const contractId = utils.binToHex(utils.contractIdFromAddress(response.contractAddress))
93
+ const contractId = binToHex(contractIdFromAddress(response.contractAddress))
94
94
  return { ...response, groupIndex: response.fromGroup, contractId, gasPrice: fromApiNumber256(response.gasPrice) }
95
95
  }
96
96
 
@@ -18,3 +18,4 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
18
 
19
19
  export * from './status'
20
20
  export * from './sign-verify'
21
+ export * from './utils'
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Lesser General Public License
16
16
  along with the library. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
 
19
- import { web3 } from '..'
19
+ import * as web3 from '../global'
20
20
  import { node } from '../api'
21
21
  import { Subscription, SubscribeOptions } from '../utils'
22
22
 
@@ -40,8 +40,6 @@ export class TxStatusSubscription extends Subscription<TxStatus> {
40
40
  this.fromGroup = fromGroup
41
41
  this.toGroup = toGroup
42
42
  this.confirmations = confirmations ?? 1
43
-
44
- this.startPolling()
45
43
  }
46
44
 
47
45
  override async polling(): Promise<void> {
@@ -69,5 +67,7 @@ export function subscribeToTxStatus(
69
67
  toGroup?: number,
70
68
  confirmations?: number
71
69
  ): TxStatusSubscription {
72
- return new TxStatusSubscription(options, txId, fromGroup, toGroup, confirmations)
70
+ const subscription = new TxStatusSubscription(options, txId, fromGroup, toGroup, confirmations)
71
+ subscription.subscribe()
72
+ return subscription
73
73
  }
@@ -0,0 +1,38 @@
1
+ /*
2
+ Copyright 2018 - 2022 The Alephium Authors
3
+ This file is part of the alephium project.
4
+
5
+ The library is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ The library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ import { node } from '../api'
20
+ import { getCurrentNodeProvider } from '../global'
21
+
22
+ function isConfirmed(txStatus: node.TxStatus): txStatus is node.Confirmed {
23
+ return txStatus.type === 'Confirmed'
24
+ }
25
+
26
+ export async function waitForTxConfirmation(
27
+ txId: string,
28
+ confirmations: number,
29
+ requestInterval: number
30
+ ): Promise<node.Confirmed> {
31
+ const provider = getCurrentNodeProvider()
32
+ const status = await provider.transactions.getTransactionsStatus({ txId: txId })
33
+ if (isConfirmed(status) && status.chainConfirmations >= confirmations) {
34
+ return status
35
+ }
36
+ await new Promise((r) => setTimeout(r, requestInterval))
37
+ return waitForTxConfirmation(txId, confirmations, requestInterval)
38
+ }
@@ -24,6 +24,9 @@ import bs58 from './bs58'
24
24
  import djb2 from './djb2'
25
25
  import { binToHex, hexToBinUnsafe } from './utils'
26
26
  import { KeyType } from '../signer'
27
+ import { MultiSig, lockupScriptCodec } from '../codec/lockup-script-codec'
28
+ import { Buffer } from 'buffer/'
29
+ import { compactSignedIntCodec } from '../codec'
27
30
 
28
31
  const ec = new EC('secp256k1')
29
32
 
@@ -49,8 +52,18 @@ function decodeAndValidateAddress(address: string): Uint8Array {
49
52
  if (decoded.length === 0) throw new Error('Address is empty')
50
53
  const addressType = decoded[0]
51
54
  if (addressType === AddressType.P2MPKH) {
52
- // [1, n, ...hashes, m]
53
- if ((decoded.length - 3) % 32 === 0) return decoded
55
+ let multisig: MultiSig
56
+ try {
57
+ multisig = lockupScriptCodec.decode(Buffer.from(decoded)).script as MultiSig
58
+ } catch (_) {
59
+ throw new Error(`Invalid multisig address: ${address}`)
60
+ }
61
+ const n = multisig.publicKeyHashes.value.length
62
+ const m = compactSignedIntCodec.toI32(multisig.m)
63
+ if (n < m) {
64
+ throw new Error(`Invalid multisig address, n: ${n}, m: ${m}`)
65
+ }
66
+ return decoded
54
67
  } else if (addressType === AddressType.P2PKH || addressType === AddressType.P2SH || addressType === AddressType.P2C) {
55
68
  // [type, ...hash]
56
69
  if (decoded.length === 33) return decoded
@@ -16,9 +16,20 @@ You should have received a copy of the GNU Lesser General Public License
16
16
  along with the library. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
 
19
- import { AddressType, addressFromPublicKey, addressFromScript, binToHex, bs58, hexToBinUnsafe } from '..'
19
+ import {
20
+ AddressType,
21
+ addressFromPublicKey,
22
+ addressFromScript,
23
+ binToHex,
24
+ bs58,
25
+ hexToBinUnsafe,
26
+ isHexString
27
+ } from '../utils'
20
28
  import { Transaction } from '../api/api-alephium'
21
29
  import { Address } from '../signer'
30
+ import { P2SH, unlockScriptCodec } from '../codec/unlock-script-codec'
31
+ import { Buffer } from 'buffer/'
32
+ import { scriptCodec } from '../codec/script-codec'
22
33
 
23
34
  export function validateExchangeAddress(address: string) {
24
35
  let decoded: Uint8Array
@@ -80,24 +91,35 @@ enum UnlockScriptType {
80
91
  }
81
92
 
82
93
  export function getAddressFromUnlockScript(unlockScript: string): Address {
94
+ if (!isHexString(unlockScript)) {
95
+ throw new Error(`Invalid unlock script ${unlockScript}, expected a hex string`)
96
+ }
83
97
  const decoded = hexToBinUnsafe(unlockScript)
84
98
  if (decoded.length === 0) throw new Error('UnlockScript is empty')
85
99
  const unlockScriptType = decoded[0]
86
100
  const unlockScriptBody = decoded.slice(1)
87
101
 
88
102
  if (unlockScriptType === UnlockScriptType.P2PKH) {
103
+ if (unlockScriptBody.length !== 33) {
104
+ throw new Error(`Invalid p2pkh unlock script: ${unlockScript}`)
105
+ }
89
106
  return addressFromPublicKey(binToHex(unlockScriptBody))
90
- } else if (unlockScriptType === UnlockScriptType.P2MPKH) {
107
+ }
108
+
109
+ if (unlockScriptType === UnlockScriptType.P2MPKH) {
91
110
  throw new Error('Naive multi-sig address is not supported for exchanges as it will be replaced by P2SH')
92
- } else if (unlockScriptType === UnlockScriptType.P2SH) {
93
- // FIXEME: for now we assume that the params is empty, so we need to
94
- // remove the last byte from the `unlockScriptBody`, we can decode
95
- // the unlock script once the codec PR is merged
96
- const script = unlockScriptBody.slice(0, -1)
97
- return addressFromScript(script)
98
- } else {
99
- throw new Error('Invalid unlock script type')
100
111
  }
112
+
113
+ if (unlockScriptType === UnlockScriptType.P2SH) {
114
+ let p2sh: P2SH
115
+ try {
116
+ p2sh = unlockScriptCodec.decode(Buffer.from(decoded)).script as P2SH
117
+ } catch (_) {
118
+ throw new Error(`Invalid p2sh unlock script: ${unlockScript}`)
119
+ }
120
+ return addressFromScript(scriptCodec.encode(p2sh.script))
121
+ }
122
+ throw new Error('Invalid unlock script type')
101
123
  }
102
124
 
103
125
  function checkALPHOutput(tx: Transaction): boolean {
@@ -21,7 +21,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
21
21
  // 2. https://github.com/ethers-io/ethers.js/blob/724881f34d428406488a1c9f9dbebe54b6edecda/src.ts/utils/fixednumber.ts
22
22
 
23
23
  import BigNumber from 'bignumber.js'
24
- import { Number256 } from '..'
24
+ import { Number256 } from '../api/types'
25
25
 
26
26
  export const isNumeric = (numToCheck: any): boolean => !isNaN(parseFloat(numToCheck)) && isFinite(numToCheck)
27
27
 
package/src/utils/sign.ts CHANGED
@@ -17,7 +17,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
 
19
19
  import { ec as EC } from 'elliptic'
20
- import { binToHex, encodeSignature, hexToBinUnsafe, signatureDecode } from '..'
20
+ import { binToHex, encodeSignature, hexToBinUnsafe, signatureDecode } from '../utils'
21
21
  import { KeyType } from '../signer'
22
22
  import * as necc from '@noble/secp256k1'
23
23
  import { createHash, createHmac } from 'crypto'
@@ -18,8 +18,8 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
18
 
19
19
  import EventEmitter from 'eventemitter3'
20
20
 
21
- type MessageCallback<Message> = (message: Message) => Promise<void>
22
- type ErrorCallback<Message> = (error: any, subscription: Subscription<Message>) => Promise<void>
21
+ type MessageCallback<Message> = (message: Message) => Promise<void> | void
22
+ type ErrorCallback<Message> = (error: any, subscription: Subscription<Message>) => Promise<void> | void
23
23
 
24
24
  export interface SubscribeOptions<Message> {
25
25
  pollingInterval: number
@@ -45,7 +45,7 @@ export abstract class Subscription<Message> {
45
45
  this.eventEmitter = new EventEmitter()
46
46
  }
47
47
 
48
- startPolling(): void {
48
+ subscribe(): void {
49
49
  this.eventEmitter.on('tick', async () => {
50
50
  await this.polling()
51
51
 
@@ -68,5 +68,5 @@ export abstract class Subscription<Message> {
68
68
  return this.cancelled
69
69
  }
70
70
 
71
- abstract polling(): Promise<void>
71
+ protected abstract polling(): Promise<void>
72
72
  }
@@ -1,4 +1,5 @@
1
1
  @std(id = #0001)
2
+ @using(methodSelector = false)
2
3
  Interface IFungibleToken {
3
4
  pub fn getSymbol() -> ByteVec
4
5
 
@@ -1,6 +1,7 @@
1
1
  import "std/nft_interface"
2
2
 
3
3
  @std(id = #0002)
4
+ @using(methodSelector = false)
4
5
  Interface INFTCollection {
5
6
  // Collection Uri points to a json file containing metadata for the NFT collection.
6
7
  //
@@ -1,6 +1,7 @@
1
1
  import "std/nft_collection_interface"
2
2
 
3
3
  @std(id = #000201)
4
+ @using(methodSelector = false)
4
5
  Interface INFTCollectionWithRoyalty extends INFTCollection {
5
6
  pub fn royaltyAmount(tokenId: ByteVec, salePrice: U256) -> (U256)
6
7
 
@@ -1,4 +1,5 @@
1
1
  @std(id = #0003)
2
+ @using(methodSelector = false)
2
3
  Interface INFT {
3
4
  // Token Uri points to a json file containing metadata for the NFT.
4
5
  //
package/webpack.config.js CHANGED
@@ -41,7 +41,6 @@ module.exports = {
41
41
  fs: false,
42
42
  stream: require.resolve('stream-browserify'),
43
43
  crypto: require.resolve('crypto-browserify'),
44
- path: require.resolve('path-browserify'),
45
44
  buffer: require.resolve('buffer/')
46
45
  }
47
46
  },
@@ -1,15 +0,0 @@
1
- declare class CompilationError {
2
- lineStart: number;
3
- column: number;
4
- errorType: string;
5
- line: number;
6
- codeLine: string;
7
- errorIndicator: string;
8
- message: string;
9
- additionalLine1?: string | undefined;
10
- additionalLine2?: string | undefined;
11
- constructor(lineStart: number, column: number, errorType: string, line: number, codeLine: string, errorIndicator: string, message: string, additionalLine1?: string | undefined, additionalLine2?: string | undefined);
12
- reformat(line: number, file: string): string;
13
- }
14
- export declare function parseError(error: string): CompilationError | undefined;
15
- export {};
@@ -1,66 +0,0 @@
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.parseError = void 0;
21
- class CompilationError {
22
- constructor(lineStart, column, errorType, line, codeLine, errorIndicator, message, additionalLine1, additionalLine2) {
23
- this.lineStart = lineStart;
24
- this.column = column;
25
- this.errorType = errorType;
26
- this.line = line;
27
- this.codeLine = codeLine;
28
- this.errorIndicator = errorIndicator;
29
- this.message = message;
30
- this.additionalLine1 = additionalLine1;
31
- this.additionalLine2 = additionalLine2;
32
- }
33
- reformat(line, file) {
34
- const spaces = `${line}`.replace(/\d/g, ' ');
35
- const newError = `${file} (${line}:${this.column}): ${this.errorType}
36
- ${line} |${this.codeLine}
37
- ${spaces} |${this.errorIndicator}
38
- ${spaces} |${this.message}`;
39
- if (this.additionalLine1 && this.additionalLine2) {
40
- return `${newError}\n${spaces} |${this.additionalLine1}\n${spaces} |${this.additionalLine2}`;
41
- }
42
- else {
43
- return newError;
44
- }
45
- }
46
- }
47
- const errorRegex = /error \((\d+):(\d+)\):\s*(.*)\n\s*(\d+)\s*\|(.*)\n.*\|(.*)\n\s*\|(.*)(?:\n\s*\|(.*)\n\s*\|(.*))?/;
48
- function parseError(error) {
49
- const match = error.match(errorRegex);
50
- if (match) {
51
- const lineStart = parseInt(match[1]);
52
- const column = parseInt(match[2]);
53
- const errorType = match[3];
54
- const line = parseInt(match[4]);
55
- const codeLine = match[5];
56
- const errorIndicator = match[6];
57
- const message = match[7];
58
- const additionalLine1 = match[8];
59
- const additionalLine2 = match[9];
60
- return new CompilationError(lineStart, column, errorType, line, codeLine, errorIndicator, message, additionalLine1, additionalLine2);
61
- }
62
- else {
63
- undefined;
64
- }
65
- }
66
- exports.parseError = parseError;
@@ -1,77 +0,0 @@
1
- /*
2
- Copyright 2018 - 2022 The Alephium Authors
3
- This file is part of the alephium project.
4
-
5
- The library is free software: you can redistribute it and/or modify
6
- it under the terms of the GNU Lesser General Public License as published by
7
- the Free Software Foundation, either version 3 of the License, or
8
- (at your option) any later version.
9
-
10
- The library is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- GNU Lesser General Public License for more details.
14
-
15
- You should have received a copy of the GNU Lesser General Public License
16
- along with the library. If not, see <http://www.gnu.org/licenses/>.
17
- */
18
-
19
- class CompilationError {
20
- constructor(
21
- public lineStart: number,
22
- public column: number,
23
- public errorType: string,
24
- public line: number,
25
- public codeLine: string,
26
- public errorIndicator: string,
27
- public message: string,
28
- public additionalLine1?: string,
29
- public additionalLine2?: string
30
- ) {}
31
-
32
- reformat(line: number, file: string): string {
33
- const spaces = `${line}`.replace(/\d/g, ' ')
34
- const newError = `${file} (${line}:${this.column}): ${this.errorType}
35
- ${line} |${this.codeLine}
36
- ${spaces} |${this.errorIndicator}
37
- ${spaces} |${this.message}`
38
-
39
- if (this.additionalLine1 && this.additionalLine2) {
40
- return `${newError}\n${spaces} |${this.additionalLine1}\n${spaces} |${this.additionalLine2}`
41
- } else {
42
- return newError
43
- }
44
- }
45
- }
46
-
47
- const errorRegex = /error \((\d+):(\d+)\):\s*(.*)\n\s*(\d+)\s*\|(.*)\n.*\|(.*)\n\s*\|(.*)(?:\n\s*\|(.*)\n\s*\|(.*))?/
48
-
49
- export function parseError(error: string): CompilationError | undefined {
50
- const match = error.match(errorRegex)
51
-
52
- if (match) {
53
- const lineStart = parseInt(match[1])
54
- const column = parseInt(match[2])
55
- const errorType = match[3]
56
- const line = parseInt(match[4])
57
- const codeLine = match[5]
58
- const errorIndicator = match[6]
59
- const message = match[7]
60
- const additionalLine1 = match[8]
61
- const additionalLine2 = match[9]
62
-
63
- return new CompilationError(
64
- lineStart,
65
- column,
66
- errorType,
67
- line,
68
- codeLine,
69
- errorIndicator,
70
- message,
71
- additionalLine1,
72
- additionalLine2
73
- )
74
- } else {
75
- undefined
76
- }
77
- }