def create_or_update_online_wallet(wallet_status, addr, username, coin_symbol): response = dict() #wallet=get_wallet_addresses(wallet_name=username, api_key='993d49173a32400eba3aaafd8b94d336', coin_symbol=coin_symbol) if not wallet_status: try: create_wallet_from_address(wallet_name=username, address=addr, api_key=settings.TOKEN, coin_symbol=coin_symbol) except: time.sleep(30) create_wallet_from_address(wallet_name=username, address=addr, api_key=settings.TOKEN, coin_symbol=coin_symbol) status = True # which means wallet was just created else: try: ok = add_address_to_wallet(wallet_name=username, address=addr, api_key=settings.TOKEN, coin_symbol=coin_symbol) except: time.sleep(30) ok = add_address_to_wallet(wallet_name=username, address=addr, api_key=settings.TOKEN, coin_symbol=coin_symbol) status = False return status
def CreateWallet(self, WavesAddress): newWallet = Wallet.new_random_wallet() # private_key_hex = newWallet.get_private_key_hex() # public_key_hex = newWallet.get_public_key_hex() serializedWallet = newWallet.serialize() newAddress = newWallet.to_address() BTCWallet = create_wallet_from_address(wallet_name=WavesAddress, address=newAddress, api_key=self.APIKEY) #TODO SAVE WAVESAddress , serializeWlt in DB print(BTCWallet) con = lite.connect('test.db') with con: cur = con.cursor() cur.execute( "CREATE TABLE IF NOT EXISTS addresses(WavesAddress TEXT , serializedWallet TEXT , BTCaddress TEXT)" ) cur.execute( """INSERT INTO addresses VALUES(?,?,?)""", (WavesAddress, serializedWallet, BTCWallet['addresses'][0])) con.commit() # con.close() return {'addresses': BTCWallet['addresses'][0]}
def create_bitwallet(user): addr,pub,priv = gen_address(user) user.wallets.add(Wallet.objects.create(name='btc', address=addr, private=priv, public=pub)) user.save() resp = create_wallet_from_address(wallet_name=user.username, address=addr, api_key=API_KEY_BLOCK) if resp.get("addresses"): return resp.get("addresses")[0] else: return None
def create_related_profile(sender, instance, created, *args, **kwargs): # Notice that we're checking for `created` here. We only want to do this # the first time the `User` instance is created. If the save that caused # this signal to be run was an update action, we know the user already # has a profile. if instance and created: instance.profile = Profile.objects.create(user=instance) new_wallet = get_payment_adress_for_user(instance) wallet = create_wallet_from_address(wallet_name=instance.username, address=new_wallet['address'], api_key=settings.BLOCKCYPHER_TOKEN, coin_symbol=settings.COIN) instance.wallet = Wallet.objects.create( profile=instance.profile, receiving_address=new_wallet['address'], private=new_wallet['priv'], reg_private=new_wallet['reg_priv'])
def CreateWallet(self,WavesAddress): con = lite.connect('test.db') with con: cur = con.cursor() cur.execute("""SELECT id FROM addressid WHERE WavesAddress=:adr""", {"adr": WavesAddress}) row = cur.fetchone() if len(row)>0 : BTCWallet = get_wallet_addresses(wallet_name='Noay'+ str(row[0]), api_key=self.APIKEY, coin_symbol=self.coin_symbol) cur.execute("""SELECT * FROM addresses WHERE WavesAddress=:adr""", {"adr": WavesAddress}) row = cur.fetchone() wallet = Wallet.deserialize(row[1] , network=BitcoinTestNet) ModuleHandler.encode(wallet.get_public_key_hex()) con.commit() return { 'addresses' : BTCWallet['addresses'][0] , 'public_key' : ModuleHandler.encode( wallet.get_public_key_hex() ) } con.commit() newWallet = Wallet.new_random_wallet(network=BitcoinTestNet) # private_key_hex = newWallet.get_private_key_hex() # public_key_hex = newWallet.get_public_key_hex() serializedWallet = newWallet.serialize() newAddress = newWallet.to_address() # print('newAddress : ',newAddress) con = lite.connect('test.db') with con: cur = con.cursor() cur.execute("CREATE TABLE IF NOT EXISTS addressid(id INTEGER PRIMARY KEY AUTOINCREMENT, WavesAddress TEXT NOT NULL )") cur.execute("""INSERT INTO addressid (WavesAddress) VALUES(?)""",(WavesAddress,)) cur.execute("""SELECT id FROM addressid WHERE WavesAddress=:adr""", {"adr": WavesAddress}) con.commit() row = cur.fetchone() # print("row[0] : ",row[0]) #TODO handle {'error': 'Error: wallet exists'} BTCWallet = get_wallet_addresses(wallet_name='Noay'+ str(row[0]), api_key=self.APIKEY, coin_symbol=self.coin_symbol) try: s = BTCWallet['error'] print('BTCWallet' , 0) BTCWallet = create_wallet_from_address(wallet_name= 'Noay'+ str(row[0]), address=newAddress, api_key=self.APIKEY , coin_symbol=self.coin_symbol) #TODO SAVE WAVESAddress , serializeWlt in DB except Exception as e: con = lite.connect('test.db') print('BTCWallet' , 1) with con: cur = con.cursor() cur.execute("CREATE TABLE IF NOT EXISTS addresses(WavesAddress TEXT , serializedWallet TEXT , BTCaddress TEXT , Inventory REAL)") cur.execute("""INSERT INTO addresses VALUES(?,?,?,0)""",(WavesAddress,serializedWallet,BTCWallet['addresses'][0])) con.commit() # con.close() # print('BTCWallet' , BTCWallet) return { 'addresses' : BTCWallet['addresses'][0] , 'public_key' : ModuleHandler.encode( newWallet.get_public_key_hex() ) } # public key btc