def initAddress(self): addresses = get_wallet_addresses(wallet_name='testnet', api_key=blockcypher_key, is_hd_wallet=True) address = addresses['chains'][0]['chain_addresses'] if (len(address) == 0): self.balanceValue = QLabel('0.0000') address = deriveAddress() self.addressLabel.setText(address) else: amount = 0.0; for add in address: add_overview = get_address_overview(add["address"]) tx_time = add_overview['final_n_tx'] if tx_time == 0 : self.addressLabel.setText(add_overview['address']) img = qrcode.make(add_overview['address']) img.save('qr_img.png') pixmap = QPixmap('qr_img.png') self.addressQRCode.setPixmap(pixmap) break if self.addressLabel.text() == "": address = self.deriveAddress() print(address) self.addressLabel.setText(address) img = qrcode.make(address) img.save('qr_img.png') pixmap = QPixmap('qr_img.png') self.addressQRCode.setPixmap(pixmap)
def btc_process_trans_id(tx_id, cur, con, coin_tx_list, coin_from_exchange, coin_to_exchange, wallet_id_number): wallet_id_number = wallet_id_number + 1 getcontext().prec = 10 transaction = get_transaction_details(tx_id) #print (transaction) for address in transaction["outputs"]: #print (int(transaction["fees"])) #print (address["value"]) #print (Decimal(coinQty[tx_id]) * -1 - int(transaction["fees"])) if ((address["value"]) >= (Decimal(coin_tx_list[tx_id].qty) * -1 - int(transaction["fees"]))) and \ ((address["value"]) <= (Decimal(coin_tx_list[tx_id].qty) * -1)): date_time = str(transaction['received']).split('.')[0] #date_time = str(datetime(transaction['received'])).split('.')[0] if "spent_by" in address.keys(): child = address["spent_by"] else: child = "wallet" cur.execute("INSERT INTO wallets ( id, disposition, filename, coin, datetime, tx_id, tx_value, wallet, " + "wallet_value, child, fees) VALUES (?,?,?,?,?,?,?,?,?,?,?);", (str(wallet_id_number), str(coin_tx_list[tx_id].type), str(coin_tx_list[tx_id].fn), 'BTC', str(date_time), tx_id, str(Decimal(address["value"])/SATOSHI), str(address['addresses'][0]), str(Decimal(get_address_overview(address["addresses"][0])["final_balance"])/SATOSHI), str(child), str(Decimal(transaction["fees"])/SATOSHI))) con.commit() # date = datetime.date(time_trans) # print datetime.time(time_trans) #print ("date of transaction:", str(date_time)) #print ("found it at address:", str(address['addresses'][0])) #print ("Inital Value of address:", str(address["value"])) #print ("output transaction:", str(child)) #print ("address final Balance:", str(get_address_overview(address["addresses"][0]) # ["final_balance"])) # if tx_id == '8615b09eab97769d7e5da6aafac57655bcf1c868e5a75e09a91accabb38a6acd': btc_wallet_recurs(child, address['addresses'][0], address["value"], str(wallet_id_number) + '.1', cur, con, coin_tx_list, coin_from_exchange, coin_to_exchange)
def get_context_data(self, *args, **kwargs): context = super(SendBitcoinsCreateView, self).get_context_data(*args, **kwargs) context['wallet'] = Wallet.objects.get( profile=self.request.user.profile) wallet = context['wallet'] # try: address_info = get_address_overview(wallet.receiving_address, coin_symbol=settings.COIN) # Obtengo el balance de la respuesta de Blockcypher luego de comision de wallet.balance = get_bitcoins(float(address_info['balance'])) wallet.save() # Muestra la clave privad desencriptada # context['priv'] = get_desencrypted_priv(wallet.private) # except: # messages.success(self.request, _(f'Could not get the balance')) return context
def check_exist_keys(): badcount = 0 # Read from file containing generated keys keysfile_name = 'random_keys.txt' filehandler = open(keysfile_name, 'r') for line in filehandler: fields = line.split('|') pubaddr = fields[0] try: print(pubaddr) overview = get_address_overview(pubaddr) if overview['balance'] > 0: print('___________________________________') print('ADDRESS EXISTS!!!') print('BALANCE = ' + overview['balance']) print('___________________________________') else: print('nothing to see here... nada') except Exception as e: badcount += 1 print('Error encountered... exiting...') break print('Number of bad addresses = ' + str(badcount)) filehandler.close()
def run(self): if self.request_type == 'balance': self.response=get_address_overview(self.address, coin_symbol=self.ticker) elif self.request_type == 'endpoint': self.response = get_address_details(self.address, coin_symbol=self.ticker) elif self.request_type == 'full_endpoint': self.response = get_address_full(self.address, coin_symbol=self.ticker)
def get_balance(address, coin_symbol): """ Takes the wallet address, and return : 1) remaining balance of the address """ msg = get_address_overview(address, coin_symbol) return msg['balance']
def query_address_assets(address): ''' :param address: input address :return: assets below this address ''' res = get_address_overview(address,'btc-testnet') print res return res
def _get_litecoin_balance(self): """ Returns litecoin balance of the class' litecoin address Yields: litecoin_balance: Litecoin balance """ photon_balance = blockcypher.get_address_overview(self.litecoin_address, coin_symbol='ltc').get('balance') litecoin_balance = float(photon_balance) / PHOTONS_TO_LITECOIN_MULTIPLIER return litecoin_balance
def get_balance(addr): #url = "https://api.blockcypher.com/v1/btc/test3/addrs/" + addr + "/balance" #request = requests.get(url) #content = request.json() #print(content) #amount = content['balance'] amount = get_address_overview(addr, coin_symbol="btc-testnet")['balance'] return amount
def setWalletBalance(self): print("name: ", self.wallet_name) self.addresses = get_wallet_addresses(wallet_name=self.wallet_name, api_key=blockcypher_key, is_hd_wallet=True) address = self.addresses['chains'][0]['chain_addresses'] if (len(address) == 0): self.balanceValue.setText('0.0000') else: amount = 0.0 for add in address: add_overview = get_address_overview(add["address"]) print("overview: ", add_overview) balanceValue1 = add_overview["final_balance"] amount = amount + (float)(balanceValue1) self.balanceValue.setText(str(amount / 100000000))
def form_valid(self, form): temp = form.cleaned_data['amount'] amount = get_satoshis(temp) to_wallet = form.cleaned_data['to_wallet'] description = form.cleaned_data['description'] context = self.get_context_data() wallet = context['wallet'] priv = get_desencrypted_priv(wallet.private) # get_desencrypted_priv(wallet.private) # try: tx = simple_spend(from_privkey=priv, to_address=to_wallet, to_satoshis=int(amount), coin_symbol=settings.COIN, api_key=settings.BLOCKCYPHER_TOKEN) if tx: instance = form.save(commit=False) address_info = get_address_overview(wallet.receiving_address, coin_symbol=settings.COIN) instance.wallet = wallet instance.amount = get_bitcoins(amount) instance.to_wallet = to_wallet instance.description = description instance.tx_ref = tx instance.save() wallet.balance = get_bitcoins(float(address_info['balance'])) wallet.save() messages.success(self.request, _(f'Congrats')) # except Exception as e: # if e == 'Build Unsigned TX Error': # messages.error(self.request, _("Transaccion invalida.")) # messages.error(self.request, _("Algo extraño ha sucedido. Por favor chequea los datos")) return HttpResponseRedirect(reverse('wallets:send'))
def form_valid(self, form): temp = form.cleaned_data['amount'] amount = get_satoshis(temp) to_wallet = form.cleaned_data['to_wallet'] description = form.cleaned_data['description'] context = self.get_context_data() wallet = context['wallet'] priv = get_desencrypted_priv(wallet.private) # get_desencrypted_priv(wallet.private) try: tx = simple_spend(from_privkey=priv, to_address=to_wallet, to_satoshis=int(amount), coin_symbol=settings.COIN, api_key=settings.BLOCKCYPHER_TOKEN) if tx: instance = form.save(commit=False) address_info = get_address_overview(wallet.receiving_address, coin_symbol=settings.COIN) print(tx) instance.wallet = wallet instance.amount = get_bitcoins(amount) instance.to_wallet = to_wallet instance.description = description # instance.tx_ref = tx['tx_ref'] instance.save() wallet.balance = get_bitcoins(float(address_info['balance'])) wallet.save() messages.success(self.request, _(f'Congrats')) except Exception as e: messages.error(self.request, e) return HttpResponseRedirect(reverse('wallets:send'))
def check_priv_key(priv_key): try: address = privkey_to_address(priv_key) print("try priv key {}".format(priv_key)) print("generated public key {}".format(address)) addr_overview = get_address_overview(address) #getting address data for key, value in addr_overview.items( ): #getting info from address overview #check past transactions if key == 'final_n_tx': #check for any transactions in the past if value > 0: #if exist, then address has been used print("Address has been used {0} times in the past".format( value)) print(priv_key) print(address) #check balance if key == 'final_balance': #check for funds in the address if value > 0: #if any btc left on address, print details print("Address has balance of {0}".format( from_satoshis(value, 'btc'))) except: #this happens if string doesn't generate valid key return None
def verify_payment(client_id, assigned_wallet_address, payee_wallet_address): """Verify if the payment in bitcoins has been made and confirmed Args: client_id (str): A unique ID in UUID4 format assigned_wallet_address (str): The wallet address generated for the client payee_wallet_address (str):The wallet address used by the victim to make the payment Returns: boolean: Returns True if the payment has been made """ if not assigned_wallet_address == get_bitcoin_wallet_id_database( client_id): logger.error( "Given wallet address does not match with assigned wallet address") return None address_details = blockcypher.get_address_overview(assigned_wallet_address) if address_details.get("balance") > 5328: insert_payment_details_into_database(client_id, payee_wallet_address) return True return True # For testing
def balance(self): overview = blockcypher.get_address_overview( self.address, coin_symbol=self.coin_symbol) return overview['balance']
PrivateVar3 = privtopub(random_key()) PrivateVar4 = privtopub(random_key()) PrivateVar5 = privtopub(random_key()) MultiSigAddressMaker = mk_multisig_script(PrivateVar2, PrivateVar1, PrivateVar3, PrivateVar4, PrivateVar5, 5, 5) MultiSigAddress = scriptaddr(MultiSigAddressMaker) print(MultiSigAddress) SigAddress = str(MultiSigAddress) #Checking Bitcoin Balance if answer == "5": CheckBalance = input("Enter Your Bitcoin Address: ") print("Your Balance Details \n") print(get_address_overview(CheckBalance)) #Hashing Address if answer == "6": print("Enter Your Bitcoin Address") WalletAddress = input() Hashed = txhash(WalletAddress) print(Hashed) # Sending Bitcoins if answer == "7": client = Client('Your API KEY', 'Your Secret Key') tx = client.send_money('2bbf394c-193b-5b2a-9155-3b4732659ede', to='1AUJ8z5RuHRTqD1eikyfUUetzGmdWLGkpT',
def search_blockchain(search): try: # Try addresss category = 'address' search_id = search data = blockcypher.get_address_overview( search, coin_symbol="btc-testnet", api_key="acb0b8a2fe3d479c8b05b415ded8021e") except (AssertionError, TypeError): try: # Try block height category = 'block' block_height = blockcypher.get_block_height( search, coin_symbol='btc-testnet', api_key="acb0b8a2fe3d479c8b05b415ded8021e") search_id = block_height data = blockcypher.get_block_overview( block_height, coin_symbol="btc-testnet", api_key="acb0b8a2fe3d479c8b05b415ded8021e") except (AssertionError, TypeError): try: # Try block hash category = 'block' search_id = search data = blockcypher.get_block_overview( search, coin_symbol="btc-testnet", api_key="acb0b8a2fe3d479c8b05b415ded8021e") except (AssertionError, TypeError): try: # Try tx category = 'tx' search_id = search data = blockcypher.get_transaction_details( search, coin_symbol="btc-testnet", api_key="acb0b8a2fe3d479c8b05b415ded8021e") except (AssertionError, TypeError): category = None search_id = search data = None print(category) print(search_id) print(data) """ try: # address ??? data = get_from_bitcoind('getblock', [search]) data['message'] try: height_to_hash = get_from_bitcoind('getblockhash', [search]) data = get_from_bitcoind('getblock', [height_to_hash]) data['message'] try: data = get_from_bitcoind('getrawtransaction', [search, 1]) data['message'] category = None search_id = None except KeyError: category = 'tx' search_id = search except KeyError: category = 'block' search_id = search except KeyError: category = 'block' search_id = data['height'] # print('category: ', category) # print('search_id: ', search_id) # print('data: ', data) """ return category, search_id, data
def balanceOf(self, address): return get_address_overview(address, coin_symbol='btc-testnet')['balance']
def getbalance(self): data = get_address_overview(self.address["address"], coin_symbol='bcy') return data
def main(): window, settings = None, load_settings(SETTINGS_FILE, DEFAULT_SETTINGS) while True: if window is None: window = create_main_window(settings) event, values = window.Read() f = values['gen'].rstrip() if event in (None, 'Exit'): break elif event == 'Generate wallet': salt = sal() secret_exponent = seed(f, salt) public_key = pub_key(secret_exponent) address = addr(public_key) WIF = wif(secret_exponent) balance = bala(address) overv = over(address) data = open("myCoin-Wallet.docx", "a") data.write( "myCoin-Wallet: " + "\n\n" + "Seed phrase + salt: " + str(f) + ' ' + str(salt) + "\n\n" + "Privatekey: " + str(secret_exponent) + "\n\n" + "Publickey: " + str(public_key) + "\n\n" + "WIF: " + str(WIF) + "\n\n" + "Address: " + str(address) + "\n\n" + "Balance: " + str(balance) + ' ' + 'btc' + "\n\n" + "Transactions: " + str(overv) + "\n" + '-------------------------------------------------------------------------------------------------------------' + "\n\n") data.close() print("Seed phrase + salt: " + str(f) + ' ' + str(salt) + "\n" + "Privatekey: " + str(secret_exponent) + "\n" + "WIF: " + str(WIF) + "\n" + "Address: " + str(address) + "\n" + "Balance: " + str(balance) + ' ' + 'btc' + "\n" + "Transactions: " + str(overv) + "\n") elif event == 'Overview address': d = blockcypher.get_address_overview(f) print(d) elif event == 'Copy': pyperclip.copy(str(f)) pyperclip.paste() elif event == 'Paste': text = pyperclip.paste() window.Element('gen').Update(str(text)) elif event == 'Settings': event, values = create_settings_window(settings).read(close=True) if event == 'Save': window.close() window = None save_settings(SETTINGS_FILE, settings, values) elif event == 'About...': sg.popup( 'About:', 'Created by A. Petek', 'myCoin bitcoin brainwallet', 'Version 1.1', ) elif event == 'paypal': webbrowser.open_new_tab( "https://www.paypal.com/donate/?cmd=_s-xclick&hosted_button_id=PFB6A6HLAQHC2&source=url" ) elif event == 'bitcoin': webbrowser.open_new_tab( "https://commerce.coinbase.com/checkout/149a6235-ec7e-4d3b-a1ae-b08c4f08b4f6" ) window.Close()
def btc_wallet_recurs(tx_id, wallet, value, id_number, cur, con, coin_tx_list, coin_from_exchange, coin_to_exchange): child_tx_id = [] child_wallet = [] child_value = [] fees = "0" tx_id_total = value wallet_trans = wallet date_time = "" disposition = '' if tx_id != "wallet": #print ("tx_id:", str(tx_id)) #print ("wallet:", str(wallet)) #print ("value:", str(value)) transaction = get_transaction_details(tx_id) tx_id_total = value date_time = str(transaction['received']).split('.')[0] fees = transaction["fees"] wallet_trans = transaction['inputs'][0]["addresses"][0] #print (len(transaction['inputs'])) #print (transaction['inputs'][0]["addresses"][0]) #print (len(transaction['outputs'])) if len(transaction['inputs']) > 2: # note the tx_id as a possible exchange child_tx_id.append("exchange") elif len(transaction["outputs"]) > 2: # note the tx_id as a possible exchange child_tx_id.append("exchange") # elif tx_id in coinToExchange : # child_tx_id.append("exchange") else: # add tx_id to the wallet table for address in transaction["outputs"]: if "spent_by" in address.keys(): # Check to see if TXid and value Matches on in the Exchanges if (tx_id in coin_to_exchange) and (int(coin_tx_list[tx_id].qty) == address["value"]): #print (coinType[tx_id]) child_tx_id.append("exchange_"+ str(coin_tx_list[tx_id].type)) disposition = coin_tx_list[tx_id].type child_wallet.append("") child_value.append("") cur.execute("UPDATE crypto SET fee = '%s' WHERE tx_id = '%s' ;" % (str(-1*Decimal(fees)/SATOSHI), tx_id)) con.commit() cur.execute("UPDATE crypto SET %s = '%s' WHERE tx_id = '%s' ;" % ('BTC_'+transaction['inputs'][0]['addresses'][0][0:5],str(-1*(Decimal(fees) + Decimal(address['value']))/SATOSHI), tx_id)) con.commit() else: child_tx_id.append(address["spent_by"]) child_wallet.append(address['addresses'][0]) child_value.append(address["value"]) elif "value" in address.keys(): child_tx_id.append("wallet") child_wallet.append(address['addresses'][0]) child_value.append(value) if len(child_tx_id) == 1: child_tx_id_str = child_tx_id[0] else: child_tx_id_str = ",".join(child_tx_id) #print (tx_id) #print (Decimal(fees)) #print (Decimal(fees)) cur.execute("INSERT INTO wallets (id, disposition, coin, datetime, tx_id, tx_value, wallet, wallet_value, " + " child, fees) VALUES (?,?,?,?,?,?,?,?,?,?);", (str(id_number), str(disposition), 'BTC', str(date_time), tx_id, str(Decimal(tx_id_total)/SATOSHI), str(wallet_trans), str(get_address_overview(wallet_trans)["final_balance"]), str(child_tx_id_str), str(Decimal(fees)/SATOSHI))) con.commit() if len(child_tx_id) > 0: #print (len(child_tx_id)) for i in range(len(child_tx_id)): if "exchange" not in child_tx_id[i]: btc_wallet_recurs(child_tx_id[i], child_wallet[i], child_value[i], str(id_number)+'.'+str(i), cur, con)
def __address_overview(self): try: results = get_address_overview(self.address) return results except BaseException as e: config.debug(e)
def BTC(expected, address): try: return float(get_address_overview(address) ['total_received']) * .00000001 >= float(expected) except: return False
wallet_Name = input("Enter Wallet Name (sample: alice): ") else: print() if choice == 1: result = get_blockchain_overview() print("Block Height: ", result['height']) elif choice == 2: result = get_block_overview(haash) print("Block Height: ", result['height']) print("Number of Transactions: ", len(result['txids'])) elif choice == 3: result = get_block_overview(block_height, txn_limit=1, txn_offset=1) print("Number of Transactions: ", len(result['txids'])) elif choice == 4: result = get_address_overview(address) print("Received: ", result['total_received'], " sat") print("Sent: ", result['total_sent'], " sat") print("Balance: ", result['balance'], " sat") elif choice == 5: result = get_address_details(address) print("Received: ", result['total_received'], " sat") print("Sent: ", result['total_sent'], " sat") print("Balance: ", result['balance'], " sat") print("Number of Transactions: ", result['n_tx']) elif choice == 6: result = get_address_full(address=address) print("Received: ", result['total_received'], " sat") print("Sent: ", result['total_sent'], " sat") print("Balance: ", result['balance'], " sat") print("Number of Transactions: ", result['n_tx'])
def get_balance(address): # Only works for mainnet addresses info = get_address_overview(address, 'dash') print('Balance: {}'.format(info['final_balance'])) return info['final_balance']
def getbalance(address): data = get_address_overview(address, coin_symbol='bcy') return data
def get_bit_balance(address, user): bal = get_address_overview(address) return bal['balance']
#import only neccessary functions from bitcoin import random_key,privkey_to_address from blockcypher import get_latest_block_height, get_total_balance, get_address_overview, from_satoshis #int("0x1", 16) #first private key #int("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364140", 16) #last private key for i in range(35): #print(hex(i)) #show iterator in hex to reflect priv key format priv_key = i #generate priv_key from int anyway address = privkey_to_address(priv_key) addr_overview = get_address_overview(address) #getting address data #[print(key, value) for key, value in addr_overview.items()] #this would show dict with address info for key,value in addr_overview.items(): #getting info from address overview if key == 'final_balance': #check for funds in the address if value > 0: #if any btc left on address, print details print(priv_key) print(address) print(from_satoshis(value,'btc'))
def address_sent(pub_key, ticker): key = str(pub_key) overview = blockcypher.get_address_overview(key, ticker) received = overview['total_sent'] rec = blockcypher.from_satoshis(received, 'btc') return rec
def get_account_balance(): #api_key = request.headers.get('api_key') api_key = request.headers.get('api_key') coin_symbol = request.headers.get('coin_symbol') ''' coin_symbol = request.headers.get('coin_symbol') address = request.headers.get('address') if coin_symbol == 'xrp': url = 'https://data.ripple.com/v2/accounts/' + address + '/balance_changes' r = requests.get(url) response = r.json() else: url = 'https://api.blockcypher.com/v1/' + coin_symbol + '/main/addrs/' + address + '/balance' r = requests.get(url) response = r.json() ''' if coin_symbol == 'all': with open('./deposit_wallet/btc/wallet.json') as json_file: data = json.load(json_file) btc_wallet_address = data['address'] btc_wallet_balance = blockcypher.get_address_overview( btc_wallet_address) with open('./deposit_wallet/btc_testnet/wallet.json') as json_file: data = json.load(json_file) btc_testnet_wallet_address = data['address'] btc_testnet_wallet_balance = blockcypher.get_address_overview( btc_testnet_wallet_address, coin_symbol="btc-testnet") with open('./deposit_wallet/ltc/wallet.json') as json_file: data = json.load(json_file) ltc_wallet_address = data['address'] ltc_wallet_balance = blockcypher.get_address_overview( ltc_wallet_address, coin_symbol="ltc") with open('./atm0001_wallet/btc/wallet.json') as json_file: data = json.load(json_file) btc_atm0001_wallet_address = data['address'] btc_atm0001_wallet_balance = blockcypher.get_address_overview( btc_atm0001_wallet_address) with open('./atm0001_wallet/btc_testnet/wallet.json') as json_file: data = json.load(json_file) btc_atm0001_testnet_wallet_address = data['address'] btc_atm0001_testnet_wallet_balance = blockcypher.get_address_overview( btc_atm0001_testnet_wallet_address, coin_symbol="btc-testnet") with open('./atm0001_wallet/ltc/wallet.json') as json_file: data = json.load(json_file) ltc_atm0001_wallet_address = data['address'] ltc_atm0001_wallet_balance = blockcypher.get_address_overview( ltc_atm0001_wallet_address, coin_symbol="ltc") result = { "btc_balance": btc_wallet_balance, "ltc_balance": ltc_wallet_balance, "btc-tesnet_balance": btc_testnet_wallet_balance, "atm0001_wallet": { "btc_balance": btc_atm0001_wallet_balance, "ltc_balance": ltc_atm0001_wallet_balance, "btc-testnet_balance": btc_atm0001_testnet_wallet_balance } } if coin_symbol == 'btc': with open('./deposit_wallet/btc/wallet.json') as json_file: data = json.load(json_file) btc_wallet_address = data['address'] btc_wallet_balance = blockcypher.get_address_overview( btc_wallet_address) result = {"btc": btc_wallet_balance} if coin_symbol == 'ltc': with open('./deposit_wallet/ltc/wallet.json') as json_file: data = json.load(json_file) ltc_wallet_address = data['address'] ltc_wallet_balance = blockcypher.get_address_overview( ltc_wallet_address, coin_symbol="ltc") result = {"ltc": ltc_wallet_balance} if coin_symbol == 'btc-testnet': with open('./deposit_wallet/btc_testnet/wallet.json') as json_file: data = json.load(json_file) btc_testnet_wallet_address = data['address'] btc_testnet_wallet_balance = blockcypher.get_address_overview( btc_testnet_wallet_address, coin_symbol="btc-testnet") result = {"btc-testnet": btc_testnet_wallet_balance} if api_key == requested_api_key: return result else: return unauthorized()