-
Notifications
You must be signed in to change notification settings - Fork 0
/
faucet.py
56 lines (47 loc) · 1.69 KB
/
faucet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import subprocess
import streamlit as st
from poktrolld import CMD_SHARE_JSON_OUTPUT, CMD_SHARED_ARGS_KEYRING, POKTROLLD_BIN_PATH, is_localnet
FAUCET_NAME = "faucet"
FAUCET_ADDRESS = (
st.secrets["faucet"]["localnet"]["address"] if is_localnet() else st.secrets["faucet"]["testnet"]["address"]
)
# Loads private key into keyring if it is available and not already imported.
# Returns True if the faucet is ready to be used, False otherwise.
def import_faucet_key() -> bool:
# Get the faucet private key
faucet_private_key = (
st.secrets["faucet"]["localnet"]["private_key"]
if is_localnet()
else st.secrets["faucet"]["testnet"]["private_key"]
)
if not faucet_private_key:
st.error("Faucet private key secret is is not set. Please verify your configurations!")
return False
# Check if the key already exists
check_command = (
[
POKTROLLD_BIN_PATH,
"keys",
"show",
FAUCET_NAME,
]
+ CMD_SHARED_ARGS_KEYRING
+ CMD_SHARE_JSON_OUTPUT
)
check_result = subprocess.run(" ".join(check_command), capture_output=True, shell=True)
if check_result.returncode == 0:
return True
# Import the faucet key
command = [
POKTROLLD_BIN_PATH,
"keys",
"import-hex",
FAUCET_NAME,
faucet_private_key,
] + CMD_SHARED_ARGS_KEYRING
result = subprocess.run(" ".join(command), capture_output=True, text=True, shell=True)
if result.returncode != 0:
st.error(f"Error importing faucet key: {result.stderr}. Fix the problem and try again!")
return False
print("Faucet key imported successfully!")
return True