Skip to content

Commit

Permalink
Merge branch 'main' of github.com:peetzweg/vscode-crypto-address-lens
Browse files Browse the repository at this point in the history
  • Loading branch information
peetzweg committed May 12, 2023
2 parents 11b072b + 0637abf commit 66edef3
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 104 deletions.
20 changes: 19 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -80,4 +98,4 @@

## [0.1.0]

Initial release of `crypto-address-lens`.
Initial release of `crypto-address-lens`.
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
}
}
```

Expand Down
14 changes: 13 additions & 1 deletion packages/vsc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -86,4 +98,4 @@

## [0.1.0]

Initial release of `crypto-address-lens`.
Initial release of `crypto-address-lens`.
29 changes: 15 additions & 14 deletions packages/vsc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
}
}
```

Expand Down
52 changes: 42 additions & 10 deletions packages/vsc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
}
Expand Down
36 changes: 0 additions & 36 deletions packages/vsc/src/app/config/chains.ts

This file was deleted.

58 changes: 30 additions & 28 deletions packages/vsc/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,44 @@ 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';

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' },
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 66edef3

Please sign in to comment.