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: Etherscan integration #4

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 9 additions & 3 deletions chainlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"""

from chainmail import verify_signature
import eth_abi
import os
from Crypto.Hash import keccak
import re
Expand All @@ -66,6 +67,7 @@
sender_private_key = KEY['testnet_sender']['private_key']
sender_address = KEY['testnet_sender']['address']
rpc_url = KEY['rpc_url']
etherscan_api_key = KEY['etherscan_api_key']

ENV_CONFIG_FILE = CONFIG['chainlink']['local_env_file']

Expand Down Expand Up @@ -152,10 +154,11 @@ def is_cast_and_send_succeed(output):
parsed = parse_cast_send_output(output)
return parsed['success']

# Returns a hash of the input using the Ethereum hash function keccak256
# Returns a hash of the input string using the Ethereum hash function keccak256
def hash(input):
input_bytes = eth_abi.encode(['string'], [input])
keccak_hash = keccak.new(digest_bits=256)
keccak_hash.update(bytes(input, 'utf-8'))
keccak_hash.update(input_bytes)
hash = keccak_hash.hexdigest()
print(f'keccak-256: {hash}')
return hash
Expand All @@ -177,7 +180,10 @@ def hash_email_address(email):
# saved locally in a file for future use.
def deploy():
# deploy smart contract
command = f'forge create {contract_file}:Chainmail --private-key {owner_private_key} --rpc-url {rpc_url}'
enable_verification = ''
if etherscan_api_key != '':
enable_verification = f' --etherscan-api-key {etherscan_api_key} --verify'
command = f'forge create {contract_file}:Chainmail --private-key {owner_private_key} --rpc-url {rpc_url}{enable_verification}'
output = execute_or_die(command)

# Save address of smart contract in environment for future use. This is important for testing on local anvil
Expand Down
2 changes: 2 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
src = "src"
out = "out"
libs = ["lib"]
solc_version = "0.8.20"
optimizer = false

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
3 changes: 3 additions & 0 deletions test_data/anvil_keys.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ rpc_url: 'http://localhost:8545'

# For Infura testnet RPC:
# rpc_url: 'https://goerli.infura.io/v3/<token>'

# For anvil use ''; for mainnet/testnet need to obtain an Etherscan token
etherscan_api_key: ''