Esempio n. 1
0
    def VerifyWallet(self, WavesAddress):

        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(
                """SELECT WavesAddress , serializedWallet , BTCaddress 
							FROM addresses WHERE WavesAddress=:adr""", {"adr": WavesAddress})
            con.commit()

            row = cur.fetchone()
            if row:
                _wallet = get_wallet_addresses(wallet_name=WavesAddress,
                                               api_key=self.APIKEY)
                details = get_address_details(_wallet['addresses'][0])
                # print(details)
                txrefs = details['txrefs']
                # print(len(txrefs))
                if len(txrefs) == 0:
                    return {"result": "not exist any transaction"}
                else:
                    tx_hash = txrefs[0][
                        'tx_hash']  #TODO should be check transaction time
                    transaction_details = get_transaction_details(tx_hash)
                    receive_count = transaction_details['receive_count']
                    # print(tx_hash)
                    recipient = pywaves.Address(address=WavesAddress)
                    BTC = pywaves.Asset(
                        '8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS')
                    res = self.WAVES.sendAsset(recipient, BTC, receive_count)

                return res

        return None
Esempio n. 2
0
 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)
Esempio n. 3
0
	def VerifyWallet(self,WavesAddress):

		# 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("""SELECT WavesAddress , serializedWallet , BTCaddress 
		# 					FROM addresses WHERE WavesAddress=:adr""",  {"adr": WavesAddress})
		# 	con.commit()
		con = lite.connect('test.db')
		with con:
			cur = con.cursor()
			cur.execute("""SELECT id FROM addressid WHERE WavesAddress=:adr""",  {"adr": WavesAddress})
			con.commit()

			row = cur.fetchone()
			if row :
				print('row[0] : ',row[0])
				_wallet = get_wallet_addresses(wallet_name='Noay'+ str(row[0]), api_key=self.APIKEY , coin_symbol=self.coin_symbol)
				print('_wallet',_wallet)
				txrefs = []
				details = get_address_details(_wallet['addresses'][0], coin_symbol=self.coin_symbol)
				print(details)
				txrefs = details['txrefs']
				print(len(txrefs))


				if len(txrefs) == 0 :
					return {"result" : "not exist any transaction"} 
				else :
					tx_hash = txrefs[0]['tx_hash']													#TODO should be check transaction time
					transaction_details = get_transaction_details(tx_hash , coin_symbol=self.coin_symbol)
					print('transaction_details' , transaction_details)
					receive_count = transaction_details['outputs'][-1]['value'] * (10** ((-1) * 8))

					# print(tx_hash)
					pywaves.setNode(node = self.TESTNET_NODE , chain = self.CHAIN)
					print("getNode(): ",pywaves.getNode())

					recipient = pywaves.Address(address=WavesAddress)
					BTC = pywaves.Asset('DWgwcZTMhSvnyYCoWLRUXXSH1RSkzThXLJhww9gwkqdn')				#todo i dnk?
					WAVES = pywaves.Address(address=self.WAVES_address , privateKey=self.WAVES_privateKey)
					res = WAVES.sendAsset(recipient,BTC,receive_count)								#todo what response
																									#todo dont read serialized? ://

					con = lite.connect('test.db')
					with con:
						cur = con.cursor()
						# cur.execute("CREATE TABLE IF NOT EXISTS btcRemind(BTCaddress TEXT , Inventory REAL ")
						# cur.execute("""INSERT INTO btcRemind VALUES(?,?)""",  (BTCWallet['addresses'][0], receive_count))
						cur.execute(""" UPDATE addresses SET Inventory = ? WHERE WavesAddress = ? """,  ( receive_count , WavesAddress ))
						con.commit()
				
				return res 


		return None
Esempio n. 4
0
    def CheckTransaction(self, WavesAddress):
        serializeWlt = None
        #TODO read serializeWlt from DB
        _wallet = get_wallet_addresses(wallet_name=WavesAddress,
                                       api_key=APIKEY)

        details = get_address_details(_wallet['addresses'][0])
        tx_hash = details['txrefs'][0]['tx_hash']
        transaction_details = get_transaction_details(tx_hash)

        # pyneel.reissueasset(verifywallet())

        return {None}
Esempio n. 5
0
def get_addresses_on_both_chains(wallet_obj, used=None, zero_balance=None):
    '''
    Get addresses across both subchains based on the filter criteria passed in

    Returns a list of dicts of the following form:
        [
            {'address': '1abc123...', 'path': 'm/0/9', 'pubkeyhex': '0123456...'},
            ...,
        ]

    Dicts may also contain WIF and privkeyhex if wallet_obj has private key
    '''
    mpub = wallet_obj.serialize_b58(private=False)

    wallet_name = get_blockcypher_walletname_from_mpub(
            mpub=mpub,
            subchain_indices=[0, 1],
            )

    wallet_addresses = get_wallet_addresses(
            wallet_name=wallet_name,
            api_key=BLOCKCYPHER_API_KEY,
            is_hd_wallet=True,
            used=used,
            zero_balance=zero_balance,
            coin_symbol=coin_symbol_from_mkey(mpub),
            )
    verbose_print('wallet_addresses:')
    verbose_print(wallet_addresses)

    if wallet_obj.private_key:
        master_key = wallet_obj.serialize_b58(private=True)
    else:
        master_key = mpub

    chains_address_paths_cleaned = []
    for chain in wallet_addresses['chains']:
        if chain['chain_addresses']:
            chain_address_paths = verify_and_fill_address_paths_from_bip32key(
                    address_paths=chain['chain_addresses'],
                    master_key=master_key,
                    network=guess_network_from_mkey(mpub),
                    )
            chain_address_paths_cleaned = {
                    'index': chain['index'],
                    'chain_addresses': chain_address_paths,
                    }
            chains_address_paths_cleaned.append(chain_address_paths_cleaned)

    return chains_address_paths_cleaned
Esempio n. 6
0
    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))
Esempio n. 7
0
def wallet_overview(request, coin_symbol, pubkey):

    subchain_indices = request.GET.get('subchain-indices')
    if subchain_indices:
        subchain_indices = subchain_indices.split('-')
        if subchain_indices == ['']:
            subchain_indices = []
        else:
            subchain_indices = [int(x) for x in subchain_indices]

    # TODO: confirm it's a pubkey and not a privkey

    TXNS_PER_PAGE = 100

    # 1 indexed page
    current_page = request.GET.get('page')
    if current_page:
        current_page = int(current_page)
    else:
        current_page = 1

    # transaction pagination: 0-indexed and inclusive
    tx_start_num = (current_page - 1) * TXNS_PER_PAGE
    tx_end_num = current_page * TXNS_PER_PAGE - 1

    wallet_name = get_blockcypher_walletname_from_mpub(mpub=pubkey,
            subchain_indices=subchain_indices)

    # TODO: could store in DB whether created or not
    create_hd_wallet(
            wallet_name=wallet_name,
            xpubkey=pubkey,
            api_key=BLOCKCYPHER_API_KEY,
            subchain_indices=subchain_indices,
            coin_symbol=coin_symbol,
            )

    wallet_details = get_wallet_transactions(
            wallet_name=wallet_name,
            api_key=BLOCKCYPHER_API_KEY,
            coin_symbol=coin_symbol,
            txn_limit=TXNS_PER_PAGE,
            )
    # import pprint; pprint.pprint(wallet_details, width=1)

    assert 'error' not in wallet_details, wallet_details

    wallet_addresses = get_wallet_addresses(
            wallet_name=wallet_name,
            api_key=BLOCKCYPHER_API_KEY,
            is_hd_wallet=True,
            zero_balance=None,
            used=None,
            coin_symbol=coin_symbol,
            )
    # import pprint; pprint.pprint(wallet_addresses, width=1)

    assert 'error' not in wallet_addresses, wallet_addresses

    all_transactions = wallet_details.get('unconfirmed_txrefs', []) + wallet_details.get('txrefs', [])

    # filter address details for pagination. HACK!
    all_transactions = all_transactions[tx_start_num:tx_end_num]

    flattened_txs = flatten_txns_by_hash(all_transactions, nesting=False)

    return {
            'is_wallet_page': True,  # shared template
            'coin_symbol': coin_symbol,
            'pubkey': pubkey,
            'subchain_indices': subchain_indices,
            'current_page': current_page,
            'max_pages': get_max_pages(num_items=wallet_details['final_n_tx'], items_per_page=TXNS_PER_PAGE),
            'total_sent_satoshis': wallet_details['total_sent'],
            'total_received_satoshis': wallet_details['total_received'],
            'unconfirmed_balance_satoshis': wallet_details['unconfirmed_balance'],
            'confirmed_balance_satoshis': wallet_details['balance'],
            'total_balance_satoshis': wallet_details['final_balance'],
            'flattened_txs': flattened_txs,
            'num_confirmed_txns': wallet_details['n_tx'],
            'num_unconfirmed_txns': wallet_details['unconfirmed_n_tx'],
            'num_all_txns': wallet_details['final_n_tx'],
            'wallet_addresses': wallet_addresses,
            'bc_wallet_name': wallet_name,
            }
Esempio n. 8
0
from blockcypher import get_wallet_addresses

get_wallet_addresses(wallet_name='alice', api_key='YOUR_TOKEN', is_hd_wallet=True)
Esempio n. 9
0
 def get_wallet(self, wallet):
     self.wallet = blockcypher.get_wallet_addresses(wallet_name=wallet.name,
                                                    api_key=self.api,
                                                    is_hd_wallet=True)
    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'])
elif choice == 7:
    result = get_wallet_addresses(wallet_name=wallet_Name, api_key=apikey)
    print("Number of addresses associated: ", len(result['addresses']))
elif choice == 8:
    result = get_wallet_addresses(wallet_name=wallet_Name,
                                  api_key=apikey,
                                  is_hd_wallet=True)
    print("Number of addresses associated: ", len(result['addresses']))
elif choice == 9:
    result = get_transaction_details(haash)
    print("Block Height: ", result['block_height'])
    print("Total :", result['total'], " sat")
elif choice == 10:
    result = get_broadcast_transactions(limit=1)
    print("Number of Unconfirmed Transactions: ", len(result))
    print("Transaction Hash: ", result[0]['hash'])
elif choice == 11:
Esempio n. 11
0
	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
Esempio n. 12
0
def wallet_overview(request, coin_symbol, pubkey):

    subchain_indices = request.GET.get('subchain-indices')
    if subchain_indices:
        subchain_indices = subchain_indices.split('-')
        if subchain_indices == ['']:
            subchain_indices = []
        else:
            subchain_indices = [int(x) for x in subchain_indices]

    # TODO: confirm it's a pubkey and not a privkey

    TXNS_PER_PAGE = 100

    # 1 indexed page
    current_page = request.GET.get('page')
    if current_page:
        current_page = int(current_page)
    else:
        current_page = 1

    # transaction pagination: 0-indexed and inclusive
    tx_start_num = (current_page - 1) * TXNS_PER_PAGE
    tx_end_num = current_page * TXNS_PER_PAGE - 1

    wallet_name = get_blockcypher_walletname_from_mpub(
        mpub=pubkey, subchain_indices=subchain_indices)

    # TODO: could store in DB whether created or not
    create_hd_wallet(
        wallet_name=wallet_name,
        xpubkey=pubkey,
        api_key=BLOCKCYPHER_API_KEY,
        subchain_indices=subchain_indices,
        coin_symbol=coin_symbol,
    )

    wallet_details = get_wallet_transactions(
        wallet_name=wallet_name,
        api_key=BLOCKCYPHER_API_KEY,
        coin_symbol=coin_symbol,
        txn_limit=TXNS_PER_PAGE,
    )
    # import pprint; pprint.pprint(wallet_details, width=1)

    assert 'error' not in wallet_details, wallet_details

    wallet_addresses = get_wallet_addresses(
        wallet_name=wallet_name,
        api_key=BLOCKCYPHER_API_KEY,
        is_hd_wallet=True,
        zero_balance=None,
        used=None,
        coin_symbol=coin_symbol,
    )
    # import pprint; pprint.pprint(wallet_addresses, width=1)

    assert 'error' not in wallet_addresses, wallet_addresses

    all_transactions = wallet_details.get(
        'unconfirmed_txrefs', []) + wallet_details.get('txrefs', [])

    # filter address details for pagination. HACK!
    all_transactions = all_transactions[tx_start_num:tx_end_num]

    flattened_txs = flatten_txns_by_hash(all_transactions, nesting=False)

    return {
        'is_wallet_page':
        True,  # shared template
        'coin_symbol':
        coin_symbol,
        'pubkey':
        pubkey,
        'subchain_indices':
        subchain_indices,
        'current_page':
        current_page,
        'max_pages':
        get_max_pages(num_items=wallet_details['final_n_tx'],
                      items_per_page=TXNS_PER_PAGE),
        'total_sent_satoshis':
        wallet_details['total_sent'],
        'total_received_satoshis':
        wallet_details['total_received'],
        'unconfirmed_balance_satoshis':
        wallet_details['unconfirmed_balance'],
        'confirmed_balance_satoshis':
        wallet_details['balance'],
        'total_balance_satoshis':
        wallet_details['final_balance'],
        'flattened_txs':
        flattened_txs,
        'num_confirmed_txns':
        wallet_details['n_tx'],
        'num_unconfirmed_txns':
        wallet_details['unconfirmed_n_tx'],
        'num_all_txns':
        wallet_details['final_n_tx'],
        'wallet_addresses':
        wallet_addresses,
        'bc_wallet_name':
        wallet_name,
    }