sol2uml 2.5.15 → 2.5.17

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
@@ -57,7 +57,7 @@ Options:
57
57
  -f, --outputFormat <value> output file format. (choices: "svg", "png", "dot", "all", default: "svg")
58
58
  -o, --outputFileName <value> output file name
59
59
  -i, --ignoreFilesOrFolders <names> comma-separated list of files or folders to ignore
60
- -n, --network <network> Ethereum network which maps to a blockchain explorer (choices: "mainnet", "goerli", "sepolia", "polygon", "arbitrum", "avalanche", "bsc", "crono", "fantom", "moonbeam", "optimism", "gnosis", "celo", "base", default: "mainnet", env: ETH_NETWORK)
60
+ -n, --network <network> Ethereum network which maps to a blockchain explorer (choices: "mainnet", "goerli", "sepolia", "polygon", "arbitrum", "avalanche", "bsc", "crono", "fantom", "moonbeam", "optimism", "gnosis", "celo", "scroll", "base", default: "mainnet", env: ETH_NETWORK)
61
61
  -e, --explorerUrl <url> Override the `network` option with a custom blockchain explorer API URL. eg Polygon Mumbai testnet https://api-testnet.polygonscan.com/api (env: EXPLORER_URL)
62
62
  -k, --apiKey <key> Blockchain explorer API key. eg Etherscan, Arbiscan, Optimism, BscScan, CronoScan, FTMScan, PolygonScan or SnowTrace API key (env: SCAN_API_KEY)
63
63
  -bc, --backColor <color> Canvas background color. "none" will use a transparent canvas. (default: "white")
@@ -28,7 +28,7 @@ const compareVerified2Local = async (addressA, aEtherscanParser, fileOrBaseFolde
28
28
  if (!options.summary) {
29
29
  (0, exports.displayFileDiffs)(files, options);
30
30
  }
31
- const aFileDesc = `"${options.aFile}" file for the `;
31
+ const aFileDesc = options.aFile ? `"${options.aFile}" file with the ` : '';
32
32
  console.log(`Compared the ${aFileDesc}"${contractNameA}" contract with address ${addressA} on ${options.network}`);
33
33
  if (local) {
34
34
  console.log(`to local file "${fileOrBaseFolders}"\n`);
@@ -49,7 +49,7 @@ const compareFlattenContracts = async (addressA, addressB, aEtherscanParser, bEt
49
49
  await (0, writerFiles_1.writeSourceCode)(codeB, addressB);
50
50
  }
51
51
  if (options.bFile || options.aFile) {
52
- console.log(`Compared the "${options.aFile}" file for the "${contractNameA}" contract with address ${addressA} on ${options.network}`);
52
+ console.log(`Compared the "${options.aFile}" file with the "${contractNameA}" contract with address ${addressA} on ${options.network}`);
53
53
  console.log(`to the "${options.bFile || options.aFile}" file for the "${contractNameB}" contract with address ${addressB} on ${options.bNetwork || options.network}\n`);
54
54
  }
55
55
  else {
@@ -4,7 +4,7 @@ export interface Remapping {
4
4
  from: RegExp;
5
5
  to: string;
6
6
  }
7
- export declare const networks: readonly ["mainnet", "goerli", "sepolia", "polygon", "arbitrum", "avalanche", "bsc", "crono", "fantom", "moonbeam", "optimism", "gnosis", "celo", "base"];
7
+ export declare const networks: readonly ["mainnet", "goerli", "sepolia", "polygon", "arbitrum", "avalanche", "bsc", "crono", "fantom", "moonbeam", "optimism", "gnosis", "celo", "scroll", "base"];
8
8
  export type Network = (typeof networks)[number];
9
9
  export declare class EtherscanParser {
10
10
  protected apikey: string;
@@ -26,6 +26,7 @@ exports.networks = [
26
26
  'optimism',
27
27
  'gnosis',
28
28
  'celo',
29
+ 'scroll',
29
30
  'base',
30
31
  ];
31
32
  class EtherscanParser {
@@ -78,6 +79,10 @@ class EtherscanParser {
78
79
  this.url = 'https://api.gnosisscan.io/api';
79
80
  this.apikey = '2RWGXIWK538EJ8XSP9DE2JUINSCG7UCSJB';
80
81
  }
82
+ else if (network === 'scroll') {
83
+ this.url = 'https://api.scrollscan.com/api';
84
+ this.apikey = '4V37ZJFIN9AURJSU9YG1RP3MSVTPH6D6Z4';
85
+ }
81
86
  else if (network === 'celo') {
82
87
  this.url = 'https://api.celoscan.io/api';
83
88
  this.apikey = 'JBV78T5KP15W7WKKKD6KC4J8RX2F4PK8AF';
package/lib/slotValues.js CHANGED
@@ -9,6 +9,7 @@ const axios_1 = __importDefault(require("axios"));
9
9
  const umlClass_1 = require("./umlClass");
10
10
  const utils_1 = require("ethers/lib/utils");
11
11
  const SlotValueCache_1 = require("./SlotValueCache");
12
+ const ethers_1 = require("ethers");
12
13
  const debug = require('debug')('sol2uml');
13
14
  /**
14
15
  * Adds the slot values to the variables in the storage section.
@@ -211,12 +212,20 @@ const getSlotValues = async (url, contractAddress, slotKeys, blockTag = 'latest'
211
212
  const block = blockTag === 'latest'
212
213
  ? blockTag
213
214
  : (0, utils_1.hexValue)(bignumber_1.BigNumber.from(blockTag));
214
- // get cached values and missing slot keys from from cache
215
+ // get cached values and missing slot keys from the cache
215
216
  const { cachedValues, missingKeys } = SlotValueCache_1.SlotValueCache.readSlotValues(slotKeys);
216
217
  // If all values are in the cache then just return the cached values
217
218
  if (missingKeys.length === 0) {
218
219
  return cachedValues;
219
220
  }
221
+ // Check we are pointing to the correct chain by checking the contract has code
222
+ const provider = new ethers_1.ethers.providers.JsonRpcProvider(url);
223
+ const code = await provider.getCode(contractAddress, block);
224
+ if (!code || code === '0x') {
225
+ const msg = `Address ${contractAddress} has no code. Check your "-u, --url" option or "NODE_URL" environment variable is pointing to the correct node.\nurl: ${url}`;
226
+ console.error(msg);
227
+ throw Error(msg);
228
+ }
220
229
  debug(`About to get ${slotKeys.length} storage values for ${contractAddress} at block ${blockTag} from slot ${missingKeys[0].toString()}`);
221
230
  // Get the values for the missing slot keys
222
231
  const payload = missingKeys.map((key) => ({
package/lib/sol2uml.js CHANGED
@@ -2,7 +2,6 @@
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const commander_1 = require("commander");
5
- const ethers_1 = require("ethers");
6
5
  const path_1 = require("path");
7
6
  const converterClasses2Dot_1 = require("./converterClasses2Dot");
8
7
  const converterClasses2Storage_1 = require("./converterClasses2Storage");
@@ -16,6 +15,7 @@ const slotValues_1 = require("./slotValues");
16
15
  const regEx_1 = require("./utils/regEx");
17
16
  const validators_1 = require("./utils/validators");
18
17
  const writerFiles_1 = require("./writerFiles");
18
+ const block_1 = require("./utils/block");
19
19
  const clc = require('cli-color');
20
20
  const program = new commander_1.Command();
21
21
  const debugControl = require('debug');
@@ -171,12 +171,7 @@ WARNING: sol2uml does not use the Solidity compiler so may differ with solc. A k
171
171
  }
172
172
  storageAddress = fileFolderAddress;
173
173
  }
174
- let block = combinedOptions.block;
175
- if (block === 'latest') {
176
- const provider = new ethers_1.ethers.providers.JsonRpcProvider(combinedOptions.url);
177
- block = await provider.getBlockNumber();
178
- debug(`Latest block is ${block}. All storage slot values will be from this block.`);
179
- }
174
+ let block = await (0, block_1.getBlock)(combinedOptions);
180
175
  // Get slot values for each storage section
181
176
  for (const storageSection of storageSections) {
182
177
  await (0, slotValues_1.addSlotValues)(combinedOptions.url, storageAddress, storageSection, arrayItems, block);
@@ -0,0 +1,5 @@
1
+ export declare const getBlock: (options: {
2
+ block: string;
3
+ url: string;
4
+ network: string;
5
+ }) => Promise<number>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBlock = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const debug = require('debug')('sol2uml');
6
+ const getBlock = async (options) => {
7
+ if (options.block === 'latest') {
8
+ try {
9
+ const provider = new ethers_1.ethers.providers.JsonRpcProvider(options.url);
10
+ const block = await provider.getBlockNumber();
11
+ debug(`Latest block is ${block}. All storage slot values will be from this block.`);
12
+ return block;
13
+ }
14
+ catch (err) {
15
+ const defaultMessage = options.url === 'http://localhost:8545'
16
+ ? 'This is the default url. Use the `-u, --url` option or `NODE_URL` environment variable to set the url of your blockchain node.'
17
+ : `Check your --url option or NODE_URL environment variable is pointing to the correct node for the "${options.network}" blockchain.`;
18
+ throw Error(`Failed to connect to blockchain node with url ${options.url}.\n${defaultMessage}`);
19
+ }
20
+ }
21
+ try {
22
+ return parseInt(options.block);
23
+ }
24
+ catch (err) {
25
+ throw Error(`Invalid block number: ${options.block}`);
26
+ }
27
+ };
28
+ exports.getBlock = getBlock;
29
+ //# sourceMappingURL=block.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sol2uml",
3
- "version": "2.5.15",
3
+ "version": "2.5.17",
4
4
  "description": "Solidity contract visualisation tool.",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -24,10 +24,10 @@
24
24
  "dependencies": {
25
25
  "@aduh95/viz.js": "^3.7.0",
26
26
  "@solidity-parser/parser": "^0.16.1",
27
- "axios": "^1.3.4",
27
+ "axios": "^1.6.0",
28
28
  "axios-debug-log": "^1.0.0",
29
29
  "cli-color": "^2.0.3",
30
- "commander": "^11.0.0",
30
+ "commander": "^11.1.0",
31
31
  "convert-svg-to-png": "^0.6.4",
32
32
  "debug": "^4.3.4",
33
33
  "diff-match-patch": "^1.0.5",
@@ -37,14 +37,14 @@
37
37
  },
38
38
  "devDependencies": {
39
39
  "@openzeppelin/contracts": "^4.9.3",
40
- "@types/diff-match-patch": "^1.0.32",
41
- "@types/jest": "^29.5.3",
42
- "@types/klaw": "^3.0.3",
43
- "jest": "^29.6.2",
44
- "prettier": "^3.0.1",
40
+ "@types/diff-match-patch": "^1.0.35",
41
+ "@types/jest": "^29.5.7",
42
+ "@types/klaw": "^3.0.5",
43
+ "jest": "^29.7.0",
44
+ "prettier": "^3.0.3",
45
45
  "ts-jest": "^29.1.1",
46
46
  "ts-node": "^10.9.1",
47
- "typescript": "^5.1.6"
47
+ "typescript": "^5.2.2"
48
48
  },
49
49
  "files": [
50
50
  "lib/*.js",