sol2uml 2.4.2 → 2.4.3
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/LICENSE +1 -1
- package/lib/converterClasses2Storage.d.ts +13 -3
- package/lib/converterClasses2Storage.js +11 -2
- package/lib/slotValues.d.ts +17 -1
- package/lib/slotValues.js +24 -8
- package/lib/sol2uml.js +3 -3
- package/lib/writerFiles.d.ts +21 -1
- package/lib/writerFiles.js +21 -1
- package/package.json +5 -5
package/LICENSE
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Attribute, UmlClass } from './umlClass';
|
|
2
|
+
import { BigNumberish } from '@ethersproject/bignumber';
|
|
2
3
|
export declare enum StorageType {
|
|
3
4
|
Contract = "Contract",
|
|
4
5
|
Struct = "Struct",
|
|
@@ -31,11 +32,20 @@ export interface Storage {
|
|
|
31
32
|
}
|
|
32
33
|
/**
|
|
33
34
|
*
|
|
34
|
-
* @param url
|
|
35
|
-
* @param contractAddress Contract address to get the storage slot values from
|
|
35
|
+
* @param url of Ethereum JSON-RPC API provider. eg Infura or Alchemy
|
|
36
|
+
* @param contractAddress Contract address to get the storage slot values from.
|
|
37
|
+
* If proxied, use proxy and not the implementation contract.
|
|
36
38
|
* @param storage is mutated with the storage values
|
|
39
|
+
* @param blockTag block number or `latest`
|
|
40
|
+
*/
|
|
41
|
+
export declare const addStorageValues: (url: string, contractAddress: string, storage: Storage, blockTag?: BigNumberish | 'latest') => Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @param contractName name of the contract to get storage layout.
|
|
45
|
+
* @param umlClasses array of UML classes of type `UMLClass`
|
|
46
|
+
* @param contractFilename relative path of the contract in the file system
|
|
47
|
+
* @return array of storage objects with consecutive slots
|
|
37
48
|
*/
|
|
38
|
-
export declare const addStorageValues: (url: string, contractAddress: string, storage: Storage, blockTag: string) => Promise<void>;
|
|
39
49
|
export declare const convertClasses2Storages: (contractName: string, umlClasses: UmlClass[], contractFilename?: string) => Storage[];
|
|
40
50
|
export declare const parseReferenceStorage: (attribute: Attribute, umlClass: UmlClass, otherClasses: UmlClass[], storages: Storage[]) => Storage | undefined;
|
|
41
51
|
export declare const calcStorageByteSize: (attribute: Attribute, umlClass: UmlClass, otherClasses: UmlClass[]) => {
|
|
@@ -21,9 +21,11 @@ let storageId = 1;
|
|
|
21
21
|
let variableId = 1;
|
|
22
22
|
/**
|
|
23
23
|
*
|
|
24
|
-
* @param url
|
|
25
|
-
* @param contractAddress Contract address to get the storage slot values from
|
|
24
|
+
* @param url of Ethereum JSON-RPC API provider. eg Infura or Alchemy
|
|
25
|
+
* @param contractAddress Contract address to get the storage slot values from.
|
|
26
|
+
* If proxied, use proxy and not the implementation contract.
|
|
26
27
|
* @param storage is mutated with the storage values
|
|
28
|
+
* @param blockTag block number or `latest`
|
|
27
29
|
*/
|
|
28
30
|
const addStorageValues = async (url, contractAddress, storage, blockTag) => {
|
|
29
31
|
const valueVariables = storage.variables.filter((s) => !s.noValue);
|
|
@@ -34,6 +36,13 @@ const addStorageValues = async (url, contractAddress, storage, blockTag) => {
|
|
|
34
36
|
});
|
|
35
37
|
};
|
|
36
38
|
exports.addStorageValues = addStorageValues;
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @param contractName name of the contract to get storage layout.
|
|
42
|
+
* @param umlClasses array of UML classes of type `UMLClass`
|
|
43
|
+
* @param contractFilename relative path of the contract in the file system
|
|
44
|
+
* @return array of storage objects with consecutive slots
|
|
45
|
+
*/
|
|
37
46
|
const convertClasses2Storages = (contractName, umlClasses, contractFilename) => {
|
|
38
47
|
// Find the base UML Class from the base contract name
|
|
39
48
|
const umlClass = umlClasses.find(({ name, relativePath }) => {
|
package/lib/slotValues.d.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
1
|
import { BigNumberish } from '@ethersproject/bignumber';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Get storage slot values from JSON-RPC API provider.
|
|
4
|
+
* @param url of Ethereum JSON-RPC API provider. eg Infura or Alchemy
|
|
5
|
+
* @param contractAddress Contract address to get the storage slot values from.
|
|
6
|
+
* If proxied, use proxy and not the implementation contract.
|
|
7
|
+
* @param slots array of slot numbers to retrieve values for.
|
|
8
|
+
* @param blockTag block number or `latest`
|
|
9
|
+
*/
|
|
3
10
|
export declare const getStorageValues: (url: string, contractAddress: string, slots: BigNumberish[], blockTag?: BigNumberish | 'latest') => Promise<string[]>;
|
|
11
|
+
/**
|
|
12
|
+
* Get storage slot values from JSON-RPC API provider.
|
|
13
|
+
* @param url of Ethereum JSON-RPC API provider. eg Infura or Alchemy
|
|
14
|
+
* @param contractAddress Contract address to get the storage slot values from.
|
|
15
|
+
* If proxied, use proxy and not the implementation contract.
|
|
16
|
+
* @param slot slot number to retrieve the value for.
|
|
17
|
+
* @param blockTag block number or `latest`
|
|
18
|
+
*/
|
|
19
|
+
export declare const getStorageValue: (url: string, contractAddress: string, slot: BigNumberish, blockTag?: BigNumberish | 'latest') => Promise<string>;
|
package/lib/slotValues.js
CHANGED
|
@@ -3,18 +3,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.getStorageValue = exports.getStorageValues = void 0;
|
|
7
7
|
const bignumber_1 = require("@ethersproject/bignumber");
|
|
8
8
|
const axios_1 = __importDefault(require("axios"));
|
|
9
9
|
const debug = require('debug')('sol2uml');
|
|
10
|
-
const getStorageValue = async (url, contractAddress, slot, blockTag = 'latest') => {
|
|
11
|
-
debug(`About to get storage slot ${slot} value for ${contractAddress}`);
|
|
12
|
-
const values = await (0, exports.getStorageValues)(url, contractAddress, [slot], blockTag);
|
|
13
|
-
debug(`Got slot ${slot} value: ${values[0]}`);
|
|
14
|
-
return values[0];
|
|
15
|
-
};
|
|
16
|
-
exports.getStorageValue = getStorageValue;
|
|
17
10
|
let jsonRpcId = 0;
|
|
11
|
+
/**
|
|
12
|
+
* Get storage slot values from JSON-RPC API provider.
|
|
13
|
+
* @param url of Ethereum JSON-RPC API provider. eg Infura or Alchemy
|
|
14
|
+
* @param contractAddress Contract address to get the storage slot values from.
|
|
15
|
+
* If proxied, use proxy and not the implementation contract.
|
|
16
|
+
* @param slots array of slot numbers to retrieve values for.
|
|
17
|
+
* @param blockTag block number or `latest`
|
|
18
|
+
*/
|
|
18
19
|
const getStorageValues = async (url, contractAddress, slots, blockTag = 'latest') => {
|
|
19
20
|
try {
|
|
20
21
|
debug(`About to get ${slots.length} storage values for ${contractAddress} at block ${blockTag}`);
|
|
@@ -48,4 +49,19 @@ const getStorageValues = async (url, contractAddress, slots, blockTag = 'latest'
|
|
|
48
49
|
}
|
|
49
50
|
};
|
|
50
51
|
exports.getStorageValues = getStorageValues;
|
|
52
|
+
/**
|
|
53
|
+
* Get storage slot values from JSON-RPC API provider.
|
|
54
|
+
* @param url of Ethereum JSON-RPC API provider. eg Infura or Alchemy
|
|
55
|
+
* @param contractAddress Contract address to get the storage slot values from.
|
|
56
|
+
* If proxied, use proxy and not the implementation contract.
|
|
57
|
+
* @param slot slot number to retrieve the value for.
|
|
58
|
+
* @param blockTag block number or `latest`
|
|
59
|
+
*/
|
|
60
|
+
const getStorageValue = async (url, contractAddress, slot, blockTag = 'latest') => {
|
|
61
|
+
debug(`About to get storage slot ${slot} value for ${contractAddress}`);
|
|
62
|
+
const values = await (0, exports.getStorageValues)(url, contractAddress, [slot], blockTag);
|
|
63
|
+
debug(`Got slot ${slot} value: ${values[0]}`);
|
|
64
|
+
return values[0];
|
|
65
|
+
};
|
|
66
|
+
exports.getStorageValue = getStorageValue;
|
|
51
67
|
//# sourceMappingURL=slotValues.js.map
|
package/lib/sol2uml.js
CHANGED
|
@@ -103,7 +103,7 @@ If an Ethereum address with a 0x prefix is passed, the verified source code from
|
|
|
103
103
|
// Convert UML classes to Graphviz dot format.
|
|
104
104
|
const dotString = (0, converterClasses2Dot_1.convertUmlClasses2Dot)(filteredUmlClasses, combinedOptions.clusterFolders, combinedOptions);
|
|
105
105
|
// Convert Graphviz dot format to file formats. eg svg or png
|
|
106
|
-
await (0, writerFiles_1.writeOutputFiles)(dotString,
|
|
106
|
+
await (0, writerFiles_1.writeOutputFiles)(dotString, contractName || 'classDiagram', combinedOptions.outputFormat, combinedOptions.outputFileName);
|
|
107
107
|
debug(`Finished generating UML`);
|
|
108
108
|
}
|
|
109
109
|
catch (err) {
|
|
@@ -160,10 +160,10 @@ WARNING: sol2uml does not use the Solidity compiler so may differ with solc. A k
|
|
|
160
160
|
const storage = storages.find((so) => so.name === contractName);
|
|
161
161
|
if (!storageAddress)
|
|
162
162
|
throw Error(`Could not find the "${contractName}" contract in list of parsed storages`);
|
|
163
|
-
await (0, converterClasses2Storage_1.addStorageValues)(combinedOptions.url, storageAddress, storage, combinedOptions.
|
|
163
|
+
await (0, converterClasses2Storage_1.addStorageValues)(combinedOptions.url, storageAddress, storage, combinedOptions.block);
|
|
164
164
|
}
|
|
165
165
|
const dotString = (0, converterStorage2Dot_1.convertStorages2Dot)(storages, combinedOptions);
|
|
166
|
-
await (0, writerFiles_1.writeOutputFiles)(dotString,
|
|
166
|
+
await (0, writerFiles_1.writeOutputFiles)(dotString, contractName || 'storageDiagram', combinedOptions.outputFormat, combinedOptions.outputFileName);
|
|
167
167
|
}
|
|
168
168
|
catch (err) {
|
|
169
169
|
console.error(err.stack);
|
package/lib/writerFiles.d.ts
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
1
1
|
export type OutputFormats = 'svg' | 'png' | 'dot' | 'all';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Writes output files to the file system based on the provided input and options.
|
|
4
|
+
* @param dot The input string in DOT format.
|
|
5
|
+
* @param contractName The name of the contract.
|
|
6
|
+
* @param outputFormat The format of the output file. choices: svg, png, dot or all. default: png
|
|
7
|
+
* @param outputFilename optional filename of the output file.
|
|
8
|
+
*/
|
|
9
|
+
export declare const writeOutputFiles: (dot: string, contractName: string, outputFormat?: OutputFormats, outputFilename?: string) => Promise<void>;
|
|
3
10
|
export declare function convertDot2Svg(dot: string): any;
|
|
4
11
|
export declare function writeSolidity(code: string, filename?: string): void;
|
|
5
12
|
export declare function writeDot(dot: string, filename: string): void;
|
|
13
|
+
/**
|
|
14
|
+
* Writes an SVG file to the file system.
|
|
15
|
+
* @param svg The SVG input to be written to the file system.
|
|
16
|
+
* @param svgFilename The desired file name for the SVG file. default: classDiagram.svg
|
|
17
|
+
* @param outputFormats The format of the output file. choices: svg, png, dot or all. default: png
|
|
18
|
+
* @throws Error - If there is an error writing the SVG file.
|
|
19
|
+
*/
|
|
6
20
|
export declare function writeSVG(svg: any, svgFilename?: string, outputFormats?: OutputFormats): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Asynchronously writes a PNG file to the file system from an SVG input.
|
|
23
|
+
* @param svg - The SVG input to be converted to a PNG file.
|
|
24
|
+
* @param filename - The desired file name for the PNG file.
|
|
25
|
+
* @throws Error - If there is an error converting or writing the PNG file.
|
|
26
|
+
*/
|
|
7
27
|
export declare function writePng(svg: any, filename: string): Promise<void>;
|
package/lib/writerFiles.js
CHANGED
|
@@ -9,7 +9,14 @@ const path_1 = __importDefault(require("path"));
|
|
|
9
9
|
const sync_1 = __importDefault(require("@aduh95/viz.js/sync"));
|
|
10
10
|
const { convert } = require('convert-svg-to-png');
|
|
11
11
|
const debug = require('debug')('sol2uml');
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Writes output files to the file system based on the provided input and options.
|
|
14
|
+
* @param dot The input string in DOT format.
|
|
15
|
+
* @param contractName The name of the contract.
|
|
16
|
+
* @param outputFormat The format of the output file. choices: svg, png, dot or all. default: png
|
|
17
|
+
* @param outputFilename optional filename of the output file.
|
|
18
|
+
*/
|
|
19
|
+
const writeOutputFiles = async (dot, contractName, outputFormat = 'svg', outputFilename) => {
|
|
13
20
|
// If all output then extension is svg
|
|
14
21
|
const outputExt = outputFormat === 'all' ? 'svg' : outputFormat;
|
|
15
22
|
if (!outputFilename) {
|
|
@@ -87,6 +94,13 @@ function writeDot(dot, filename) {
|
|
|
87
94
|
});
|
|
88
95
|
}
|
|
89
96
|
exports.writeDot = writeDot;
|
|
97
|
+
/**
|
|
98
|
+
* Writes an SVG file to the file system.
|
|
99
|
+
* @param svg The SVG input to be written to the file system.
|
|
100
|
+
* @param svgFilename The desired file name for the SVG file. default: classDiagram.svg
|
|
101
|
+
* @param outputFormats The format of the output file. choices: svg, png, dot or all. default: png
|
|
102
|
+
* @throws Error - If there is an error writing the SVG file.
|
|
103
|
+
*/
|
|
90
104
|
function writeSVG(svg, svgFilename = 'classDiagram.svg', outputFormats = 'png') {
|
|
91
105
|
debug(`About to write SVN file to ${svgFilename}`);
|
|
92
106
|
if (outputFormats === 'png') {
|
|
@@ -113,6 +127,12 @@ function writeSVG(svg, svgFilename = 'classDiagram.svg', outputFormats = 'png')
|
|
|
113
127
|
});
|
|
114
128
|
}
|
|
115
129
|
exports.writeSVG = writeSVG;
|
|
130
|
+
/**
|
|
131
|
+
* Asynchronously writes a PNG file to the file system from an SVG input.
|
|
132
|
+
* @param svg - The SVG input to be converted to a PNG file.
|
|
133
|
+
* @param filename - The desired file name for the PNG file.
|
|
134
|
+
* @throws Error - If there is an error converting or writing the PNG file.
|
|
135
|
+
*/
|
|
116
136
|
async function writePng(svg, filename) {
|
|
117
137
|
// get svg file name from png file name
|
|
118
138
|
const parsedPngFile = path_1.default.parse(filename);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sol2uml",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.3",
|
|
4
4
|
"description": "Solidity contract visualisation tool.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@openzeppelin/contracts": "4.8.0",
|
|
37
37
|
"@types/diff-match-patch": "^1.0.32",
|
|
38
|
-
"@types/jest": "^29.
|
|
38
|
+
"@types/jest": "^29.4.0",
|
|
39
39
|
"@types/klaw": "^3.0.3",
|
|
40
|
-
"jest": "^29.
|
|
41
|
-
"prettier": "^2.8.
|
|
42
|
-
"ts-jest": "^29.0.
|
|
40
|
+
"jest": "^29.4.1",
|
|
41
|
+
"prettier": "^2.8.3",
|
|
42
|
+
"ts-jest": "^29.0.5",
|
|
43
43
|
"ts-node": "^10.9.1",
|
|
44
44
|
"typescript": "^4.9.4"
|
|
45
45
|
},
|