Skip to content

Commit

Permalink
merged master into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
dule-git committed Dec 14, 2022
2 parents f5946c8 + 674bed5 commit d4e6c40
Show file tree
Hide file tree
Showing 27 changed files with 1,060 additions and 133 deletions.
2 changes: 1 addition & 1 deletion examples/contract-verification/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"dependencies": {
"@nomiclabs/hardhat-ethers": "^2.1.0",
"@tenderly/hardhat-tenderly": "^1.3.0",
"@tenderly/hardhat-tenderly": "^1.3.2",
"dotenv": "^16.0.1",
"hardhat": "^2.10.2"
}
Expand Down
360 changes: 344 additions & 16 deletions examples/contract-verification/yarn.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions packages/tenderly-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# tenderly

## 0.0.3

### Patch Changes

- [#88](https://github.com/Tenderly/hardhat-tenderly/pull/88) [`913aad5`](https://github.com/Tenderly/hardhat-tenderly/commit/913aad5b23e3c3c170a600b7153dfe085be34919) Thanks [@Riphal](https://github.com/Riphal)! - Remove got package, start using axios.

## 0.0.2

### Patch Changes
Expand Down
7 changes: 4 additions & 3 deletions packages/tenderly-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "MIT",
"homepage": "https://tenderly.co",
"description": "",
"version": "0.0.2",
"version": "0.0.3",
"main": "internal/lib/tenderly-lib.js",
"types": "internal/lib/tenderly-lib.d.ts",
"repository": {
Expand Down Expand Up @@ -55,7 +55,8 @@
"hyperlinker": "^1.0.0",
"js-yaml": "^4.1.0",
"open": "^8.4.0",
"prompts": "^2.4.2"
"prompts": "^2.4.2",
"tslog": "^4.4.0"
},
"peerDependencies": {
"ts-node": "*",
Expand All @@ -69,4 +70,4 @@
"optional": true
}
}
}
}
26 changes: 21 additions & 5 deletions packages/tenderly-core/src/internal/cli/commands/LoginCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,51 @@ import open from "open";
import axios from "axios";
import prompts from "prompts";
import commander from "commander";
import { logger } from "../../../utils/logger";

import { isAccessTokenSet, setAccessToken } from "../../../utils/config";
import { TENDERLY_API_BASE_URL, TENDERLY_DASHBOARD_BASE_URL } from "../../../common/constants";

export const LoginCommand = new commander.Command("login").description("login to Tenderly").action(async () => {
logger.info("Trying to login to Tenderly.");

if (isAccessTokenSet()) {
logger.debug("Access token is already set. Checking if access token overwrite is needed.");
const response = await prompts({
type: "confirm",
name: "overwrite",
message: "Access token already set. Would you like to overwrite it?",
});
if (!response.overwrite) {
logger.debug("Access token overwrite skipped. Trying to login with the existing token.");
return;
}
}

logger.info("Access token not set.");
const accessToken = await promptAccessToken();

logger.debug("Access token accepted. Trying to log in.");
setAccessToken(accessToken);
console.log("Successfully logged in.");

console.log("Successfully logged in to Tenderly.");
logger.info("Successfully logged in to Tenderly.");
});

async function promptAccessToken(): Promise<string> {
console.log(`Redirecting to ${TENDERLY_DASHBOARD_BASE_URL}/account/authorization`);
console.log(`Redirecting to ${TENDERLY_DASHBOARD_BASE_URL}/account/authorization`)
logger.debug(`Redirecting to ${TENDERLY_DASHBOARD_BASE_URL}/account/authorization`);
await open(`${TENDERLY_DASHBOARD_BASE_URL}/account/authorization`);

logger.info("Requesting access token.");
const response = await prompts({
type: "text",
name: "accessToken",
message: "Enter access token",
validate: validator,
});

logger.info("Access token accepted.");
return response.accessToken;
}

Expand All @@ -53,14 +65,18 @@ const validator = async function (value: string) {

async function canAuthenticate(accessToken: string): Promise<boolean> {
try {
logger.debug("Checking if access token is valid.");
const response = await axios.get(`${TENDERLY_API_BASE_URL}/api/v1/user`, {
headers: { "x-access-key": accessToken },
});
if (response.data.user !== undefined) {
return true;
if (response.data.user === undefined || response.data.user === null) {
logger.error("Access token is invalid.");
return false;
}
return false;
logger.debug("Access token is valid.");
return true;
} catch (err) {
logger.error("Authentication error.");
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import Table from "cli-table3";
import commander from "commander";
import { logger } from "../../../utils/logger";

import { PLUGIN_NAME } from "../../../common/constants";
import { TenderlyService } from "../../core/services";
import { TenderlyNetwork } from "../../core/types";
import { convertToLogCompliantNetworks } from "../../../utils/log-compliance";

const tenderlyService = new TenderlyService(PLUGIN_NAME);

Expand All @@ -22,6 +24,9 @@ export const NetworksCommand = new commander.Command("networks")
const filteredNetworks = networks.filter(isNotExcluded);
filteredNetworks.sort((a, b) => a.sort_order - b.sort_order);

const logCompliantNetworks = convertToLogCompliantNetworks(filteredNetworks);
logger.silly("Obtained filtered public networks:", logCompliantNetworks);

const table = new Table({
style: { head: ["magenta"] },
head: headers,
Expand All @@ -39,6 +44,7 @@ export const NetworksCommand = new commander.Command("networks")
})
))
);
logger.silly("Networks table:", table);

console.log(table.toString());
});
Expand Down
23 changes: 0 additions & 23 deletions packages/tenderly-core/src/internal/core/common/logger.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,32 +1,59 @@
import * as axios from "axios";

import { logger } from "../../../utils/logger";
import { getConfig, isAccessTokenSet } from "../../../utils/config";
import { TENDERLY_API_BASE_URL, TENDERLY_JSON_RPC_BASE_URL } from "../../../common/constants";

export class TenderlyApiService {
public static configureInstance(): axios.AxiosInstance {
logger.debug("Configuring instance.");

const tdlyConfig = getConfig();
return axios.default.create({
const params = {
baseURL: TENDERLY_API_BASE_URL,
headers: { "x-access-key": tdlyConfig.access_key },
};

logger.debug("Configured instance with parameters:", {
baseURL: TENDERLY_API_BASE_URL,
access_key:
tdlyConfig.access_key !== undefined && tdlyConfig.access_key !== null && tdlyConfig.access_key !== ""
? "super secret access_key is set in 'access_key' field"
: "undefined or null or empty string",
});

return axios.default.create(params);
}

public static configureAnonymousInstance(): axios.AxiosInstance {
logger.debug("Configured anonymous instance towards tenderly api.");

return axios.default.create({
baseURL: TENDERLY_API_BASE_URL,
});
}

public static configureTenderlyRPCInstance(): axios.AxiosInstance {
logger.debug("Configuring tenderly RPC instance.");

const tdlyConfig = getConfig();
return axios.default.create({
const params = {
baseURL: TENDERLY_JSON_RPC_BASE_URL,
headers: {
"x-access-key": tdlyConfig.access_key,
Head: tdlyConfig.head !== undefined ? tdlyConfig.head : "",
},
};

logger.debug("Configured tenderly rpc instance with parameters:", {
baseURL: TENDERLY_API_BASE_URL,
access_key:
tdlyConfig.access_key !== undefined && tdlyConfig.access_key !== null && tdlyConfig.access_key !== ""
? "super secret access_key is set in 'access_key' field"
: "undefined or null or empty string",
});

return axios.default.create(params);
}

public static isAuthenticated(): boolean {
Expand Down
Loading

0 comments on commit d4e6c40

Please sign in to comment.