def fetch_history(self, wallet_key, doc_name): p_key = Key(wallet_key, network=self.network) txs = p_key.get_transactions() return sorted(filter(lambda m: m['name'] == doc_name, self._extract_metadata(txs)), key=lambda m: m['timestamp'], reverse=True)
def find_matching_versions(self, wallet_key, doc_hash): p_key = Key(wallet_key, network=self.network) txs = p_key.get_transactions() metadata_list = self._extract_metadata(txs) return sorted(filter(lambda m: m['hash'] == doc_hash, metadata_list), key=lambda m: m['timestamp'], reverse=True)
def fetch_documents(self, wallet_key): p_key = Key(wallet_key, network=self.network) txs = p_key.get_transactions() metadata_list = self._extract_metadata(txs) # TODO: this is inefficient but probably sufficient for the time being docs_data = {} for metadata in metadata_list: name = metadata['name'] if not docs_data.get(name, None): docs_data[name] = { 'versions': 1, 'last_modified': metadata['timestamp'] } else: version = docs_data[name]['versions'] + 1 last_modified = max(docs_data[name]['last_modified'], metadata['timestamp']) docs_data[name] = { 'versions': version, 'last_modified': last_modified } results = [] # TODO: there must be a better way to do this, but I'm a python n00b for entry in docs_data.items(): results.append({'name': entry[0], 'data': entry[1]}) return results
def save(self, wallet_key, doc_hash, doc_name, doc_size): p_key = Key(wallet_key, network=self.network) try: p_key.send_op_return(list_of_pushdata=[(doc_hash + ':' + doc_name + ':' + str(doc_size), 'utf-8')]) return {'hash': doc_hash} except ValueError as err: print(err) if str(err) == 'Transactions must have at least one unspent.': raise InsufficientBalanceError else: raise err
def show_QR(): file4 = open('privkey.txt', 'r+') a = file4.read() key = Key(a) addy = key.address print(addy) # Create qr code instance qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_H, box_size=10, border=4, ) data = addy # Add data qr.add_data(data) qr.make(fit=True) img = qr.make_image() img.save("image.jpg") try: img = Image.open("image.jpg") img.show() except IOError: pass
def create_user(): file = open('user.txt', 'w') file.write(username.get()) file.close() file2 = open('password.txt', 'w') file2.write(password.get()) key = Key() priv2 = key.to_wif() priv = priv2 file3 = open('privkey.txt', 'w') file3.write(priv) file.close() controller.show_frame(init)
def send_tx(): file = open('privkey.txt', 'r+') a = file.read() my_key = bitsv.Key(a) key = Key(a) addy = key.address print(addy) address = address_widget.get() ammount = ammount_widget.get() my_key.send([(address, ammount, 'usd')], leftover=addy) time.sleep(5) update_balance()
def check_balance(a): my_key=bitsv.Key(a) #priv key needed key=Key(a) addy=key.address print(addy)
DUST = 546 if remaining > DUST: outputs.append((leftover, remaining)) elif remaining < 0: raise InsufficientFunds( 'Balance {} is less than {} (including fee).'.format( total_in, total_out)) outputs.extendleft(messages) return unspents, list(outputs) # real msg = 'hi'.encode('utf-8') key = Key('') unspents, outputs = sanitize_tx_data(get_unspents(key.address), key.address, message=msg, compressed=key.is_compressed()) tx_hex = create_p2pkh_transaction(key, unspents, outputs) txid = send(tx_hex) print("https://blockchair.com/bitcoin-sv/transaction/{}".format(txid)) # regtest # msg = 'xyū'.encode('utf-8') # key = Key('cRVFvtZENLvnV4VAspNkZxjpKvt65KC5pKnKtK7Riaqv5p1ppbnh') # _unspents = [ Unspent(amount=5000000000, confirmations=120, txid="4bc41432979746dbd6c613dc5b2a2c1234ecc6a5bf3b48d108b4ecba90ea43fe", txindex=0) ] # unspents, outputs = sanitize_tx_data( # _unspents, # key.address,
def get_wallet_balance(): wallet_key = get_wallet_key_header() return Key(wallet_key, network='test').get_balance()