from asyncio import sleep from autobahn.wamp import auth from autobahn.wamp.types import CallResult from asyncio import coroutine import json from bts import BTS config_file = open("config.json") config = json.load(config_file) config_file.close() config_wamp = config["wamp_client"] config_bts = config["bts_client"] client = BTS(config_bts["user"],config_bts["password"],config_bts["host"],config_bts["port"]) class MyComponent(ApplicationSession): IsConnect = True def onConnect(self): self.IsConnect = True self.join(self.config.realm, [u"wampcra"], config_wamp["user"]) def onChallenge(self, challenge): key = config_wamp["password"].encode('utf8') signature = auth.compute_wcs(key, challenge.extra['challenge'].encode('utf8')) return signature.decode('ascii') def mypublish(self, topic, event): try:
from datetime import datetime import time from bts import BTS import operator import json from math import fabs ## Loading Config config_file = open("config.json") config = json.load(config_file) config_file.close() ## Opening RPC to wallet client = BTS( config["client"]["rpc_user"], config["client"]["rpc_password"], config["client"]["rpc_host"], config["client"]["rpc_port"] ) runtime = 0 timeout = 60 while True: try: response = client.request("get_info", []) blockchain_info = response.json()["result"] age = int(blockchain_info["blockchain_head_block_age"]) height = int(blockchain_info["blockchain_head_block_num"]) timestamp = blockchain_info["blockchain_head_block_timestamp"] health = blockchain_info["blockchain_average_delegate_participation"] confirm = blockchain_info["blockchain_confirmation_requirement"]
formatter = logging.Formatter('%(asctime)s[%(levelname)s]: %(message)s') #ch = logging.StreamHandler() #ch.setFormatter(formatter) #logger.addHandler(ch) ## Setting up Logger fh = logging.handlers.RotatingFileHandler( config["log"]["filename"], maxBytes=config["log"]["logMaxByte"], backupCount=config["log"]["logBackupCnt"]) fh.setFormatter(formatter) logger.addHandler(fh) ## Opening RPC to wallet client = BTS(config["client"]["rpc_user"], config["client"]["rpc_password"], config["client"]["rpc_host"], config["client"]["rpc_port"]) asset_list_publish = [] asset_list_display = [] if len(sys.argv) == 2: if sys.argv[1] == "ALL": asset_list_publish = asset_list_all asset_list_display = asset_list_all else: asset_list_publish = sys.argv asset_list_publish.pop(0) asset_list_display = list( set(config["asset_list_display"] + asset_list_publish))