-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
69 lines (54 loc) · 2.55 KB
/
settings.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
57
58
59
60
61
62
63
64
65
66
67
68
import yaml
import os
from algosdk.v2client import indexer, algod
from algosdk import mnemonic
class Settings:
INDEXER_ADDRESSES = {
"testnet": "https://algoindexer.testnet.algoexplorerapi.io",
"mainnet": "https://algoindexer.algoexplorerapi.io"
}
ALGOD_ADDRESSES = {
"testnet": "https://node.testnet.algoexplorerapi.io",
"mainnet": "https://node.algoexplorerapi.io"
}
full_settings = {}
def __init__(self, settings_key):
self.settings_key = settings_key
module_path = os.path.dirname(__file__)
settings_path = os.path.join(module_path, './settings.yaml')
settings_exists = os.path.exists(settings_path)
if not settings_exists:
print(f'Your settings.yaml could not be found here: {os.path.abspath(settings_path)}')
exit()
with open(settings_path, 'r') as file:
try:
self.full_settings = yaml.safe_load(file)
except:
print("Your settings.yaml is incorrectly formatted. Remember to use forward slashes in filepaths!")
exit()
if self.full_settings['testnet']:
self.indexer_address = self.INDEXER_ADDRESSES['testnet']
self.algod_address = self.ALGOD_ADDRESSES['testnet']
else:
self.indexer_address = self.INDEXER_ADDRESSES['mainnet']
self.algod_address = self.ALGOD_ADDRESSES['mainnet']
self.context_settings = self.full_settings[self.settings_key]
def get_indexer(self):
indexer_address = self.indexer_address
headers = {'User-Agent': 'py-algorand-sdk'}
return indexer.IndexerClient(indexer_token="", headers=headers, indexer_address=indexer_address)
def get_algod_client(self):
indexer_address = self.algod_address
headers = {'User-Agent': 'py-algorand-sdk'}
return algod.AlgodClient(algod_token="", algod_address=indexer_address, headers=headers);
def __getattr__(self, name):
return self.context_settings[name]
def get_output_folder(self):
root_path = os.path.abspath(os.path.dirname(__file__) + '/../')
return os.path.join(root_path, self.full_settings['default_output_folder'], self.settings_key)
def get_private_key(self):
pass_phrase = self.context_settings['mnemonic1']
return mnemonic.to_private_key(pass_phrase.replace(',', ''))
def get_public_key(self):
pass_phrase = self.context_settings['mnemonic1']
return mnemonic.to_public_key(pass_phrase.replace(',', ''))