Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: add various setup improvements #4

Merged
merged 3 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2023 Lido

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
42 changes: 40 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,50 @@
# Diffyscan

Diff your Github code against Etherscan verified source code.
![python ^3.10](https://img.shields.io/badge/python-^3.10-blue)
![poetry ^1.4](https://img.shields.io/badge/poetry-^1.4-blue)
![license MIT](https://img.shields.io/badge/license-MIT-brightgreen)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

Diff your Ethereum smart contracts code from GitHub against Etherscan verified source code.

## Prerequisites
This project was developed using these dependencies with their exact versions listed below:
- Python ^3.10
- Poetry ^1.4

Other versions may work as well but were not tested at all.

## Setup

1. Install Poetry

Use the following command to install poetry:

```shell
pip install --user poetry~=1.4
```

alternatively, you could proceed with `pipx`:

```shell
pipx install poetry~=1.4
```

2. Install Python dependencies
TheDZhon marked this conversation as resolved.
Show resolved Hide resolved
```shell
poetry install
```

3. Activate poetry virtual environment,
```shell
poetry shell
```

## Usage

Set your Etherscan token to fetch verified source code,
```bash
export ETHERSCAN_API_TOKEN=<your-etherscan-token>
export ETHERSCAN_TOKEN=<your-etherscan-token>
```

Set your Github token to query API without strict rate limiting,
Expand Down
12 changes: 8 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def run_diff(config, name, address, etherscan_api_token, github_api_token):
)

if (contract_name != name):
logger.error("Contract name in config does not match with etherscan", f"{address}: {name} != {contract_name}")
logger.error("Contract name in config does not match with Etherscan", f"{address}: {name} != {contract_name}")
sys.exit(1)

files_count = len(source_files)
Expand Down Expand Up @@ -59,7 +59,7 @@ def run_diff(config, name, address, etherscan_api_token, github_api_token):
):
repo = config["dependencies"].get(origin)
else:
logger.warn(f"No file in github repo for: {filepath}")
logger.warn(f"No file in GitHub repo for: {filepath}")
logger.divider()

diff_report_filename = None
Expand Down Expand Up @@ -114,7 +114,7 @@ def main():
logger.divider()

logger.info("Loading API tokens...")
etherscan_api_token = load_env("ETHERSCAN_API_TOKEN", masked=True)
etherscan_api_token = load_env("ETHERSCAN_TOKEN", masked=True)
github_api_token = load_env("GITHUB_API_TOKEN", masked=True)
contract_address = load_env("CONTRACT_ADDRESS", required=False)
contract_name = load_env("CONTRACT_NAME", required=False)
Expand All @@ -128,7 +128,11 @@ def main():
config = load_config()

if contract_address is not None:
logger.info(f"Running diff for a single contract {contract_name} ...")
if contract_name is None:
logger.error("Contract name isn't set for address", f"{contract_address}")
TheDZhon marked this conversation as resolved.
Show resolved Hide resolved
sys.exit(1)

logger.info(f"Running diff for a single contract {contract_name} deployed at {contract_address}...")
run_diff(config, contract_name, contract_address, etherscan_api_token, github_api_token)
else:
contracts = config["contracts"]
Expand Down
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
[tool.poetry]
name = "etherscan-github-diff-checker"
version = "0.1.0"
description = ""
description = "Diff your Ethereum smart contracts code from GitHub against Etherscan verified source code."
authors = ["Azat Serikov <azatsdev@gmail.com>"]
license = "MIT"
readme = "README.md"
repository = "https://github.com/lidofinance/diffyscan"

keywords = ["ethereum", "diff", "sources"]

[tool.poetry.dependencies]
python = "^3.10"
Expand Down