mirror of
https://github.com/Steffo99/greed.git
synced 2025-03-13 12:17:27 +00:00
add test setup
This commit is contained in:
parent
7e5f5f4fd7
commit
57a70e76fc
2 changed files with 73 additions and 69 deletions
|
@ -65,6 +65,7 @@ phone_required = yes
|
|||
api_key = YOUR_API_HERE_
|
||||
secret = YOUR_SECRET_HERE_
|
||||
network_confirmations = 2
|
||||
test_setup = False
|
||||
|
||||
# Bot appearance settings
|
||||
[Appearance]
|
||||
|
|
141
core.py
141
core.py
|
@ -175,79 +175,82 @@ def callback():
|
|||
else:
|
||||
return "Incorrect secret"
|
||||
|
||||
# Add test setup button to index page
|
||||
@app.route('/', methods=['GET'])
|
||||
def home():
|
||||
if configloader.config["Bitcoin"]["test_setup"] == str(True):
|
||||
return '<a href="/test_setup"><button>Test Setup</button></a>'
|
||||
else:
|
||||
return "No access, enable test_setup in config.ini"
|
||||
|
||||
@app.route('/test_setup', methods=['GET', 'POST'])
|
||||
def test_setup():
|
||||
response = Blockonomics.get_callbacks()
|
||||
error_str = ''
|
||||
print (response.json()[0]['address'])
|
||||
response_body = response.json()
|
||||
if response_body[0]:
|
||||
response_callback = response_body[0]['callback']
|
||||
response_address = response_body[0]['address']
|
||||
else :
|
||||
response_callback = ''
|
||||
response_address = ''
|
||||
print (response_address)
|
||||
callback_secret = configloader.config["Bitcoin"]["secret"]
|
||||
api_url = flask.url_for('callback', _external=True)
|
||||
callback_url = api_url + "?secret=" + callback_secret
|
||||
return_string = "Blockonomics Callback URL: " + callback_url
|
||||
# Remove http:# or https:# from urls
|
||||
api_url_without_schema = api_url.replace("https://","")
|
||||
api_url_without_schema = api_url_without_schema.replace("http://","")
|
||||
callback_url_without_schema = callback_url.replace("https://","")
|
||||
callback_url_without_schema = callback_url_without_schema.replace("http://","")
|
||||
response_callback_without_schema = response_callback.replace("https://","")
|
||||
response_callback_without_schema = response_callback_without_schema.replace("http://","")
|
||||
# TODO: Check This: WE should actually check code for timeout
|
||||
if response == False:
|
||||
error_str = 'Your server is blocking outgoing HTTPS calls'
|
||||
elif response.status_code==401:
|
||||
error_str = 'API Key is incorrect'
|
||||
elif response.status_code!=200:
|
||||
error_str = response.text
|
||||
elif response_body == None or len(response_body) == 0:
|
||||
error_str = 'You have not entered an xpub'
|
||||
elif len(response_body) == 1:
|
||||
print ("response callback" + response_callback)
|
||||
if response_callback == "":
|
||||
print ("No callback URL set, set one")
|
||||
# No callback URL set, set one
|
||||
Blockonomics.update_callback(callback_url, response_address)
|
||||
elif response_callback_without_schema != callback_url_without_schema:
|
||||
print ("callback URL set, checking secret")
|
||||
base_url = api_url_without_schema
|
||||
# Check if only secret differs
|
||||
if base_url in response_callback:
|
||||
# Looks like the user regenrated callback by mistake
|
||||
# Just force Update_callback on server
|
||||
Blockonomics.update_callback(callback_url, response_address)
|
||||
else:
|
||||
error_str = "You have an existing callback URL. Refer instructions on integrating multiple websites"
|
||||
else:
|
||||
error_str = "You have an existing callback URL. Refer instructions on integrating multiple websites"
|
||||
# Check if callback url is set
|
||||
for res_obj in response_body:
|
||||
res_url = res_obj['callback'].replace("https://","")
|
||||
res_url = res_url.replace("https://","")
|
||||
if res_url == callback_url_without_schema:
|
||||
error_str = ""
|
||||
if error_str == "":
|
||||
# Everything OK ! Test address generation
|
||||
response = Blockonomics.new_address(True)
|
||||
if response.status_code != 200:
|
||||
if configloader.config["Bitcoin"]["test_setup"] == str(True):
|
||||
response = Blockonomics.get_callbacks()
|
||||
error_str = ''
|
||||
response_body = response.json()
|
||||
if response_body[0]:
|
||||
response_callback = response_body[0]['callback']
|
||||
response_address = response_body[0]['address']
|
||||
else :
|
||||
response_callback = ''
|
||||
response_address = ''
|
||||
callback_secret = configloader.config["Bitcoin"]["secret"]
|
||||
api_url = flask.url_for('callback', _external=True)
|
||||
callback_url = api_url + "?secret=" + callback_secret
|
||||
callback_string = "Blockonomics Callback URL: " + callback_url
|
||||
# Remove http:# or https:# from urls
|
||||
api_url_without_schema = api_url.replace("https://","")
|
||||
api_url_without_schema = api_url_without_schema.replace("http://","")
|
||||
callback_url_without_schema = callback_url.replace("https://","")
|
||||
callback_url_without_schema = callback_url_without_schema.replace("http://","")
|
||||
response_callback_without_schema = response_callback.replace("https://","")
|
||||
response_callback_without_schema = response_callback_without_schema.replace("http://","")
|
||||
# TODO: Check This: WE should actually check code for timeout
|
||||
if response == False:
|
||||
error_str = 'Your server is blocking outgoing HTTPS calls'
|
||||
elif response.status_code==401:
|
||||
error_str = 'API Key is incorrect'
|
||||
elif response.status_code!=200:
|
||||
error_str = response.text
|
||||
if error_str:
|
||||
error_str = error_str + '<p>For more information, please consult <a href="https://blockonomics.freshdesk.com/support/solutions/articles/33000215104-troubleshooting-unable-to-generate-new-address" target="_blank">this troubleshooting article</a></p>'
|
||||
return error_str + '<br>' + return_string
|
||||
# No errors
|
||||
return 'Congrats ! Setup is all done<br>' + return_string
|
||||
|
||||
def flaskThread():
|
||||
app.run(threaded=True)
|
||||
elif response_body == None or len(response_body) == 0:
|
||||
error_str = 'You have not entered an xpub'
|
||||
elif len(response_body) == 1:
|
||||
if response_callback == "":
|
||||
# No callback URL set, set one
|
||||
Blockonomics.update_callback(callback_url, response_address)
|
||||
elif response_callback_without_schema != callback_url_without_schema:
|
||||
base_url = api_url_without_schema
|
||||
# Check if only secret differs
|
||||
if base_url in response_callback:
|
||||
# Looks like the user regenrated callback by mistake
|
||||
# Just force Update_callback on server
|
||||
Blockonomics.update_callback(callback_url, response_address)
|
||||
else:
|
||||
error_str = "You have an existing callback URL. Refer instructions on integrating multiple websites"
|
||||
else:
|
||||
error_str = "You have an existing callback URL. Refer instructions on integrating multiple websites"
|
||||
# Check if callback url is set
|
||||
for res_obj in response_body:
|
||||
res_url = res_obj['callback'].replace("https://","")
|
||||
res_url = res_url.replace("https://","")
|
||||
if res_url == callback_url_without_schema:
|
||||
error_str = ""
|
||||
if error_str == "":
|
||||
# Everything OK ! Test address generation
|
||||
response = Blockonomics.new_address(True)
|
||||
if response.status_code != 200:
|
||||
error_str = response.text
|
||||
if error_str:
|
||||
error_str = error_str + '<p>For more information, please consult <a href="https://blockonomics.freshdesk.com/support/solutions/articles/33000215104-troubleshooting-unable-to-generate-new-address" target="_blank">this troubleshooting article</a></p>'
|
||||
return error_str
|
||||
# No errors
|
||||
return 'Congrats ! Setup is all done<br>'+callback_string
|
||||
else:
|
||||
return "No access, enable test_setup in config.ini"
|
||||
|
||||
threading.Thread(target=main).start()
|
||||
# Run the main function only in the main process
|
||||
if __name__ == "__main__":
|
||||
# Start callback in thread
|
||||
threading.Thread(target=flaskThread).start()
|
||||
main()
|
||||
app.run()
|
Loading…
Add table
Reference in a new issue