-
Notifications
You must be signed in to change notification settings - Fork 682
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #812 version 4.3.0 from RavenProject/develop
Merge 4.3.0 into master
- Loading branch information
Showing
17 changed files
with
133 additions
and
32 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 |
---|---|---|
|
@@ -6,18 +6,26 @@ | |
# | ||
# -- NOTE: This script requires Python, PIP, and bitcoin-rpc to be installed. | ||
# To install bitcoin-rpc run the following command from the terminal: | ||
# pip install wheel | ||
# pip install python-bitcoinrpc | ||
# | ||
# To use sendgid notification (optional): | ||
# pip3 install sendgrid | ||
# export SENDGRID_API_KEY="<your sendgrid API key>" | ||
# set notification_emails variable below | ||
|
||
|
||
import os | ||
import subprocess | ||
import json | ||
import logging | ||
|
||
|
||
#Set this to your raven-cli program | ||
cli = "./src/raven-cli" | ||
cli = "raven-cli" | ||
|
||
mode = "-main" | ||
rpc_port = 8767 | ||
rpc_port = 8766 | ||
|
||
#mode = "-testnet" | ||
#rpc_port = 18770 | ||
#mode = "-regtest" | ||
|
@@ -27,6 +35,9 @@ | |
rpc_user = 'rpcuser' | ||
rpc_pass = 'rpcpass555' | ||
|
||
#Set this e-mail address, and SENDGRID_API_KEY env variable for notifications | ||
notification_emails='[email protected]' | ||
send_alerts_on_success = True #Set to True if you want email notification on success | ||
|
||
def listassets(filter): | ||
rpc_connection = get_rpc_connection() | ||
|
@@ -59,6 +70,36 @@ def get_rpc_connection(): | |
rpc_connection = AuthServiceProxy(connection) | ||
return(rpc_connection) | ||
|
||
def log_failure(err): | ||
logging.error(err) | ||
|
||
def send_notification(notification_to_emails, notification_subject, notification_content): | ||
sendgrid_api_key = '' | ||
if "SENDGRID_API_KEY" in os.environ: | ||
sendgrid_api_key = os.environ.get('SENDGRID_API_KEY') | ||
#print("Key="+sendgrid_api_key) | ||
else: | ||
print("Must set SENDGRID_API_KEY environment to use e-mail notification.") | ||
return | ||
|
||
import sendgrid | ||
from sendgrid.helpers.mail import Content, Email, Mail | ||
|
||
message = Mail( | ||
from_email='[email protected]', | ||
to_emails=notification_to_emails, | ||
subject=notification_subject, | ||
html_content=notification_content) | ||
|
||
try: | ||
sg = sendgrid.SendGridAPIClient(sendgrid_api_key) | ||
response = sg.send(message) | ||
#print(response.status_code) | ||
#print(response.body) | ||
#print(response.headers) | ||
except: | ||
print(e.message) | ||
|
||
|
||
def audit(filter): | ||
assets = listassets(filter) | ||
|
@@ -68,6 +109,7 @@ def audit(filter): | |
count = 0 | ||
max_dist_asset_name = "" | ||
max_dist_address_count = 0 | ||
audits_failed = 0 | ||
for asset, properties in assets.items(): | ||
count=count+1 | ||
total_issued = 0 | ||
|
@@ -88,9 +130,11 @@ def audit(filter): | |
number_of_addresses += len(address_qtys) | ||
|
||
for address, qty in address_qtys.items(): | ||
#print(address + " -> " + str(qty)) | ||
#print(address + "," + str(qty)) | ||
total_for_asset += qty | ||
|
||
|
||
|
||
# If the number of address is less than 50000, end the loop | ||
if len(address_qtys) < 50000: | ||
loop = False | ||
|
@@ -108,17 +152,28 @@ def audit(filter): | |
print("Audit PASSED for " + asset) | ||
print("") | ||
else: | ||
audits_failed += 1 | ||
print("Audit FAILED for " + asset) | ||
exit() | ||
msg = "Audit FAILED for " + asset + " Issued="+str(total_issued)+ " Total="+str(total_for_asset) | ||
log_failure(msg) | ||
send_notification(notification_emails, "Ravencoin Asset Audit Failed", msg) | ||
#exit(-1) | ||
|
||
if len(assets) == count: | ||
print("All " + str(len(assets)) + " assets audited.") | ||
print("Stats:") | ||
print(" Max Distribed Asset: " + max_dist_asset_name + " with " + str(max_dist_address_count) + " addresses.") | ||
|
||
if (send_alerts_on_success and audits_failed == 0): | ||
send_notification(notification_emails, "Ravencoin Asset Audit Success", "All " + str(len(assets)) + " assets audited.") | ||
|
||
if mode == "-regtest": #If regtest then mine our own blocks | ||
import os | ||
os.system(cli + " " + mode + " generate 400") | ||
|
||
audit("*") #Set to "*" for all. | ||
#### Uncomment these lines to test e-mail notification ### | ||
#send_notification(notification_emails, "Test Subject", "Test Message") | ||
#exit() | ||
########################################################## | ||
|
||
logging.basicConfig(filename='failures.txt', format="%(asctime)-15s %(message)s", level=logging.INFO) | ||
audit("*") #Set to "*" for all, or set a specific asset, or 'B*' |
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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