sol2uml 2.2.0 → 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 +5 -3
- package/lib/converterAST2Classes.js +17 -3
- package/lib/converterClass2Dot.js +3 -2
- package/lib/parserEtherscan.d.ts +1 -0
- package/lib/parserEtherscan.js +10 -3
- package/lib/sol2uml.js +6 -4
- package/lib/umlClass.d.ts +2 -1
- package/lib/umlClass.js +1 -0
- package/lib/utils/regEx.d.ts +1 -0
- package/lib/utils/regEx.js +9 -1
- package/package.json +2 -1
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.
|
|
141
|
-
2.
|
|
142
|
-
3.
|
|
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
|
|
|
@@ -158,9 +158,23 @@ function convertAST2UmlClasses(node, relativePath, filesystem = false) {
|
|
|
158
158
|
else {
|
|
159
159
|
throw new Error(`AST node not of type SourceUnit`);
|
|
160
160
|
}
|
|
161
|
-
umlClasses.
|
|
162
|
-
umlClass
|
|
163
|
-
|
|
161
|
+
if (umlClasses.length > 0) {
|
|
162
|
+
umlClasses.forEach((umlClass) => {
|
|
163
|
+
umlClass.imports = imports;
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
const importUmlClass = new umlClass_1.UmlClass({
|
|
168
|
+
name: 'Import',
|
|
169
|
+
stereotype: umlClass_1.ClassStereotype.Import,
|
|
170
|
+
absolutePath: filesystem
|
|
171
|
+
? path.resolve(relativePath) // resolve the absolute path
|
|
172
|
+
: relativePath,
|
|
173
|
+
relativePath,
|
|
174
|
+
});
|
|
175
|
+
importUmlClass.imports = imports;
|
|
176
|
+
umlClasses = [importUmlClass];
|
|
177
|
+
}
|
|
164
178
|
return umlClasses;
|
|
165
179
|
}
|
|
166
180
|
exports.convertAST2UmlClasses = convertAST2UmlClasses;
|
|
@@ -6,8 +6,9 @@ const umlClass_1 = require("./umlClass");
|
|
|
6
6
|
const regEx_1 = require("./utils/regEx");
|
|
7
7
|
const convertClass2Dot = (umlClass, options = {}) => {
|
|
8
8
|
// do not include library, interface, abstracts, struct or enum classes if hidden
|
|
9
|
-
if (
|
|
10
|
-
|
|
9
|
+
if (umlClass.stereotype === umlClass_1.ClassStereotype.Import ||
|
|
10
|
+
(options.hideLibraries &&
|
|
11
|
+
umlClass.stereotype === umlClass_1.ClassStereotype.Library) ||
|
|
11
12
|
(options.hideInterfaces &&
|
|
12
13
|
umlClass.stereotype === umlClass_1.ClassStereotype.Interface) ||
|
|
13
14
|
(options.hideAbstracts &&
|
package/lib/parserEtherscan.d.ts
CHANGED
package/lib/parserEtherscan.js
CHANGED
|
@@ -8,6 +8,8 @@ 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");
|
|
12
|
+
require('axios-debug-log');
|
|
11
13
|
const debug = require('debug')('sol2uml');
|
|
12
14
|
exports.networks = [
|
|
13
15
|
'mainnet',
|
|
@@ -122,7 +124,7 @@ class EtherscanParser {
|
|
|
122
124
|
* @return Promise string of Solidity code
|
|
123
125
|
*/
|
|
124
126
|
async getSolidityCode(contractAddress) {
|
|
125
|
-
const { files, contractName } = await this.getSourceCode(contractAddress);
|
|
127
|
+
const { files, contractName, compilerVersion } = await this.getSourceCode(contractAddress);
|
|
126
128
|
// Parse the UmlClasses from the Solidity code in each file
|
|
127
129
|
let umlClasses = [];
|
|
128
130
|
for (const file of files) {
|
|
@@ -139,7 +141,9 @@ class EtherscanParser {
|
|
|
139
141
|
// find any files that didn't have dependencies found
|
|
140
142
|
const nonDependentFiles = files.filter((f) => !dependentFilenames.includes(f.filename));
|
|
141
143
|
const nonDependentFilenames = nonDependentFiles.map((f) => f.filename);
|
|
142
|
-
|
|
144
|
+
debug(`Failed to find dependencies to files: ${nonDependentFilenames}`);
|
|
145
|
+
const solidityVersion = (0, regEx_1.parseSolidityVersion)(compilerVersion);
|
|
146
|
+
let solidityCode = `pragma solidity = ${solidityVersion};\n`;
|
|
143
147
|
// output non dependent code before the dependent files just in case sol2uml missed some dependencies
|
|
144
148
|
const filenames = [...nonDependentFilenames, ...dependentFilenames];
|
|
145
149
|
// For each filename
|
|
@@ -148,11 +152,13 @@ class EtherscanParser {
|
|
|
148
152
|
const file = files.find((f) => f.filename === filename);
|
|
149
153
|
if (!file)
|
|
150
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 */');
|
|
151
157
|
// comment out any import statements
|
|
152
158
|
// match whitespace before import
|
|
153
159
|
// and characters after import up to ;
|
|
154
160
|
// replace all in file and match across multiple lines
|
|
155
|
-
const removedImports =
|
|
161
|
+
const removedImports = removedPragmaSolidity.replace(/(\s)(import.*;)/gm, '$1/* $2 */');
|
|
156
162
|
// Rename SPDX-License-Identifier to SPDX--License-Identifier so the merged file will compile
|
|
157
163
|
const removedSPDX = removedImports.replace(/SPDX-/, 'SPDX--');
|
|
158
164
|
solidityCode += removedSPDX;
|
|
@@ -239,6 +245,7 @@ class EtherscanParser {
|
|
|
239
245
|
return {
|
|
240
246
|
files: results.flat(1),
|
|
241
247
|
contractName: response.data.result[0].ContractName,
|
|
248
|
+
compilerVersion: response.data.result[0].CompilerVersion,
|
|
242
249
|
};
|
|
243
250
|
}
|
|
244
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.
|
|
160
|
-
2.
|
|
161
|
-
3.
|
|
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 {
|
|
@@ -179,7 +181,7 @@ In order for the merged code to compile, the following is done:
|
|
|
179
181
|
}
|
|
180
182
|
});
|
|
181
183
|
program.on('option:verbose', () => {
|
|
182
|
-
debugControl.enable('sol2uml');
|
|
184
|
+
debugControl.enable('sol2uml,axios');
|
|
183
185
|
debug('verbose on');
|
|
184
186
|
});
|
|
185
187
|
const main = async () => {
|
package/lib/umlClass.d.ts
CHANGED
package/lib/umlClass.js
CHANGED
|
@@ -19,6 +19,7 @@ var ClassStereotype;
|
|
|
19
19
|
ClassStereotype[ClassStereotype["Struct"] = 5] = "Struct";
|
|
20
20
|
ClassStereotype[ClassStereotype["Enum"] = 6] = "Enum";
|
|
21
21
|
ClassStereotype[ClassStereotype["Constant"] = 7] = "Constant";
|
|
22
|
+
ClassStereotype[ClassStereotype["Import"] = 8] = "Import";
|
|
22
23
|
})(ClassStereotype = exports.ClassStereotype || (exports.ClassStereotype = {}));
|
|
23
24
|
var OperatorStereotype;
|
|
24
25
|
(function (OperatorStereotype) {
|
package/lib/utils/regEx.d.ts
CHANGED
package/lib/utils/regEx.js
CHANGED
|
@@ -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.
|
|
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",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"@aduh95/viz.js": "^3.7.0",
|
|
23
23
|
"@solidity-parser/parser": "^0.14.3",
|
|
24
24
|
"axios": "^0.27.2",
|
|
25
|
+
"axios-debug-log": "^0.8.4",
|
|
25
26
|
"commander": "^9.4.0",
|
|
26
27
|
"convert-svg-to-png": "^0.6.4",
|
|
27
28
|
"debug": "^4.3.4",
|