diff --git a/chainlink.py b/chainlink.py index 1b21b71..f3afd1d 100644 --- a/chainlink.py +++ b/chainlink.py @@ -46,6 +46,7 @@ """ from chainmail import verify_signature +import eth_abi import os from Crypto.Hash import keccak import re @@ -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'] @@ -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 @@ -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 diff --git a/foundry.toml b/foundry.toml index 25b918f..e9c48bf 100644 --- a/foundry.toml +++ b/foundry.toml @@ -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 diff --git a/test_data/anvil_keys.yaml b/test_data/anvil_keys.yaml index 8a2b532..76ad529 100644 --- a/test_data/anvil_keys.yaml +++ b/test_data/anvil_keys.yaml @@ -38,3 +38,6 @@ rpc_url: 'http://localhost:8545' # For Infura testnet RPC: # rpc_url: 'https://goerli.infura.io/v3/' + +# For anvil use ''; for mainnet/testnet need to obtain an Etherscan token +etherscan_api_key: ''