Skip to content

Commit

Permalink
feat: added explorerUrl option for testnet block explorers
Browse files Browse the repository at this point in the history
chore: bumped version to 2.5.6
  • Loading branch information
naddison36 committed Jun 25, 2023
1 parent 5093f67 commit 328694e
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 156 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ Options:
-f, --outputFormat <value> output file format. (choices: "svg", "png", "dot", "all", default: "svg")
-o, --outputFileName <value> output file name
-i, --ignoreFilesOrFolders <filesOrFolders> comma separated list of files or folders to ignore
-n, --network <network> Ethereum network (choices: "mainnet", "goerli", "sepolia", "polygon", "arbitrum", "avalanche", "bsc", "crono", "fantom", "moonbeam",
-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", default: "mainnet", env: ETH_NETWORK)
-e, --explorerUrl <url> Override network with custom blockchain explorer API URL. eg Polygon Mumbai testnet https://api-testnet.polygonscan.com/api (env: EXPLORER_URL)
-k, --apiKey <key> Blockchain explorer API key. eg Etherscan, Arbiscan, Optimism, BscScan, CronoScan, FTMScan, PolygonScan or SnowTrace API key (env: SCAN_API_KEY)
-bc, --backColor <color> Canvas background color. "none" will use a transparent canvas. (default: "white")
-sc, --shapeColor <color> Basic drawing color for graphics, not text (default: "black")
Expand Down
2 changes: 1 addition & 1 deletion lib/parserEtherscan.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export declare class EtherscanParser {
protected apikey: string;
network: Network;
readonly url: string;
constructor(apikey?: string, network?: Network);
constructor(apikey?: string, network?: Network, url?: string);
/**
* Parses the verified source code files from Etherscan
* @param contractAddress Ethereum contract address with a 0x prefix
Expand Down
336 changes: 194 additions & 142 deletions lib/parserEtherscan.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/parserGeneral.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { UmlClass } from './umlClass';
export interface ParserOptions {
apiKey?: string;
network?: Network;
explorerUrl?: string;
subfolders?: string;
ignoreFilesOrFolders?: string;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/parserGeneral.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions lib/sol2uml.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sol2uml",
"version": "2.5.5",
"version": "2.5.6",
"description": "Solidity contract visualisation tool.",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down
7 changes: 6 additions & 1 deletion src/ts/parserEtherscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ export class EtherscanParser {

constructor(
protected apikey: string = 'ZAD4UI2RCXCQTP38EXS3UY2MPHFU5H9KB1',
public network: Network = 'mainnet'
public network: Network = 'mainnet',
url?: string
) {
if (url) {
this.url = url
return
}
if (!networks.includes(network)) {
throw new Error(
`Invalid network "${network}". Must be one of ${networks}`
Expand Down
4 changes: 3 additions & 1 deletion src/ts/parserGeneral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const debug = require('debug')('sol2uml')
export interface ParserOptions {
apiKey?: string
network?: Network
explorerUrl?: string
subfolders?: string
ignoreFilesOrFolders?: string
}
Expand Down Expand Up @@ -39,7 +40,8 @@ export const parserUmlClasses = async (
options.apiKey || 'ZAD4UI2RCXCQTP38EXS3UY2MPHFU5H9KB1'
const etherscanParser = new EtherscanParser(
etherscanApiKey,
options.network
options.network,
options.explorerUrl
)

result = await etherscanParser.getUmlClasses(fileFolderAddress)
Expand Down
17 changes: 14 additions & 3 deletions src/ts/sol2uml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,20 @@ Can also flatten or compare verified source files on Etherscan-like explorers.`
'comma separated list of files or folders to ignore'
)
.addOption(
new Option('-n, --network <network>', 'Ethereum network')
new Option(
'-n, --network <network>',
'Ethereum network which maps to a blockchain explorer'
)
.choices(networks)
.default('mainnet')
.env('ETH_NETWORK')
)
.addOption(
new Option(
'-e, --explorerUrl <url>',
'Override network with custom blockchain explorer API URL. eg Polygon Mumbai testnet https://api-testnet.polygonscan.com/api'
).env('EXPLORER_URL')
)
.addOption(
new Option(
'-k, --apiKey <key>',
Expand Down Expand Up @@ -400,7 +409,8 @@ In order for the merged code to compile, the following is done:

const etherscanParser = new EtherscanParser(
combinedOptions.apiKey,
combinedOptions.network
combinedOptions.network,
combinedOptions.explorerUrl
)

const { solidityCode, contractName } =
Expand Down Expand Up @@ -480,7 +490,8 @@ The line numbers are from contract B. There are no line numbers for the red sect

const etherscanParser = new EtherscanParser(
combinedOptions.apiKey,
combinedOptions.network
combinedOptions.network,
combinedOptions.explorerUrl
)

// Get verified Solidity code from Etherscan and flatten
Expand Down

0 comments on commit 328694e

Please sign in to comment.