def check_account(account, wallet_seed, index): #print("Check for blocks") pending = nano.get_pending(str(account)) #print("Pending Len:" + str(len(pending))) while len(pending) > 0: pending = nano.get_pending(str(account)) nano.receive_xrb(int(index), account, wallet_seed)
def update_txt(root, y, account, wallet_seed, index, listbox): # Process any pending blocks print(_("Checking for update")) pending = nano.get_pending(str(account)) if pending == "timeout": root.update_idletasks() root.after( 5000, lambda: update_txt(root, y, account, wallet_seed, index, listbox)) return previous = nano.get_previous(str(account)) if len(pending) > 0: print(_("Processing...")) while len(pending) > 0: pending = nano.get_pending(str(account)) if pending == "timeout": continue try: if len(previous) == 0: print(_("Opening Account")) hash, balance = nano.open_xrb(int(index), account, wallet_seed) print(_("Reply {} {}").format(reply, balance)) if hash != 'timeout' and hash != None: listbox.insert( END, "{}... {:.4} Nano".format( hash['hash'][:24], Decimal(balance) / Decimal(raw_in_xrb))) listbox.itemconfig(END, {'bg': 'spring green'}) #We get previous after opening the account to switch it to receive rather than open previous = nano.get_previous(str(account)) else: hash, balance = nano.receive_xrb(int(index), account, wallet_seed) print(_("Reply {} {}").format(hash, balance)) if hash != 'timeout' and hash != None: listbox.insert( END, "{}... {:.4} Nano".format( hash['hash'][:24], Decimal(balance) / Decimal(raw_in_xrb))) listbox.itemconfig(END, {'bg': 'spring green'}) except: print(_("Error processing blocks")) try: current_balance = nano.get_account_balance(account) if current_balance != "timeout": y.config(text="{:.3} Nano".format( Decimal(current_balance) / Decimal(raw_in_xrb))) else: y.config(text=_("Timeout")) except: y.config(text=_("Account Not Open")) root.update_idletasks() root.after( 5000, lambda: update_txt(root, y, account, wallet_seed, index, listbox))
def get_reply(account, index, wallet_seed): pending = nano.get_pending(str(account)) while len(pending) > 0: rx_amount = nano.receive_xrb(int(index), account, wallet_seed) pending = nano.get_pending(str(account)) print(len(pending)) print('Rx amount %s' % rx_amount) return rx_amount
def balance(user_details, text_body): print('Found balance') account = nano.get_address(user_details.id + 1, str(wallet_seed)) faucet = nano.get_address(0, str(wallet_seed)) print(account) previous = nano.get_previous(str(account)) print(previous) print(len(previous)) pending = nano.get_pending(str(account)) if (len(previous) == 0): print("Opening Account: ", account) nano.send_xrb(account, 1, faucet, 0, str(wallet_seed)) nano.open_xrb(int(user_details.id + 1), account, str(wallet_seed)) print("Rx Pending: ", pending) pending = nano.get_pending(str(account)) print(f'Pending Len: {len(pending)}') while len(pending) > 0: pending = nano.get_pending(str(account)) print(len(pending)) nano.receive_xrb(int(user_details.id + 1), account, str(wallet_seed)) if len(previous) == 0: balance = "Empty" else: previous = nano.get_previous(str(account)) balance = int(nano.get_balance(previous))/ \ 1000000000000000000000000000000 print("User balance", str(balance)) # Start our response resp = MessagingResponse() # Add a message resp.message(f'Balance: {balance} Nano') return resp
def search_pending(account, index_pos, api_key): pending = nano.get_pending(str(account)) print("Pending: {}".format(pending)) while len(pending) > 0: print("Processing new blocks") pending = nano.get_pending(str(account)) previous = nano.get_previous(str(account)) try: if len(previous) == 0: print("Opening Account") hash, balance = nano.open_xrb(int(index_pos), account, settings.wallet_seed, api_key) else: hash, balance = nano.receive_xrb(int(index_pos), account, settings.wallet_seed, api_key) except: print("Error processing blocks") return 0
def sms_ahoy_reply(): print(request.values) from_number = request.values.get('From') from_country = request.values.get('FromCountry') user_details = user_table.find_one(number=from_number) print(user_details) if user_details == None: authcode = (random.SystemRandom().randint(1000, 9999)) user_table.insert( dict(number=from_number, time=int(time.time()), count=1, authcode=authcode, claim_last=0)) user_details = user_table.find_one(number=from_number) else: user_table.update( dict(number=from_number, time=int(time.time()), count=(int(user_details['count']) + 1)), ['number']) text_body = request.values.get('Body') text_body = text_body.lower() new_authcode = (random.SystemRandom().randint(1000, 9999)) if 'register' in text_body: print('Found register') account = nano.get_address(user_details['id']) # Start our response resp = MessagingResponse() # Add a message resp.message("Welcome to NanoSMS, your address:\n" + account + ", Code: " + str(new_authcode)) elif 'details' in text_body: print('Found help') resp = MessagingResponse() resp.message( "balance - get your balance\n send - send Nano\n address - your nano address" + ", Code: " + str(new_authcode)) elif 'address' in text_body: print('Found address') account = nano.get_address(user_details['id']) resp = MessagingResponse() resp.message(account + ", Code: " + str(new_authcode)) elif 'history' in text_body: print('Found address') account = nano.get_address(user_details['id']) resp = MessagingResponse() resp.message("https://www.nanode.co/account/" + account + ", Code: " + str(new_authcode)) elif 'balance' in text_body: print('Found balance') account = nano.get_address(user_details['id']) print(account) previous = nano.get_previous(str(account)) print(previous) print(len(previous)) pending = nano.get_pending(str(account)) if (len(previous) == 0) and (len(pending) > 0): print("Opening Account") nano.open_xrb(int(user_details['id']), account) print("Rx Pending: ", pending) pending = nano.get_pending(str(account)) print("Pending Len:" + str(len(pending))) while len(pending) > 0: pending = nano.get_pending(str(account)) print(len(pending)) nano.receive_xrb(int(user_details['id']), account) if len(previous) == 0: balance = "Empty" else: previous = nano.get_previous(str(account)) balance = int( nano.get_balance(previous)) / 1000000000000000000000000 print(balance) # Start our response resp = MessagingResponse() # Add a message resp.message("Balance: " + str(balance) + " nanos" + ", Code: " + str(new_authcode)) elif 'send' in text_body: print('Found send') account = nano.get_address(user_details['id']) components = text_body.split(" ") # Check amount is real try: amount = int(components[1]) * 1000000000000000000000000 except: resp = MessagingResponse() resp.message("Error: Incorrect Amount") return str(resp) destination = components[2] destination = destination.replace("\u202d", "") destination = destination.replace("\u202c", "") authcode = int(components[3]) if authcode == int(user_details['authcode']): if destination[0] == "x": print("xrb addresses") nano.send_xrb(destination, amount, account, user_details['id']) resp = MessagingResponse() resp.message("Sent!" + ", Code: " + str(new_authcode)) return str(resp) else: try: phonenum = phonenumbers.parse(destination, from_country) dest_address = phonenumbers.format_number( phonenum, phonenumbers.PhoneNumberFormat.E164) except phonenumbers.phonenumberutil.NumberParseException: print("Error") resp = MessagingResponse() resp.message("Error: Incorrect destination address/number") return str(resp) if not phonenumbers.is_possible_number(phonenum): resp = MessagingResponse() resp.message("Error: Incorrect destination") return str(resp) dest_user_details = user_table.find_one(number=dest_address) print(dest_user_details) if dest_user_details == None: user_table.insert( dict(number=dest_address, time=0, count=0, authcode=0, claim_last=0)) dest_user_details = user_table.find_one(number=dest_address) nano.send_xrb(nano.get_address(dest_user_details['id']), amount, account, user_details['id']) resp = MessagingResponse() resp.message("Sent!" + ", Code: " + str(new_authcode)) else: resp = MessagingResponse() resp.message("Error: Incorrect Auth Code") return str(resp) elif 'claim' in text_body: print("Found claim") account = nano.get_address(user_details['id']) current_time = int(time.time()) if current_time > (int(user_details['claim_last']) + 86400): print("They can claim") amount = 10000000000000000000000000 nano.send_xrb(account, amount, nano.get_address(10), 10) user_table.update( dict(number=from_number, claim_last=int(time.time())), ['number']) resp = MessagingResponse() resp.message( "Claim Success (10 nanos)\nAD1: check out localnanos to exchange nano/VEF\nAD2: Cerveza Polar 6 for 1Nano at JeffMart, 424 Caracas\n" + "Code: " + str(new_authcode)) else: resp = MessagingResponse() resp.message("Error: Claim too soon") return str(resp) elif 'trust' in text_body: # Only works with local numbers. Do not supply country code. print("Found trust") components = text_body.split(" ") authcode = int(components[2]) if authcode == int(user_details['authcode']): if "x" in components[1][0]: try: if nano.xrb_account(components[1]): xrb_trust = components[1] resp = MessagingResponse() resp.message("Trust address set to " + components[1] + " Code:" + str(new_authcode)) user_table.update( dict(trust_address=xrb_trust, trust_number=0), ['id']) else: print("Invalid address") resp = MessagingResponse() resp.message("Invalid address" + str(new_authcode)) except KeyError: print("Invalid address") resp = MessagingResponse() resp.message("Invalid address" + str(new_authcode)) elif components[1].isdigit(): trust_number = components[1] resp = MessagingResponse() resp.message("Trust address set to " + components[1] + " Code: " + str(new_authcode)) user_table.update( dict(trust_address="", trust_number=trust_number), ['id']) else: print("No valid trust") resp = MessagingResponse() resp.message("No valid trust" + str(new_authcode)) else: resp = MessagingResponse() resp.message("Error: Incorrect Auth Code") return str(resp) else: print('Error') # Start our response resp = MessagingResponse() # Add a message resp.message("Error") user_table.update(dict(number=from_number, authcode=new_authcode), ['number']) return str(resp)
user_table.update(dict(number=from_number, authcode=new_authcode), ['number']) return str(resp) if __name__ == "__main__": #Check faucet address on boot to make sure we are up to date account = nano.get_address(10) print(account) previous = nano.get_previous(str(account)) print(previous) print(len(previous)) pending = nano.get_pending(str(account)) if (len(previous) == 0) and (len(pending) > 0): print("Opening Account") nano.open_xrb(int(10), account) print("Rx Pending: ", pending) pending = nano.get_pending(str(account)) print("Pending Len:" + str(len(pending))) while len(pending) > 0: pending = nano.get_pending(str(account)) print(len(pending)) nano.receive_xrb(int(10), account) app.run(debug=True, host="0.0.0.0", port=5002)
account = nano.get_address(0, str(wallet_seed)) print("Faucet Address: ", account) previous = nano.get_previous(str(account)) print("Previous Hash: ", previous) print("Hash Length: ", len(previous)) # Check faucet and topup address balance topupacc = nano.get_address(1, str(wallet_seed)) faucbal = int(nano.get_balance(nano.get_previous(account))) topupbal = int(nano.get_balance(nano.get_previous(topupacc))) print("\nFaucet Balance [RAW]: ", faucbal, "\nTopup Balance [RAW]: ", topupbal) print("\nFaucet Balance: ", faucbal / 1000000000000000000000000000000, "\nTopup Balance: ", topupbal / 1000000000000000000000000000000) pending = nano.get_pending(str(account)) if (len(previous) == 0) and (len(pending) > 0): print("Opening Account") nano.open_xrb(int(0), account, str(wallet_seed)) print(f'Rx Pending: {pending}') pending = nano.get_pending(str(account)) print(f'Pending Len: {len(pending)}') while len(pending) > 0: pending = nano.get_pending(str(account)) print(len(pending)) nano.receive_xrb(int(0), account, str(wallet_seed)) app.run(debug=True, host="0.0.0.0", port=5002)
def main(): print("Starting NanoQuake2...") print() parser = ConfigParser() config_files = parser.read('config.ini') while True: password = prompt('Enter password: '******'Confirm password: '******'seed.txt', wallet_seed) cfgfile = open("config.ini", 'w') parser.add_section('wallet') priv_key, pub_key = nano.seed_account(str(wallet_seed), 0) public_key = str(binascii.hexlify(pub_key), 'ascii') print("Public Key: ", str(public_key)) account = nano.account_xrb(str(public_key)) print("Account Address: ", account) parser.set('wallet', 'account', account) parser.set('wallet', 'index', '0') parser.write(cfgfile) cfgfile.close() index = 0 seed = wallet_seed else: print() print("Config file found") print("Decoding wallet seed with your password") try: wallet_seed = read_encrypted(password, 'seed.txt', string=True) priv_key, pub_key = nano.seed_account(str(wallet_seed), 0) public_key = str(binascii.hexlify(pub_key), 'ascii') print("Public Key: ", str(public_key)) account = nano.account_xrb(str(public_key)) print("Account Address: ", account) except: print('\nError decoding seed, check password and try again') sys.exit() index = 0 previous = nano.get_previous(str(account)) print() print("This is your game account address: {}".format(account)) if previous != "": current_balance = Decimal( nano.get_balance(previous)) / Decimal(raw_in_xrb) print("Your balance is {:.5} Nano".format( print_decimal(current_balance))) else: current_balance = 0 print("Your balance is 0 Nano") r = nano.get_rates() print() print("NANO Rates") print("- $:", r.json()['NANO']['USD']) print("- £:", r.json()['NANO']['GBP']) print("- €:", r.json()['NANO']['EUR']) while True: print() print("--------------") print("NanoQuake Menu") print("--------------") print("1. Start Game - Lets Get REKT...") print("2. Top-up Game Balance") print("3. Withdraw Funds") print("4. Display Seed") print("5. Check Balance") print("6. Exit") print() menu1 = 0 try: menu1 = int(input("Please select an option: ")) except: pass if menu1 == 6: print("Exiting NanoQuake") sys.exit() elif menu1 == 5: previous = nano.get_previous(str(account)) current_balance = nano.get_balance(previous) if current_balance == "": current_balance = 0 if int(current_balance) < server_payin: print() print("Insufficient funds - please deposit at least 0.1 Nano") print("{} Raw Detected...".format(current_balance)) #Scan for new blocks, wait for pending pending = nano.get_pending(str(account)) if len(pending) > 0: print() print( "This account has pending transactions. Follow option 2 to process..." .format(current_balance)) print("\nBalance: {:.5} Nano\n".format( Decimal(current_balance) / Decimal(raw_in_xrb))) elif menu1 == 4: print("\nSeed: {}\n".format(wallet_seed)) elif menu1 == 3: print("Withdraw Funds") withdraw_dest = input("Destination Address: ") previous = nano.get_previous(str(account)) current_balance = nano.get_balance(previous) nano.send_xrb(withdraw_dest, int(current_balance), account, int(index), wallet_seed) elif menu1 == 2: display_qr(account) previous = nano.get_previous(str(account)) pending = nano.get_pending(str(account)) #Scan for new blocks, wait for pending if len(pending) == 0: print("Waiting for funds...") wait_for_reply(account) # Process any pending blocks pending = nano.get_pending(str(account)) if len(pending) > 0: print("Processing...") while len(pending) > 0: pending = nano.get_pending(str(account)) if len(previous) == 0: print("Opening Account") nano.open_xrb(int(index), account, wallet_seed) #We get previous after opening the account to switch it to receive rather than open time.sleep( 2) #Just to make sure that the block as been recorded previous = nano.get_previous(str(account)) else: nano.receive_xrb(int(index), account, wallet_seed) print('.', end='', flush=True) time.sleep( 2) #give it chance so we down display message twice previous = nano.get_previous(str(account)) current_balance = nano.get_balance(previous) if int(current_balance) < server_payin: print() print("Insufficient funds - please deposit at least 0.1 Nano") print("({} Raw Detected)".format(current_balance)) else: print() print("Sufficient Funds - Lets Go!") print("Your balance is {:.5} Nano".format( Decimal(current_balance) / Decimal(raw_in_xrb))) elif menu1 == 1: previous = nano.get_previous(str(account)) current_balance = nano.get_balance(previous) #try: current_dir = os.getcwd() print(current_dir) #os.remove('~/.yq2/baseq2/config.cfg') #except OSError: # pass print("Starting Quake2") #game_args = "+set nano_address {} +set vid_fullscreen 0".format(account[4:]) game_args = "+set vid_fullscreen 0 &" print(game_args) if platform.system() == 'Windows': full_command = "start quake2 " + game_args else: full_command = "release/quake2 " + game_args print(full_command) process = subprocess.run(full_command, shell=True) # tcp server server = SimpleTcpServer(account, wallet_seed, index) server.listen(PORT, HOST) print("Listening on %s:%d..." % (HOST, PORT)) # pc = tornado.ioloop.PeriodicCallback( lambda: check_account(account, wallet_seed, index), 20000) pc.start() # infinite loop tornado.ioloop.IOLoop.instance().start() else: print("Error, incorrect option selected") sys.exit()
if (len(previous) == 0) and (len(pending) == 0): print("Account not open, please send value to " + account + " to activate") time.sleep(2) print("Closing Channel") sys.exit() pending = nano.get_pending(str(account)) if (len(previous) == 0) and (len(pending) > 0): print("Opening Account") nano.open_xrb(int(index), account, wallet_seed) pending = nano.get_pending(str(account)) while len(pending) > 0: pending = nano.get_pending(str(account)) nano.receive_xrb(int(index), account, wallet_seed) print("Account Address: ", account) #Check Balance balance = int(nano.get_balance(nano.get_previous(account))) if balance < 10000: print("Please send 0.1 Nano to this address") else: print('You have ' + str(balance) + ' to send emojis') host = int(input("To open channel press 1, else [Enter] to join existing: ")) target_account = input("Enter recieving account address: ") if host == 1: print()
def main(): print("Starting Nanoquake2") parser = ConfigParser() config_files = parser.read('config.ini') while True: password = prompt('Enter password: '******'Confirm password: '******'seed.txt', wallet_seed) cfgfile = open("config.ini", 'w') parser.add_section('wallet') priv_key, pub_key = nano.seed_account(str(wallet_seed), 0) public_key = str(binascii.hexlify(pub_key), 'ascii') print("Public Key: ", str(public_key)) account = nano.account_xrb(str(public_key)) print("Account Address: ", account) parser.set('wallet', 'account', account) parser.set('wallet', 'index', '0') parser.write(cfgfile) cfgfile.close() index = 0 seed = wallet_seed else: print("Config file found") print("Decoding wallet seed with your password") try: wallet_seed = read_encrypted(password, 'seed.txt', string=True) except: print('\nError decoding seed, check password and try again') sys.exit() account = parser.get('wallet', 'account') index = int(parser.get('wallet', 'index')) previous = nano.get_previous(str(account)) if previous != "": current_balance = float(nano.get_balance(previous)) / raw_in_xrb else: current_balance = 0 print("This is your game account address: {}, your balance is {} Nano". format(account, current_balance)) while True: print("Nanoquake Menu") print("1. Start the Game") print("2. TopUp Your Game Balance") print("3. Withdraw Funds") print("4. Display Seed") print("5. Exit") menu1 = 0 try: menu1 = int(input("Please select an option: ")) except: pass if menu1 == 5: print("Exiting Nanoquake") sys.exit() elif menu1 == 4: print("\nSeed: {}\n".format(wallet_seed)) elif menu1 == 3: print("Withdraw Funds") withdraw_dest = input("Destination Address: ") previous = nano.get_previous(str(account)) current_balance = nano.get_balance(previous) nano.send_xrb(withdraw_dest, int(current_balance), account, int(index), wallet_seed) elif menu1 == 2: display_qr(account) previous = nano.get_previous(str(account)) pending = nano.get_pending(str(account)) #print(previous) if (len(previous) == 0) and (len(pending) == 0): print("Please send at least 0.1Nano to this account") print("Waiting for funds...") wait_for_reply(account) pending = nano.get_pending(str(account)) if (len(previous) == 0) and (len(pending) > 0): print("Opening Account") nano.open_xrb(int(index), account, wallet_seed) #print("Rx Pending: ", pending) pending = nano.get_pending(str(account)) #print("Pending Len:" + str(len(pending))) while len(pending) > 0: pending = nano.get_pending(str(account)) print(len(pending)) nano.receive_xrb(int(index), account, wallet_seed) previous = nano.get_previous(str(account)) current_balance = nano.get_balance(previous) while int(current_balance) < server_payin: print("Insufficient funds - please deposit at least 0.1 Nano") wait_for_reply(account) while len(pending) > 0: pending = nano.get_pending(str(account)) print(len(pending)) nano.receive_xrb(int(index), account, wallet_seed) else: print("Sufficient Funds - Lets Go!") print("Your Balance: {}".format(current_balance)) elif menu1 == 1: previous = nano.get_previous(str(account)) current_balance = nano.get_balance(previous) print("Starting Quake2") #game_args = "+set nano_address {} +set vid_fullscreen 0".format(account[4:]) game_args = "+set nano_address {} +set vid_fullscreen 0 &".format( account[4:]) print(game_args) if platform.system() == 'Windows': full_command = "start quake2 " + game_args else: full_command = "release/quake2 " + game_args print(full_command) process = subprocess.run(full_command, shell=True) # tcp server server = SimpleTcpServer(account, wallet_seed, index) server.listen(PORT, HOST) print("Listening on %s:%d..." % (HOST, PORT)) # pc = tornado.ioloop.PeriodicCallback( lambda: check_account(account, wallet_seed, index), 10000) pc.start() # infinite loop tornado.ioloop.IOLoop.instance().start() else: print("Error, incorret option selected") sys.exit()