-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for encrypted wallet (#20)
Signed-off-by: cyc60 <avsysoev60@gmail.com>
- Loading branch information
Showing
2 changed files
with
38 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,37 @@ | ||
import json | ||
import os.path | ||
|
||
from eth_account import Account | ||
from eth_account.account import LocalAccount | ||
|
||
from src.config.settings import ( | ||
WALLET_KEYSTORE_PASSWORD_PATH, | ||
WALLET_KEYSTORE_PATH, | ||
WALLET_PRIVATE_KEY, | ||
) | ||
|
||
|
||
def get_operator_account() -> LocalAccount: | ||
if WALLET_PRIVATE_KEY: | ||
return Account().from_key(WALLET_PRIVATE_KEY) | ||
|
||
if WALLET_KEYSTORE_PATH and WALLET_KEYSTORE_PASSWORD_PATH: | ||
if not os.path.isfile(WALLET_KEYSTORE_PATH): | ||
raise ValueError(f"Can't open WALLET_KEYSTORE_PATH file. " | ||
f' Path: {WALLET_KEYSTORE_PATH}') | ||
if not os.path.isfile(WALLET_KEYSTORE_PASSWORD_PATH): | ||
raise ValueError(f"Can't open WALLET_KEYSTORE_PASSWORD_PATH file. " | ||
f'Path: {WALLET_KEYSTORE_PASSWORD_PATH}') | ||
|
||
with open(WALLET_KEYSTORE_PATH, 'r', encoding='utf-8') as f: | ||
keyfile_json = json.load(f) | ||
with open(WALLET_KEYSTORE_PASSWORD_PATH, 'r', encoding='utf-8') as f: | ||
password = f.read().strip() | ||
key = Account().decrypt(keyfile_json, password) | ||
return Account().from_key(key) | ||
|
||
raise ValueError('Provide WALLET_PRIVATE_KEY setting or combination of ' | ||
'WALLET_KEYSTORE_PATH and WALLET_KEYSTORE_PASSWORD_PATH settings') | ||
|
||
from src.config.settings import OPERATOR_PRIVATE_KEY | ||
|
||
operator_account = Account().from_key(OPERATOR_PRIVATE_KEY) | ||
operator_account = get_operator_account() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters