Add handling of the 'xpub' configuration key
Since it is supposed to be provided by the user, it explicitly has no default value
Also improved configuration error messages and ordered those by importance
Simon Volpert
3 years ago
25 | 25 | |
26 | 26 | # Configuration defaults |
27 | 27 | file_path = '' |
28 | xpub = '' | |
28 | 29 | default_price = 1000.0 |
29 | 30 | api_url = 'https://api.blockchair.com/bitcoin-cash/dashboards/address/{address}' |
30 | 31 | api_key_balance = 'data.{address}.address.balance' |
37 | 38 | # location should be in a place inaccessible from your capsule (outside the |
38 | 39 | # document root): |
39 | 40 | path={file_path} |
41 | # Set this to the extended public key (xPub) of your receiving wallet, which | |
42 | # will be used to generate a fresh receiving address for every payment. | |
43 | xpub= | |
40 | 44 | # Set this to the default price any given file should be in BITs (1,000,000th |
41 | 45 | # of a Bitcoin Cash): |
42 | 46 | default_price={default_price} |
158 | 162 | for line in _data: |
159 | 163 | if line.startswith('path='): |
160 | 164 | file_path = line[5:] |
165 | elif line.startswith('xpub='): | |
166 | xpub = line[5:] | |
161 | 167 | elif line.startswith('default_price='): |
162 | 168 | default_price = round(float(line[14:]), 2) |
163 | 169 | elif line.startswith('api_url='): |
170 | 176 | api_unit = line[9:] |
171 | 177 | |
172 | 178 | # Check configuration validity |
179 | if file_path == '': | |
180 | print('42 Missing required configuration value: path\r') | |
181 | raise SystemExit | |
182 | if xpub == '': | |
183 | print('42 Missing required configuration value: xpub\r') | |
184 | raise SystemExit | |
173 | 185 | if api_unit not in ['native', 'satoshi']: |
174 | 186 | print(f'42 Bad configuration value for api_unit: {api_unit}\r') |
175 | 187 | raise SystemExit |
176 | 188 | # Check if the file exists |
177 | if file_path == '': | |
178 | print('51 Not found\r') | |
179 | raise SystemExit | |
180 | 189 | request_file = Path(file_path) / path_info |
181 | 190 | if not request_file.is_file(): |
182 | 191 | print('51 Not found\r') |