def topup(user_details, text_body): print('Found topup request') components = text_body.split(" ") cardcode = str.upper(components[1]) account = nano.get_address(user_details.id + 1, str(wallet_seed)) current_time = int(time.time()) print('User request: ', account, '\nTime: ', current_time) #check card code valid card_valid = TopupCards.get_or_none(TopupCards.cardcode == cardcode) if card_valid == None: print("Card code error " + cardcode) resp = MessagingResponse() resp.message("Error: Invalid Topup voucher code") return resp if card_valid.claimed == True: print("Card already claimed " + cardcode) resp = MessagingResponse() resp.message("Card has already been claimed") return resp topupadd = nano.get_address(1, str(wallet_seed)) previous = nano.get_previous(str(topupadd)) topupadd_bal = int(nano.get_balance(previous)) card_val = card_valid.cardvalue / 10 #DELETE AFTER ALPHA TOP UP CARDS ARE DEPLETED card_val = card_val * 1000000000000000000000000000000 #Card value in RAW if topupadd_bal < card_val: print(f'Insufficient Balance\n' f'Address Balance: {topupadd_bal} \nCard request: {card_val}') else: nano.send_xrb(account, card_val, topupadd, 1, str(wallet_seed)) previous = nano.get_previous(str(account)) print("Testing previous: ", previous) print("Len previous", len(previous)) if len(previous) == 0: balance = 0 else: balance = int(nano.get_balance(previous))/ \ 1000000000000000000000000000000 balance = balance resp = MessagingResponse() resp.message(f'Topup success!\n' f'Your new account balance is approx {balance}\n') print(f'Success topup to {account} from topup address\n' f'Address Balance {topupadd_bal-card_val}') card_valid.claimed = True card_valid.save() return resp
def dispatch_client(self): try: while True: line = yield self.stream.read_until(b'\n') self.log('got |%s|' % line.decode('utf-8').strip()) print("{} {}".format(time.strftime("%d/%m/%Y %H:%M:%S"), line)) split_data = line.rstrip().decode('utf8').split(",") if split_data[0] == "shutdown": print("Shutdown Socket Server and Exit") tornado.ioloop.IOLoop.instance().stop() sys.exit() elif split_data[0] == "pay_server": print("Pay Nano to Server") dest_account = 'xrb_' + split_data[1] amount = str(server_payin) previous = nano.get_previous(self.account) current_balance = nano.get_balance(previous) if int(current_balance) >= server_payin: return_block = nano.send_xrb(dest_account, int(amount), self.account, int(self.index), self.wallet_seed) return_string = "Block: {}".format(return_block) yield self.stream.write(return_string.encode('ascii')) else: print("Error - insufficient funds") return_string = "Error insufficent funds" yield self.stream.write(return_string.encode('ascii')) elif split_data[0] == "balance": print("Nano Balance") new_balance = 'Empty' try: previous = nano.get_previous(self.account) current_balance = nano.get_balance(previous) new_balance = float(current_balance) / raw_in_xrb except: pass print("Balance: {}".format(new_balance)) return_string = "{} Nano".format(new_balance) yield self.stream.write(return_string.encode('ascii')) elif split_data[0] == "rates": print("Nano Rates") return_string = "Rates {}".format("0") yield self.stream.write(return_string.encode('ascii')) except tornado.iostream.StreamClosedError: pass
def claim(user_details, text_body): faucet = nano.get_address(0, str(wallet_seed)) print("Found faucet claim") account = nano.get_address(user_details.id + 1, str(wallet_seed)) current_time = int(time.time()) if int(user_details.claim_last) == 0: print("They can claim") # Check faucet balance previous = nano.get_previous(str(faucet)) faucet_bal = int(nano.get_balance(previous))/ \ 1000000000000000000000000000000 claim = faucet_bal * 0.01 print("Faucet claim: ", claim, "\nFaucet balance: ", faucet_bal) nano.send_xrb(account, claim, faucet, 0, str(wallet_seed)) user_details.claim_last = 1 user_details.save() resp = MessagingResponse() resp.message(f'Claim Success {claim}\n' f'Send balance to check your balance' f'AD1: Place your ad here!\n' f'AD2: Place your ad here!\n') print(f'{claim} sent to {account} from faucet\n' f'Faucet funds remaining {faucet_bal-claim}') return resp else: print('User has already claimed') resp = MessagingResponse() resp.message("This number has already made a claim") return resp
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 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)
def send(user_details, text_body): print('Found send') account = nano.get_address(user_details.id + 1, str(wallet_seed)) components = text_body.split(" ") previous = nano.get_previous(str(account)) balance = int(nano.get_balance(previous)) # Check amount is real try: print("Sending: ", Decimal(components[1]) * 1000000000000000000000000000000) amount = int(Decimal(components[1]) * 1000000000000000000000000000000) print('Amount to send: ', amount) authcode = int(components[3]) except: resp = MessagingResponse() resp.message( "Error: Incorrect Amount please use the following format\nsend 10 +1234567890 1001" ) return str(resp) print('Error with send') destination = components[2] destination = destination.replace("\u202d", "") destination = destination.replace("\u202c", "") authcode = int(components[3]) #Test Number validity regex = "(\d{3}[-\.\s]??\d{3}[-\.\s]??\d{4}|\(\d{3}\)\s*\d{3}[-\.\s]??\d{4}|\d{3}[-\.\s]??\d{4})" if re.search(regex, destination): valid_num = "Yes" else: valid_num = "No" print(f'Destination: {destination}\nValid Number: {valid_num}') if authcode == int(user_details.authcode): print('Authcode valid!') if amount > balance: print("Insufficient balance", "\nAmount to send: ", str(amount), "\nBalance: ", str(balance / 1000000000000000000000000000000)) resp = MessagingResponse() resp.message(f'Insufficient balance!\nYour Balance: {balance}') return resp #Send to xrb address if destination[:4] == "xrb_": print("Destination is xrb addresses format") nano.send_xrb(destination, amount, account, user_details.id + 1, str(wallet_seed)) resp = MessagingResponse() new_authcode = authcode_gen_save(user_details) previous = nano.get_previous(str(account)) balance = int(nano.get_balance(previous))/\ 1000000000000000000000000000000 resp.message( f'Sent to {destination}!\nYour Balance approx.: {balance}\nNew Authcode: {new_authcode}' ) return resp #Send to Alias if valid_num == "No": print("Sending request to alias address ", destination) dest_user_details = Alias.get_or_none(alias=destination) if dest_user_details is not None: print(dest_user_details) dest_address = dest_user_details.address alias = dest_user_details.alias dest_phone = dest_user_details.phonenumber print(f'Sending to {dest_address} \nAlias: , {alias}') nano.send_xrb(dest_address, amount, account, user_details.id + 1, str(wallet_seed)) new_authcode = authcode_gen_save(user_details) previous = nano.get_previous(str(account)) balance = int(nano.get_balance(previous)) / \ 1000000000000000000000000000000 resp = MessagingResponse() resp.message( f'Sent to {destination}!\nYour Balance approx.: {balance}\nNew Authcode: {new_authcode}' ) return resp bodysend = 'You have recieved nano!\nPlease send register or balance to open your block on the Nano Network' twilionum = Config().get("twilionum") print(f'Sending: {bodysend}' f' to {dest_phone} from {twilionum}') message = client.messages.create(from_=twilionum, body=bodysend, to=dest_phone) print(message.sid) else: print("Alias not found ", destination) resp = MessagingResponse() resp.message( f'Error! Unrecognized Alias\nSet an alias with - set alias myAlias' ) return resp #send to phonenumber else: try: phonenum = phonenumbers.parse(destination, user_details.country) dest_phone = phonenumbers.format_number( phonenum, phonenumbers.PhoneNumberFormat.E164) print('Destination is phonenumber: ', dest_phone) except phonenumbers.phonenumberutil.NumberParseException: print("Error") resp = MessagingResponse() resp.message( "Error: Incorrect destination address/number try using E164 format" ) return resp if not phonenumbers.is_possible_number(phonenum): resp = MessagingResponse() resp.message("Error: Incorrect destination") return resp dest_user_details = User.get_or_none(phonenumber=dest_phone) print('\nReciepient ID: ', dest_user_details) #Send to phonenumber, and register if not registered. dest_user_details = User.get_or_none(phonenumber=dest_phone) if dest_user_details is None: dest_authcode = random.SystemRandom().randint(1000, 9999) rec_word = ''.join( random.sample(open("english.txt").read().split(), 5)) x = phonenumbers.parse(dest_phone, None) region = phonenumbers.region_code_for_number(x) print("Destination region: ", region) dest_user_details = User.create(phonenumber=dest_phone, country=region, time=datetime.now(), count=1, authcode=dest_authcode, claim_last=0, rec_word=rec_word) print("User created", dest_phone) dest_user_details = User.get_or_none(phonenumber=dest_phone) dest_address = nano.get_address(dest_user_details.id + 1, str(wallet_seed)) print("Sending to: " + dest_address) nano.send_xrb(dest_address, amount, account, user_details.id + 1, str(wallet_seed)) previous = nano.get_previous(str(account)) balance = int(nano.get_balance(previous))/ \ 1000000000000000000000000000000 bodysend = 'You have recieved nano!\nPlease send register or balance to open your block on the Nano Network' twilionum = Config().get("twilionum") print(f'Sending: {bodysend}' f' to {dest_phone} from {twilionum}') message = client.messages.create(from_=twilionum, body=bodysend, to=dest_phone) print(message.sid) resp = MessagingResponse() new_authcode = authcode_gen_save(user_details) resp.message( f'Sent to {destination}!\nYour Balance approx.: {balance} \nNew Authcode: {new_authcode}' ) return resp else: print('Invalid authcode! \nAuthcode submitted: ', authcode) new_authcode = authcode_gen_save(user_details) print('Authcode required: ', new_authcode) resp = MessagingResponse() resp.message("Error: Incorrect Auth Code try: " + str(new_authcode)) return resp
if __name__ == "__main__": # Check twilio information print('Twilio client: ', client) print('Twilio number: ', Config().get("twilionum")) # Check faucet address on boot to make sure we are up to date 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)}')
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()
def dispatch_client(self): try: while True: line = yield self.stream.read_until(b'\n') self.log('got |%s|' % line.decode('utf-8').strip()) print("{} {}".format(time.strftime("%d/%m/%Y %H:%M:%S"), line)) split_data = line.rstrip().decode('utf8').split(",") if split_data[0] == "shutdown": print("Shutdown Socket Server and Exit") tornado.ioloop.IOLoop.instance().stop() sys.exit() elif split_data[0] == "pay_server": print("Pay Nano to Server") global last_pay_time dest_account = 'xrb_' + split_data[1] amount = str(server_payin) current_balance = 'Empty' time_difference = time.time() - last_pay_time print(time_difference) if time_difference > 30: try: previous = nano.get_previous(self.account) current_balance = nano.get_balance(previous) except: pass if current_balance == 'Empty' or current_balance == '': return_string = "Error empty balance" yield self.stream.write( return_string.encode('ascii')) if int(current_balance) >= server_payin: return_block = nano.send_xrb( dest_account, int(amount), self.account, int(self.index), self.wallet_seed) last_pay_time = time.time() return_string = "Block: {}".format(return_block) yield self.stream.write( return_string.encode('ascii')) else: print("Error - insufficient funds") return_string = "Error insufficent funds" yield self.stream.write( return_string.encode('ascii')) else: print("Last pay in less that 30 seconds ago") return_string = "Last pay in less that 30 seconds ago" yield self.stream.write(return_string.encode('ascii')) elif split_data[0] == "balance": print("Nano Balance") new_balance = 'Empty' try: previous = nano.get_previous(self.account) current_balance = nano.get_balance(previous) new_balance = Decimal(current_balance) / Decimal( raw_in_xrb) except: pass if new_balance != 'Empty': print("Balance: {:.3}".format(new_balance)) #print("- $:",Decimal(r.json()['NANO']['USD'])*new_balance) #print("- £:",Decimal(r.json()['NANO']['GBP'])*new_balance) #print("- €:",Decimal(r.json()['NANO']['EUR'])*new_balance) return_string = "{:.5} Nano".format(new_balance) yield self.stream.write(return_string.encode('ascii')) elif split_data[0] == "nano_address": return_string = "{}".format(self.account[4:]) yield self.stream.write(return_string.encode('ascii')) elif split_data[0] == "rates": try: r = nano.get_rates() except: pass return_string = "USD:" + str( r.json()['NANO']['USD']) + " - GBP:" + str( r.json()['NANO']['GBP']) + " - EURO:" + str( r.json()['NANO']['EUR']) yield self.stream.write(return_string.encode('ascii')) except tornado.iostream.StreamClosedError: pass
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() print('Channel Opened') nano.send_xrb(target_account, 1, account, 0, wallet_seed) else: print("Waiting for host...") wait_for_reply(account)
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()