sol2uml 2.2.1 → 2.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.
package/README.md CHANGED
@@ -137,9 +137,11 @@ Options:
137
137
  Usage: sol2uml flatten <contractAddress> [options]
138
138
 
139
139
  In order for the merged code to compile, the following is done:
140
- 1. File imports are commented out.
141
- 2. "SPDX-License-Identifier" is renamed to "SPDX--License-Identifier".
142
- 3. Contract dependencies are analysed so the files are merged in an order that will compile.
140
+ 1. pragma solidity is set using the compiler of the verified contract.
141
+ 2. All pragma solidity lines in the source files are commented out.
142
+ 3. File imports are commented out.
143
+ 4. "SPDX-License-Identifier" is renamed to "SPDX--License-Identifier".
144
+ 5. Contract dependencies are analysed so the files are merged in an order that will compile.
143
145
 
144
146
  Merges verified source files for a contract from a Blockchain explorer into one local file.
145
147
 
@@ -42,6 +42,7 @@ export declare class EtherscanParser {
42
42
  filename: string;
43
43
  }[];
44
44
  contractName: string;
45
+ compilerVersion: string;
45
46
  }>;
46
47
  }
47
48
  export {};
@@ -8,6 +8,7 @@ const axios_1 = __importDefault(require("axios"));
8
8
  const parser_1 = require("@solidity-parser/parser");
9
9
  const converterAST2Classes_1 = require("./converterAST2Classes");
10
10
  const filterClasses_1 = require("./filterClasses");
11
+ const regEx_1 = require("./utils/regEx");
11
12
  require('axios-debug-log');
12
13
  const debug = require('debug')('sol2uml');
13
14
  exports.networks = [
@@ -123,7 +124,7 @@ class EtherscanParser {
123
124
  * @return Promise string of Solidity code
124
125
  */
125
126
  async getSolidityCode(contractAddress) {
126
- const { files, contractName } = await this.getSourceCode(contractAddress);
127
+ const { files, contractName, compilerVersion } = await this.getSourceCode(contractAddress);
127
128
  // Parse the UmlClasses from the Solidity code in each file
128
129
  let umlClasses = [];
129
130
  for (const file of files) {
@@ -141,7 +142,8 @@ class EtherscanParser {
141
142
  const nonDependentFiles = files.filter((f) => !dependentFilenames.includes(f.filename));
142
143
  const nonDependentFilenames = nonDependentFiles.map((f) => f.filename);
143
144
  debug(`Failed to find dependencies to files: ${nonDependentFilenames}`);
144
- let solidityCode = '';
145
+ const solidityVersion = (0, regEx_1.parseSolidityVersion)(compilerVersion);
146
+ let solidityCode = `pragma solidity = ${solidityVersion};\n`;
145
147
  // output non dependent code before the dependent files just in case sol2uml missed some dependencies
146
148
  const filenames = [...nonDependentFilenames, ...dependentFilenames];
147
149
  // For each filename
@@ -150,11 +152,13 @@ class EtherscanParser {
150
152
  const file = files.find((f) => f.filename === filename);
151
153
  if (!file)
152
154
  throw Error(`Failed to find file with filename "${filename}"`);
155
+ // comment out any pragma solidity lines as its set from the compiler version
156
+ const removedPragmaSolidity = file.code.replace(/(\s)(pragma\s+solidity.*;)/gm, '$1/* $2 */');
153
157
  // comment out any import statements
154
158
  // match whitespace before import
155
159
  // and characters after import up to ;
156
160
  // replace all in file and match across multiple lines
157
- const removedImports = file.code.replace(/(\s)(import.*;)/gm, '$1/* $2 */');
161
+ const removedImports = removedPragmaSolidity.replace(/(\s)(import.*;)/gm, '$1/* $2 */');
158
162
  // Rename SPDX-License-Identifier to SPDX--License-Identifier so the merged file will compile
159
163
  const removedSPDX = removedImports.replace(/SPDX-/, 'SPDX--');
160
164
  solidityCode += removedSPDX;
@@ -241,6 +245,7 @@ class EtherscanParser {
241
245
  return {
242
246
  files: results.flat(1),
243
247
  contractName: response.data.result[0].ContractName,
248
+ compilerVersion: response.data.result[0].CompilerVersion,
244
249
  };
245
250
  }
246
251
  catch (err) {
package/lib/sol2uml.js CHANGED
@@ -156,9 +156,11 @@ program
156
156
  .usage(`<contractAddress> [options]
157
157
 
158
158
  In order for the merged code to compile, the following is done:
159
- 1. File imports are commented out.
160
- 2. "SPDX-License-Identifier" is renamed to "SPDX--License-Identifier".
161
- 3. Contract dependencies are analysed so the files are merged in an order that will compile.`)
159
+ 1. pragma solidity is set using the compiler of the verified contract.
160
+ 2. All pragma solidity lines in the source files are commented out.
161
+ 3. File imports are commented out.
162
+ 4. "SPDX-License-Identifier" is renamed to "SPDX--License-Identifier".
163
+ 5. Contract dependencies are analysed so the files are merged in an order that will compile.`)
162
164
  .argument('<contractAddress>', 'Contract address in hexadecimal format with a 0x prefix.')
163
165
  .action(async (contractAddress, options, command) => {
164
166
  try {
@@ -1 +1,2 @@
1
1
  export declare const isAddress: (input: string) => boolean;
2
+ export declare const parseSolidityVersion: (compilerVersion: string) => string;
@@ -1,8 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isAddress = void 0;
3
+ exports.parseSolidityVersion = exports.isAddress = void 0;
4
4
  const isAddress = (input) => {
5
5
  return input.match(/^0x([A-Fa-f0-9]{40})$/) !== null;
6
6
  };
7
7
  exports.isAddress = isAddress;
8
+ const parseSolidityVersion = (compilerVersion) => {
9
+ const result = compilerVersion.match(`v(\\d+.\\d+.\\d+)`);
10
+ if (result[1]) {
11
+ return result[1];
12
+ }
13
+ throw Error(`Failed to parse compiler version ${compilerVersion}`);
14
+ };
15
+ exports.parseSolidityVersion = parseSolidityVersion;
8
16
  //# sourceMappingURL=regEx.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sol2uml",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "Solidity contract visualisation tool.",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",