From 97e4fa49847348889e3effcb4f3c5c76450eedfe Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Fri, 12 May 2023 13:54:05 +0200 Subject: [PATCH 1/2] changes configuration style of rpcs and allows adding block explorers --- README.md | 29 +++++++------- packages/vsc/package.json | 52 +++++++++++++++++++----- packages/vsc/src/app/config/chains.ts | 36 ----------------- packages/vsc/src/main.ts | 58 ++++++++++++++------------- 4 files changed, 87 insertions(+), 88 deletions(-) delete mode 100644 packages/vsc/src/app/config/chains.ts diff --git a/README.md b/README.md index 2e08970..f0c86c7 100644 --- a/README.md +++ b/README.md @@ -21,21 +21,22 @@ Valid configurations settings with defaults: ```json +//settings.json { - "cryptoAddressLens.ethereum.rpc": "https://rpc.ankr.com/eth", - "cryptoAddressLens.ethereum.enabled": true, - - "cryptoAddressLens.polygon.rpc": "https://rpc-mainnet.matic.quiknode.pro", - "cryptoAddressLens.polygon.enabled": true, - - "cryptoAddressLens.bsc.rpc": "https://binance.nodereal.io", - "cryptoAddressLens.bsc.enabled": true, - - "cryptoAddressLens.local.rpc": "http://localhost:8545", - "cryptoAddressLens.local.enabled": false, - - "cryptoAddressLens.custom.rpc": "http://localhost:8545", - "cryptoAddressLens.custom.enabled": false + "cryptoAddressLens.rpcs": { + "Ethereum": "https://rpc.ankr.com/eth", + "Arbitrum": "https://1rpc.io/arb", + "Optimism": "https://mainnet.optimism.io", + "Polygon": "https://rpc-mainnet.matic.quiknode.pro", + "BSC": "https://binance.nodereal.io" + }, + "cryptoAddressLens.explorers": { + "Etherscan": "https://etherscan.io/address/", + "Arbiscan": "https://arbiscan.io/address/", + "Optimism": "https://optimistic.etherscan.io/address/", + "Polygonscan": "https://polygonscan.com/address/", + "Bscscan": "https://bscscan.com/address/" + } } ``` diff --git a/packages/vsc/package.json b/packages/vsc/package.json index a148fa8..ef4be8f 100644 --- a/packages/vsc/package.json +++ b/packages/vsc/package.json @@ -44,55 +44,87 @@ "configuration": { "title": "Crypto Address Lens", "properties": { + "cryptoAddressLens.rpcs": { + "type": "object", + "description": "Object defining key: network name, value: rpc url. Set value to `false` to deactivate chain lookups.", + "default":{ + "Ethereum": "https://rpc.ankr.com/eth", + "Arbitrum": "https://1rpc.io/arb", + "Optimism": "https://mainnet.optimism.io", + "Polygon": "https://rpc-mainnet.matic.quiknode.pro", + "BSC": "https://binance.nodereal.io" + } + }, + "cryptoAddressLens.explorers":{ + "type": "object", + "description": "Object defining key: network name, value: explorer url. Set value to `false` to deactivate explorer.", + "default":{ + "Etherscan": "https://etherscan.io/address/", + "Arbiscan": "https://arbiscan.io/address/", + "Optimism": "https://optimistic.etherscan.io/address/", + "Polygonscan": "https://polygonscan.com/address/", + "Bscscan": "https://bscscan.com/address/" + } + }, "cryptoAddressLens.ethereum.rpc": { "type": "string", "default": "https://rpc.ankr.com/eth", - "description": "URL of the RPC node to use for Ethereum" + "description": "URL of the RPC node to use for Ethereum", + "deprecationMessage": "Deprecated: Please 'cryptoAddressLens.rpc' instead." }, "cryptoAddressLens.ethereum.enabled": { "type": "boolean", "default": true, - "description": "Enables Ethereum for Address Lookups" + "description": "Enables Ethereum for Address Lookups", + "deprecationMessage": "Deprecated: Please 'cryptoAddressLens.rpc' instead." }, "cryptoAddressLens.polygon.rpc": { "type": "string", "default": "https://rpc-mainnet.matic.quiknode.pro", - "description": "URL of the RPC node to use for Polygon" + "description": "URL of the RPC node to use for Polygon", + "deprecationMessage": "Deprecated: Please 'cryptoAddressLens.rpc' instead." }, "cryptoAddressLens.polygon.enabled": { "type": "boolean", "default": true, - "description": "Enables Polygon for Address Lookups" + "description": "Enables Polygon for Address Lookups", + "deprecationMessage": "Deprecated: Please 'cryptoAddressLens.rpc' instead." }, "cryptoAddressLens.bsc.rpc": { "type": "string", "default": "https://binance.nodereal.io", - "description": "URL of the RPC node to use for Binance Smart Chain" + "description": "URL of the RPC node to use for Binance Smart Chain", + "deprecationMessage": "Deprecated: Please 'cryptoAddressLens.rpc' instead." }, "cryptoAddressLens.bsc.enabled": { "type": "boolean", "default": true, - "description": "Enables Binance Smart Chain for Address Lookups" + "description": "Enables Binance Smart Chain for Address Lookups", + "deprecationMessage": "Deprecated: Please 'cryptoAddressLens.rpc' instead." }, "cryptoAddressLens.local.rpc": { "type": "string", "default": "http://localhost:8545", - "description": "URL of the RPC node to use for Local Chain" + "description": "URL of the RPC node to use for Local Chain", + "deprecationMessage": "Deprecated: Please 'cryptoAddressLens.rpc' instead." }, "cryptoAddressLens.local.enabled": { "type": "boolean", "default": false, - "description": "Enables Local Chain for Address Lookups" + "description": "Enables Local Chain for Address Lookups", + "deprecationMessage": "Deprecated: Please 'cryptoAddressLens.rpc' instead." }, "cryptoAddressLens.custom.rpc": { "type": "string", "default": "http://localhost:8545", - "description": "URL of the RPC node to use for Custom Chain" + "description": "URL of the RPC node to use for Custom Chain", + "deprecationMessage": "Deprecated: Please 'cryptoAddressLens.rpc' instead." }, "cryptoAddressLens.custom.enabled": { "type": "boolean", "default": false, - "description": "Enables Custom Chain for Address Lookups" + "description": "Enables Custom Chain for Address Lookups", + "deprecationMessage": "Deprecated: Please 'cryptoAddressLens.rpc' instead." } } } diff --git a/packages/vsc/src/app/config/chains.ts b/packages/vsc/src/app/config/chains.ts deleted file mode 100644 index ae4c5c2..0000000 --- a/packages/vsc/src/app/config/chains.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -enum ChainId { - ETHEREUM = 1, - POLYGON = 137, - BSC = 56, - LOCAL = 1337, - CUSTOM = -1, -} - -interface ChainDetails { - name: string; - configSection: string; -} - -export const ChainInfos: Record = { - [ChainId.ETHEREUM]: { - name: "Ethereum", - configSection: "ethereum", - }, - [ChainId.POLYGON]: { - name: "Polygon", - configSection: "polygon", - }, - [ChainId.BSC]: { - name: "Binance Smart Chain", - configSection: "bsc", - }, - [ChainId.LOCAL]: { - name: "Ethereum", - configSection: "local", - }, - [ChainId.CUSTOM]: { - name: "Custom", - configSection: "custom", - }, -}; diff --git a/packages/vsc/src/main.ts b/packages/vsc/src/main.ts index 469e69e..e62541e 100644 --- a/packages/vsc/src/main.ts +++ b/packages/vsc/src/main.ts @@ -11,7 +11,6 @@ import { workspace, } from 'vscode'; import { AddressFixer } from './app/AddressFixer'; -import { ChainInfos } from './app/config/chains'; import * as decorations from './app/config/decorations'; import { RPCClient } from './app/RPCClient'; @@ -19,31 +18,37 @@ let detailsDecoration: TextEditorDecorationType | null = null; let rpcClients: RPCClient[] = []; -function initRPCClients(): RPCClient[] { - const clients = Object.entries(ChainInfos).map(([, chainDetails]) => { - const enabled = workspace - .getConfiguration('cryptoAddressLens.' + chainDetails.configSection) - .get('enabled'); - const rpc = workspace - .getConfiguration('cryptoAddressLens.' + chainDetails.configSection) - .get('rpc'); - - if (rpc && typeof rpc === 'string') { - if (enabled) { - return new RPCClient(chainDetails.name, rpc); - } - } else { - console.warn( - `RPC Url for chain ${chainDetails.name} not correctly setup: ${rpc}` - ); - return; +let createExplorerMarkdown: (address: string) => string = () => ''; + +function initRPCClients() { + const rpcs = workspace.getConfiguration('cryptoAddressLens').get('rpcs'); + + const clients = Object.entries(rpcs).map(([chain, uri]) => { + if (typeof uri === 'string' && uri) { + return new RPCClient(chain, uri); } }); - return clients.filter((client) => !!client) as RPCClient[]; + rpcClients = clients.filter((client) => !!client) as RPCClient[]; +} + +function initExplorers() { + const explorers = workspace + .getConfiguration('cryptoAddressLens') + .get('explorers'); + createExplorerMarkdown = (address: string) => { + const links = Object.entries(explorers).map(([chain, uri]) => { + if (typeof uri === 'string' && uri) { + return `[${chain}](${uri}${address})`; + } + }); + + return links.filter((explorer) => !!explorer).join(' | '); + }; } export function activate(context: ExtensionContext) { + initExplorers(); context.subscriptions.push( languages.registerCodeActionsProvider( { scheme: 'file' }, @@ -77,11 +82,13 @@ export function activate(context: ExtensionContext) { // Init rpcClients again if configuration has changed workspace.onDidChangeConfiguration(() => { - rpcClients = initRPCClients(); + initRPCClients(); + initExplorers(); }); // Init clients right before first use - rpcClients = initRPCClients(); + initRPCClients(); + window.onDidChangeTextEditorSelection((event) => { // Always dispose previous decoration if available if (detailsDecoration) { @@ -155,12 +162,7 @@ function decorate(editor: TextEditor) { const range = new Range(startPos, endPos); const checksumAddress = evm.utils.toChecksumAddress(matchedAddress); const hoverMessage = new MarkdownString(); - const explorerMarkdown = [ - `[Etherscan](https://etherscan.io/address/${checksumAddress})`, - `[Polygonscan](https://polygonscan.com/address/${checksumAddress})`, - `[Bscscan](https://bscscan.com/address/${checksumAddress})`, - ].join(' | '); - + const explorerMarkdown = createExplorerMarkdown(checksumAddress); if (matchedAddress === checksumAddress) { hoverMessage.appendText('Checksum of address is valid.\n'); hoverMessage.appendMarkdown(explorerMarkdown); From a4d5ba3c7e5affa493ed79b167f388b818dc1802 Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Fri, 12 May 2023 14:12:20 +0200 Subject: [PATCH 2/2] updates changelog and syncs readme prior to distribution --- CHANGELOG.md | 20 +++++++++++++++++++- packages/vsc/CHANGELOG.md | 14 +++++++++++++- packages/vsc/README.md | 29 +++++++++++++++-------------- 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d43c82a..b05bc0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,22 @@ # Change Log +## [1.1.0] - 2023-05-12 + + +### Added + ++ adds new configuration property `crypoAddressLens.explorers` to configure block explorers to show up on address hover. It expects an object, key of this object is the explorers name, value is the URL of the block explorer which is suffixed with the address to lookup. + +### Changed + ++ deprecates configuration properties of the scheme `cryptoAddressLens.[network].rpc` and `cryptoAddressLens.[network].enabled`. + ++ migrates ability to setup networks and rpcs into new configuration property called `cryptoAddressLens.rpcs`. It expects an objects which keys are the network name and the value is the RPC url. Pass `false` as value to deactivate the network. + +## [1.0.1] - 2023-02-12 + +### Fixed + ++ restores access to README and CHANGELOG from VSCode/marketplace ## [1.0.0] - 2023-02-12 @@ -80,4 +98,4 @@ ## [0.1.0] -Initial release of `crypto-address-lens`. \ No newline at end of file +Initial release of `crypto-address-lens`. diff --git a/packages/vsc/CHANGELOG.md b/packages/vsc/CHANGELOG.md index 1dc15f4..b05bc0f 100644 --- a/packages/vsc/CHANGELOG.md +++ b/packages/vsc/CHANGELOG.md @@ -1,4 +1,16 @@ # Change Log +## [1.1.0] - 2023-05-12 + + +### Added + ++ adds new configuration property `crypoAddressLens.explorers` to configure block explorers to show up on address hover. It expects an object, key of this object is the explorers name, value is the URL of the block explorer which is suffixed with the address to lookup. + +### Changed + ++ deprecates configuration properties of the scheme `cryptoAddressLens.[network].rpc` and `cryptoAddressLens.[network].enabled`. + ++ migrates ability to setup networks and rpcs into new configuration property called `cryptoAddressLens.rpcs`. It expects an objects which keys are the network name and the value is the RPC url. Pass `false` as value to deactivate the network. ## [1.0.1] - 2023-02-12 @@ -86,4 +98,4 @@ ## [0.1.0] -Initial release of `crypto-address-lens`. \ No newline at end of file +Initial release of `crypto-address-lens`. diff --git a/packages/vsc/README.md b/packages/vsc/README.md index 2e08970..f0c86c7 100644 --- a/packages/vsc/README.md +++ b/packages/vsc/README.md @@ -21,21 +21,22 @@ Valid configurations settings with defaults: ```json +//settings.json { - "cryptoAddressLens.ethereum.rpc": "https://rpc.ankr.com/eth", - "cryptoAddressLens.ethereum.enabled": true, - - "cryptoAddressLens.polygon.rpc": "https://rpc-mainnet.matic.quiknode.pro", - "cryptoAddressLens.polygon.enabled": true, - - "cryptoAddressLens.bsc.rpc": "https://binance.nodereal.io", - "cryptoAddressLens.bsc.enabled": true, - - "cryptoAddressLens.local.rpc": "http://localhost:8545", - "cryptoAddressLens.local.enabled": false, - - "cryptoAddressLens.custom.rpc": "http://localhost:8545", - "cryptoAddressLens.custom.enabled": false + "cryptoAddressLens.rpcs": { + "Ethereum": "https://rpc.ankr.com/eth", + "Arbitrum": "https://1rpc.io/arb", + "Optimism": "https://mainnet.optimism.io", + "Polygon": "https://rpc-mainnet.matic.quiknode.pro", + "BSC": "https://binance.nodereal.io" + }, + "cryptoAddressLens.explorers": { + "Etherscan": "https://etherscan.io/address/", + "Arbiscan": "https://arbiscan.io/address/", + "Optimism": "https://optimistic.etherscan.io/address/", + "Polygonscan": "https://polygonscan.com/address/", + "Bscscan": "https://bscscan.com/address/" + } } ```