def chargify(): dtime = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') id = request.get_json()['id'] invoice_data = get_invoice(id=id) #print(invoice_data) address = str(invoice_data['description']).replace('BitClouds.sh: ', '') status = invoice_data['status'] amount_sats = int(int(invoice_data['msatoshi']) / 1000) bolt = invoice_data['payreq'] print(dtime + " new status [" + status + "] for [" + id + "]") if status == 'paid': new_host = find_host(address) if new_host: if new_host['status'] == 'new': global task_running while task_running: time.sleep(30) task_running = True if task_running: _ = new_server(address, new_host['image']) time.sleep(15) task_running = False add_tx(address=address, txhash=bolt, amount_sats=amount_sats, status='confirmed', chargeid=id, prev_outhash='none') hours = convert_sats2hours(address, amount_sats) subscribe_host(address, hours) print("\n" + dtime + " TOP-UP " + str(find_host(address)) + "\n\n") return ''
def post(self): parser = reqparse.RequestParser() parser.add_argument('id') args = parser.parse_args() dtime = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') try: id = args['id'] except KeyError as e: print(dtime + ': error on handling callback from charge - ' + str(e)) return False invoice_data = get_invoice(id=id) #print(invoice_data) address = invoice_data['description'] status = invoice_data['status'] amount_sats = int(int(invoice_data['msatoshi'])/1000) bolt = invoice_data['payreq'] print(dtime + " new status [" + status + "] for [" + id + "]") if status == 'paid': new_host = find_host(address) if new_host: if new_host['status'] == 'new': serverData = new_server(address, new_host['image']) add_tx(address=address, txhash=bolt, amount_sats=amount_sats, status='confirmed', chargeid=id, prev_outhash='none') hours = convert_sats2hours(address, amount_sats) subscribe_host(address, hours) print("\n\n" + str(find_host(address)) + "\n\n") return True
def elify(): dtime = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') data = request.get_json() status = '[' + data['status'] + ']' address = '[' + data['address'] + ']' print(dtime + " new status " + status + " for " + address) if status != '': unspents = blistunspent(wallet) #print(unspents) for unspent in unspents: if address == unspent['address']: amount_sats = unspent['value'] * 100000000 outhash = status prev_outhash = unspent['prevout_hash'] if unspent['height'] == 0: if not find_tx(outhash): add_tx(address=address, txhash=outhash, amount_sats=amount_sats, status='paid', chargeid='none', prev_outhash=prev_outhash) else: print(dtime + 'tx already exists') elif unspent['height'] > 0: existing_tx = find_tx(outhash) if existing_tx: if existing_tx['status'] == 'paid': new_host = find_host(address) if new_host: if new_host['status'] == 'new': global task_running while task_running: time.sleep(30) task_running = True if task_running: _ = new_server(address, new_host['image']) task_running = False update_tx(address, outhash, 'confirmed') hours = convert_sats2hours(address, amount_sats) subscribe_host(address, hours) print("\n\n" + str(find_host(address)) + "\n\n") else: print(dtime + ' ' + outhash + 'tx already confirmed') else: print(dtime + ' ' + outhash + ' tx not found but confirmed') return ''
def post(self): parser = reqparse.RequestParser() parser.add_argument('address') parser.add_argument('status') args = parser.parse_args() dtime = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') try: status = '['+str(args['status'])+']' address = '['+str(args['address'])+']' except KeyError as e: print(dtime + ' no data' + str(e)) print(request.get_data()) return False print(dtime + " new status " + status + " for " + address) if status is not '': unspents = blistunspent(wallet) #print(unspents) for unspent in unspents: if address == unspent['address']: amount_sats = unspent['value']*100000000 outhash = status prev_outhash = unspent['prevout_hash'] if unspent['height'] == 0: if not find_tx(outhash): add_tx(address=address, txhash=outhash, amount_sats=amount_sats, status='paid', chargeid='none', prev_outhash=prev_outhash) else: print(dtime + 'tx already exists') elif unspent['height'] > 0: existing_tx = find_tx(outhash) if existing_tx: if existing_tx['status'] == 'paid': new_host = find_host(address) if new_host: if new_host['status'] == 'new': serverData = new_server(address, new_host['image']) update_tx(address, outhash, 'confirmed') hours = convert_sats2hours(address, amount_sats) subscribe_host(address, hours) print("\n\n" + str(find_host(address)) + "\n\n") else: print(dtime + ' ' + outhash + 'tx already confirmed') else: print(dtime + ' ' + outhash + ' tx not found but confirmed') return True
def newaddr(): dtime = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') #address = str(bgetunused(wallet).rstrip()) image = request.form['image'] address = getStar() inc = 0 while find_host(address): inc += 1 address = getStar() + '-' + str(inc) result = {"address": address} print(dtime) print("new addr:" + address + ";\nwill notify:" + notifyURL + ";\n") #bnotify(wallet, address, notifyURL) create_host(address, "basic", image) return jsonify(result)
def post(self): dtime = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') address = str(bgetunused(wallet).rstrip()) parser = reqparse.RequestParser() parser.add_argument('image') args = parser.parse_args() image = args['image'] if find_host(address): print('unused addr: ' + address) address = str(bgetnew(wallet).rstrip()) else: pass result = { "address": address } print(dtime) print("new addr:" + address + ";\nwill notify:" + notifyURL + ";\n") bnotify(wallet, address, notifyURL) create_host(address, "basic", image) return result