def read_oracle(CHAIN, ORCLID, numrec): orcl_info = getconf.oraclesinfo_rpc(CHAIN, ORCLID) batonutxo = orcl_info['registered'][0]['batontxid'] name = orcl_info['name'] funds = '{:.2f}'.format(float(orcl_info['registered'][0]['funds'])) publisher = orcl_info['registered'][0]['publisher'] samples = getconf.oraclessamples_rpc(CHAIN, ORCLID, batonutxo, numrec) return samples['samples']
#!/usr/bin/env python3 import sys import getconf # construct daemon url CHAIN = sys.argv[1] RPCURL = getconf.def_credentials(CHAIN) oraclelist_result = getconf.oracleslist_rpc(CHAIN) for oracle_txid in oraclelist_result: oraclesinfo_result = getconf.oraclesinfo_rpc(CHAIN, oracle_txid) description = oraclesinfo_result['description'] name = oraclesinfo_result['name'] if description[0:4] == 'CHAT': print('[' + name + ': ' + description[5:] + ']: ' + oracle_txid)
oracletxIDs = [] oracleChains = [] HOME = os.environ['HOME'] with open(HOME + '/StakedNotary/assetchains.json') as file: assetchains = json.load(file) print(colorTable.colors[i] + 'ID'.rjust(3) + ' | ' + 'ASSET CHAIN'.ljust(12) + ' | ' + 'ORACLE NAME'.ljust(20) + ' | ' + 'ORACLE DESCIPTION'.ljust(50) + ' | ' + 'ORACLE TX ID') for chain in assetchains: RPCURL = getconf.def_credentials(chain['ac_name']) oraclelist_result = getconf.oracleslist_rpc(chain['ac_name']) i += 1 for oracle_txid in oraclelist_result: oraclesinfo_result = getconf.oraclesinfo_rpc(chain['ac_name'], oracle_txid) description = oraclesinfo_result['description'] name = oraclesinfo_result['name'] # if description[0:3] == 'GPS': print(colorTable.colors[i] + str(ID).rjust(3) + ' | ' + chain['ac_name'].ljust(12) + ' | ' + name.ljust(20) + ' | ' + description.ljust(50) + ' | ' + oracle_txid) oracletxIDs.append(oracle_txid) oracleChains.append(chain['ac_name']) ID += 1 chosen_one = selectRange(0, len(oracletxIDs), "Select an oracle: ") chosen_info = getconf.oraclesinfo_rpc(oracleChains[chosen_one - 1], oracletxIDs[chosen_one - 1]) print("you selected oracle " + str(chosen_one) + " [" + chosen_info['name'] + " ]") print(chosen_info)
def create_oracle(chain, houndname, user_id): result = getconf.oraclescreate_rpc( chain, houndname, username + "'s Dragonhound Track History", "S") print("oracle_create: " + str(result)) oracleHex = result['hex'] print("oracleHex: " + oracleHex) oracleResult = result['result'] print("oracleResult: " + oracleResult) while oracleResult != 'success': result = getconf.oraclescreate_rpc( chain, houndname, username + "'s Dragonhound Track History", "S") print("oracle_create: " + result) oracleHex = result['hex'] print("oracleHex: " + oracleHex) oracleResult = result['result'] print("create oracleResult: " + oracleResult) print('----------- SENDING RAW -----------') result = getconf.sendrawtx_rpc(chain, oracleHex) print("rawtx: " + str(result)) print("raw_result: " + result['result']) while len(result['result']) != 64: time.sleep(15) result = getconf.sendrawtx_rpc(chain, oracleHex) print("rawtx: " + result) print("raw_result: " + result['result']) orclid = result['result'] print("--------------------- Confirm Tx --------------------- ") memPool = str(getconf.getrawmempool_rpc(chain)) while memPool.find(orclid) < 0: time.sleep(15) memPool = str(getconf.getrawmempool_rpc(chain)) print(memPool) print(orclid) print("Oracle creation tx confirmed") print("--------------------- Confirm Listing --------------------- ") oraclesList = str(getconf.oracleslist_rpc(chain)) while oraclesList.find(orclid) < 0: time.sleep(15) oraclesList = str(getconf.oracleslist_rpc(chain)) print(oraclesList) print(orclid) print("Oracle Listing confirmed") print("--------------------- Registering Oracle --------------------- ") datafee = '1000000' rego = getconf.oraclesregister_rpc(chain, orclid, datafee) print("rego: " + str(rego)) oracleHex = rego['hex'] print("oracleHex: " + oracleHex) oracleResult = rego['result'] print("oracleResult: " + oracleResult) while oracleResult != 'success': rego = getconf.oraclesregister_rpc(chain, orclid, datafee) print("rego: " + str(rego)) oracleHex = rego['hex'] print("oracleHex: " + oracleHex) oracleResult = rego['result'] print("reg oracleResult: " + oracleResult) print("Oracle registered") print("--------------------- SENDING RAW --------------------- ") result = getconf.sendrawtx_rpc(chain, oracleHex) print("rawtx: " + str(result)) print("rawtx['result']: " + result['result']) while len(result['result']) != 64: time.sleep(15) result = getconf.sendrawtx_rpc(chain, oracleHex) print("rawtx: " + str(result)) print("rawtx['result']: " + result['result']) rego_hex = result['result'] print("raw rego_hex: " + rego_hex) print("--------------------- Confirm Tx --------------------- ") memPool = str(getconf.getrawmempool_rpc(chain)) while memPool.find(rego_hex) < 0: time.sleep(15) memPool = str(getconf.getrawmempool_rpc(chain)) print(memPool) print("mempool rego_hex: " + rego_hex) print("Oracle rego confirmed") print("--------------------- Get Info --------------------- ") time.sleep(60) orcl_info = getconf.oraclesinfo_rpc(chain, orclid) print("info: " + str(orcl_info)) reg_json = orcl_info['registered'] print("reg: " + str(reg_json)) while len(reg_json) < 1: time.sleep(30) reg_json = orcl_info['registered'] print("reg: " + str(reg_json)) print("len: " + str(len(reg_json))) print("reg: " + str(reg_json)) print("len: " + str(len(reg_json))) print( "DONE --------------------------------------------------------------------------------" ) name = orcl_info['name'] print("name: " + str(name)) orclid = orcl_info['txid'] print("orclid: " + str(orclid)) funds = '{:.2f}'.format(float(orcl_info['registered'][0]['funds'])) print("funds: " + str(funds)) publisher = str(orcl_info['registered'][0]['publisher']) print("pub: " + str(publisher)) #sql = "UPDATE "+userdb+" SET orcl_id = '"+orclid+"', orcl_pub = '"+publisher+"' WHERE user_id = '"+user_id+"';" print(sql) result = pgio.pgsqlio(sql) print(result) return orclid
except IOError as e: print("Password not set or access denied!") try: with open(CONFIGDIR + 'orclid.gps', 'r') as file: ORCLID = file.read() except IOError as e: print("Oracle Tx ID not set!") try: with open(CONFIGDIR + 'chain.gps', 'r') as file: CHAIN = file.read() except IOError as e: print("CHAIN not set!") chosen_info = getconf.oraclesinfo_rpc(CHAIN, ORCLID) batonutxo = chosen_info['registered'][0]['batontxid'] try: num = 1 sample = getconf.oraclessamples_rpc(CHAIN, ORCLID, batonutxo, num) print(json.dumps(sample['samples'][0][0])) dec = enc.decrypt(str.encode(sample['samples'][0][0]), pword) msg = bytes.decode(dec) msg2 = msg.replace("'", "\"") data = json.loads(msg2) dataList = data['data'].split(',') timestamp = int(time.time()) lon = dataList[0] lat = dataList[1] charge = dataList[2] except IOError as e:
def default(self, token): gpsdata = "" try: with open(CONFIGDIR + 'gps.pgs', 'r') as file: pword = file.read() except IOError as e: print("Password not set or access denied!") try: with open(CONFIGDIR + 'orclid.gps', 'r') as file: ORCLID = file.read() except IOError as e: print("Oracle Tx ID not set!") try: with open(CONFIGDIR + 'chain.gps', 'r') as file: CHAIN = file.read() except IOError as e: print("CHAIN not set!") chosen_info = getconf.oraclesinfo_rpc(CHAIN, ORCLID) batonutxo = chosen_info['registered'][0]['batontxid'] name = chosen_info['name'] funds = '{:.2f}'.format(float(chosen_info['registered'][0]['funds'])) publisher = chosen_info['registered'][0]['publisher'] print("name: " + str(name)) print("funds: " + str(funds)) print("publisher: " + str(publisher)) if float(funds) < 200: amount = 5 print("adding oracle funds") result = getconf.oraclessubscribe_rpc(CHAIN, ORCLID, publisher, amount) print(result) print("oracle funds added!") chosen_info = getconf.oraclesinfo_rpc(CHAIN, ORCLID) funds = '{:.2f}'.format( float(chosen_info['registered'][0]['funds'])) print("Oracle funds: " + funds) num = 99 samples = getconf.oraclessamples_rpc(CHAIN, ORCLID, batonutxo, num) num_samples = len(samples['samples']) print("num_samples: " + str(num_samples)) leaflet_data = [] points = [] lastpoint = "" lastcharge = "" bounds = "" view = "" point_var = "" opac = 0.99 i = 0 for sample in samples['samples']: try: dec = enc.decrypt(str.encode(sample[0]), pword) msg = bytes.decode(dec) msg2 = msg.replace("'", "\"") data = json.loads(msg2) dataList = data['data'].split(',') timestamp = data['published_at'] try: timestamp = datetime.utcfromtimestamp(float( timestamp)).strftime('%Y-%m-%d %H:%M:%S') + " UTC" except Exception as e: timestamp = data['published_at'] pass if lastpoint == "": print("adding first point") print('time: ' + str(timestamp)) print('lon: ' + dataList[0]) print('lat: ' + dataList[1]) print('c: ' + dataList[2]) lastpoint = makePoint([dataList[0], dataList[1]], 'skrunch', str(timestamp), 'lastping', '1') bounds = "" + str(dataList[0]) + "," + str( dataList[1]) + "," + str(dataList[0]) + "," + str( dataList[1]) + "" view = "" + dataList[0] + "," + dataList[1] + "" lastcharge = dataList[2] elif (float(dataList[1]) > lon_max or float(dataList[1]) < lon_min or float(dataList[0]) > lat_max or float(dataList[0]) < lat_min): point_var += makePoint([dataList[0], dataList[1]], 'paw', str(timestamp), 'paws', str(opac)) leaflet_data.append( json.loads('{"time":"' + timestamp + '", "lat":' + dataList[1] + ', "lon":' + dataList[0] + ',"charge":' + dataList[2] + '}')) opac -= 0.01 points.append([dataList[0], dataList[1]]) except Exception as e: print(e) #print("point_var: "+str(point_var)) try: if 1 != 1: underlay1 = makeLines('UNDERLAY_VAR1', 'UNDERLAY_1', points[0:11], '#ffffff', '4.2', '0.7', '30', 'underlay') underlay2 = makeLines('UNDERLAY_VAR2', 'UNDERLAY_2', points[10:22], '#ffffff', '4', '0.7', '30', 'underlay') underlay3 = makeLines('UNDERLAY_VAR3', 'UNDERLAY_3', points[21:33], '#ffffff', '3.8', '0.7', '30', 'underlay') underlay4 = makeLines('UNDERLAY_VAR4', 'UNDERLAY_4', points[32:44], '#ffffff', '3.6', '0.7', '30', 'underlay') underlay5 = makeLines('UNDERLAY_VAR5', 'UNDERLAY_5', points[43:55], '#ffffff', '3.4', '0.7', '30', 'underlay') underlay6 = makeLines('UNDERLAY_VAR6', 'UNDERLAY_6', points[54:66], '#ffffff', '2.6', '0.7', '30', 'underlay') underlay7 = makeLines('UNDERLAY_VAR7', 'UNDERLAY_7', points[65:77], '#ffffff', '2', '0.7', '30', 'underlay') underlay8 = makeLines('UNDERLAY_VAR8', 'UNDERLAY_8', points[76:88], '#ffffff', '2', '0.7', '30', 'underlay') underlay9 = makeLines('UNDERLAY_VAR9', 'UNDERLAY_9', points[87:99], '#ffffff', '2', '0.7', '30', 'underlay') track1 = makeLines('TRACK_VAR1', 'TRACK_1', points[0:11], '#667DFF', '2.2', '0.7', '30', 'dogtracks') track2 = makeLines('TRACK_VAR2', 'TRACK_2', points[10:22], '#057DFF', '2', '0.7', '30', 'dogtracks') track3 = makeLines('TRACK_VAR3', 'TRACK_3', points[21:33], '#057DFF', '1.8', '0.7', '30', 'dogtracks') track4 = makeLines('TRACK_VAR4', 'TRACK_4', points[32:44], '#057DFF', '1.6', '0.7', '30', 'dogtracks') track5 = makeLines('TRACK_VAR5', 'TRACK_5', points[43:55], '#057DFF', '1.4', '0.7', '30', 'dogtracks') track6 = makeLines('TRACK_VAR6', 'TRACK_6', points[54:66], '#057DFF', '1.2', '0.7', '30', 'dogtracks') track7 = makeLines('TRACK_VAR7', 'TRACK_7', points[65:77], '#057DFF', '1', '0.7', '30', 'dogtracks') track8 = makeLines('TRACK_VAR8', 'TRACK_8', points[76:88], '#057DFF', '1', '0.7', '30', 'dogtracks') track9 = makeLines('TRACK_VAR9', 'TRACK_9', points[87:99], '#057DFF', '1', '0.7', '30', 'dogtracks') except Exception as e: raise e try: with open(HTMLDIR + 'scrunch.html', 'r') as file: print("Populating template") numPoints = len(points) print("numPoints: " + str(numPoints)) dh_map = file.read() if 1 != 1: dh_map = dh_map.replace('UNDERLAY_VAR1', underlay1) dh_map = dh_map.replace('UNDERLAY_VAR2', underlay2) dh_map = dh_map.replace('UNDERLAY_VAR3', underlay3) dh_map = dh_map.replace('UNDERLAY_VAR4', underlay4) dh_map = dh_map.replace('UNDERLAY_VAR5', underlay5) dh_map = dh_map.replace('UNDERLAY_VAR6', underlay6) dh_map = dh_map.replace('UNDERLAY_VAR7', underlay7) dh_map = dh_map.replace('UNDERLAY_VAR8', underlay8) dh_map = dh_map.replace('UNDERLAY_VAR9', underlay9) dh_map = dh_map.replace('TRACK_VAR1', track1) dh_map = dh_map.replace('TRACK_VAR2', track2) dh_map = dh_map.replace('TRACK_VAR3', track3) dh_map = dh_map.replace('TRACK_VAR4', track4) dh_map = dh_map.replace('TRACK_VAR5', track5) dh_map = dh_map.replace('TRACK_VAR6', track6) dh_map = dh_map.replace('TRACK_VAR7', track7) dh_map = dh_map.replace('TRACK_VAR8', track8) dh_map = dh_map.replace('TRACK_VAR9', track9) dh_map = dh_map.replace('BOUNDS_VAR', bounds) dh_map = dh_map.replace('SETVEIW_VAR', view) dh_map = dh_map.replace('CHARGE_VAR', lastcharge) dh_map = dh_map.replace('POINTS_VAR', point_var) dh_map = dh_map.replace('LASTPOINT_VAR', lastpoint) dh_map = dh_map.replace('FUNDS_VAR', funds) #print(dh_map) except IOError as e: print("Password not set or access denied!") return dh_map
def default(self, token): gpsdata = "" try: with open(CONFIGDIR + 'gps.pgs', 'r') as file: pword = file.read() except IOError as e: print("Password not set or access denied!") try: with open(CONFIGDIR + 'orclid.gps', 'r') as file: ORCLID = file.read() except IOError as e: print("Oracle Tx ID not set!") try: with open(CONFIGDIR + 'chain.gps', 'r') as file: CHAIN = file.read() except IOError as e: print("CHAIN not set!") chosen_info = getconf.oraclesinfo_rpc(CHAIN, ORCLID) batonutxo = chosen_info['registered'][0]['batontxid'] name = chosen_info['name'] funds = '{:.2f}'.format(float(chosen_info['registered'][0]['funds'])) publisher = chosen_info['registered'][0]['publisher'] print("name: " + str(name)) print("funds: " + str(funds)) print("publisher: " + str(publisher)) if float(funds) < 200: amount = 50 result = getconf.oraclessubscribe_rpc(CHAIN, ORCLID, publisher, amount) print("oracle funds added!") chosen_info = getconf.oraclesinfo_rpc(CHAIN, ORCLID) funds = '{:.2f}'.format( float(chosen_info['registered'][0]['funds'])) print("Oracle funds: " + funds) num = 99 samples = getconf.oraclessamples_rpc(CHAIN, ORCLID, batonutxo, num) num_samples = len(samples['samples']) print("num_samples: " + str(num_samples)) leaflet_data = [] points = [] lastpoint = "" lastcharge = "" bounds = "" view = "" point_var = "" opac = 0.99 i = 0 for sample in samples['samples']: try: dec = enc.decrypt(str.encode(sample[0]), pword) msg = bytes.decode(dec) msg2 = msg.replace("'", "\"") data = json.loads(msg2) dataList = data['data'].split(',') timestamp = data['published_at'] #print('time: '+timestamp) timestamp = datetime.utcfromtimestamp( float(timestamp)).strftime('%Y-%m-%d %H:%M:%S') + " UTC" #print('time: '+str(timestamp)) if lastpoint == "": print("adding last point") print('time: ' + str(timestamp)) print('lon: ' + dataList[0]) print('lat: ' + dataList[1]) print('c: ' + dataList[2]) lastpoint = makePoint([dataList[0], dataList[1]], 'skrunch', str(timestamp), 'lastping', '1') bounds = "" + str(dataList[0]) + "," + str( dataList[1]) + "," + str(dataList[0]) + "," + str( dataList[1]) + "" view = "" + dataList[0] + "," + dataList[1] + "" lastcharge = dataList[2] else: point_var += makePoint([dataList[0], dataList[1]], 'paw', str(timestamp), 'paws', str(opac)) leaflet_data.append( json.loads('{"time":"' + timestamp + '", "lat":' + dataList[1] + ', "lon":' + dataList[0] + ',"charge":' + dataList[2] + '}')) opac -= 0.01 points.append([dataList[0], dataList[1]]) except Exception as e: print(e) numPoints = len(points) print("numPoints: " + str(numPoints)) try: with open(HTMLDIR + 'demo.html', 'r') as file: dh_map = file.read() dh_map = dh_map.replace('BOUNDS_VAR', bounds) dh_map = dh_map.replace('SETVEIW_VAR', view) dh_map = dh_map.replace('CHARGE_VAR', lastcharge) dh_map = dh_map.replace('POINTS_VAR', point_var) dh_map = dh_map.replace('LASTPOINT_VAR', lastpoint) dh_map = dh_map.replace('FUNDS_VAR', funds) #print(dh_map) except IOError as e: print("Password not set or access denied!") return dh_map