def send_whole_wallet(fromprivkey, toaddr): transaction_fee = 20000 # .0002 BTC fromaddress = bitcoin.privtoaddr(fromprivkey) balance = sum(transaction['value'] for transaction in bitcoin.unspent(fromaddress)) assert balance >= transaction_fee tx = bitcoin.mktx(bitcoin.history(fromaddress), [{'value': balance - transaction_fee, 'address': toaddr}]) signed_tx = bitcoin.sign(tx, 0, fromprivkey) bitcoin.pushtx(signed_tx)
def _get_unspent(): try: unspent = bitcoin.unspent(addr) except Exception as exc: _LOG.debug('Error retrieving from Blockchain.info: %s', exc) callback(0) return total = sum(tx['value'] for tx in unspent) callback(total)
def send_whole_wallet(fromprivkey, toaddr): transaction_fee = 20000 # .0002 BTC fromaddress = bitcoin.privtoaddr(fromprivkey) balance = sum(transaction['value'] for transaction in bitcoin.unspent(fromaddress)) assert balance >= transaction_fee tx = bitcoin.mktx(bitcoin.history(fromaddress), [{ 'value': balance - transaction_fee, 'address': toaddr }]) signed_tx = bitcoin.sign(tx, 0, fromprivkey) bitcoin.pushtx(signed_tx)
def get_balance(): """ Get wallet balance Returns: balance (int): satoshis in wallet """ priv, pub, addr = read_wallet() inputs = bitcoin.unspent(addr) balance = 0 for input in inputs: balance += input['value'] return balance
def get_unspents(multisig_addr,crypto_type): try: if crypto_type.lower() == 'bitcoin': unspents = bitcoin.unspent(multisig_addr) elif crypto_type.lower() == 'litecoin': unspents = bitcoin.litecoin_unspent(multisig_addr) elif crypto_type.lower() == 'dogecoin': unspents = bitcoin.dogecoin_unspent(multisig_addr) else: return None return unspents except Exception as e: print(str(e)) return None
def post_book(isbn, price, quality, send=True): """ Post a book sale to the mempool. Args: isbn (str): 10 digit ISBN Returns: signed_tx (str): signed transaction of book sale. """ priv, pub, addr = read_wallet() script = encode_OP_RETURN(isbn, price, quality) inputs = bitcoin.unspent(addr) signed_tx = build_tx(inputs[0], priv, addr, script, send=send) return signed_tx
def cancel_posting(isbn, send=True): """ Cancel a book sale that is already in the mempool. Useful if you have already sold the book. Args: isbn (str): 10 digit ISBN Returns: signed_tx (str): signed transaction of cancelled sale """ priv, pub, addr = read_wallet() script = _build_cancelation(isbn) inputs = bitcoin.unspent(addr) signed_tx = build_tx(inputs, priv, addr, script, send) return signed_tx
def show_unspent(): text = PapirusText() wallet_file = open('.wallet', 'r') wallet_json_dump = wallet_file.read() wallet_file.close() wallet_json = json.loads(wallet_json_dump) addr = wallet_json['address'] money = unspent(addr) unspent_total = 0 for output in money: transaction = json.loads("output") unspent_total += int(transaction['value']) text.write("Wallet Credit\n\r" + str(unspent_total))
def send_message(recipient_addr, scripts, fee=0, send=False): """ Send encoded message Args: recipient_addr (str): address of user to send message too scripts (list): list of strings, each element is a single encoded message. Multiple encodings are needed if the message is longer than 40 char. fee (int): Satoshis to pay in miner fees. Not actually required. send (bool): If True, send transactions to mempool. Returns: signed_txs (list): list of strings where each element is a signed transaction encoding a message Also sends transaction to the mempool. Notes: This is currently sending the message to blockchain.info, but this is trivially changed if needed. """ priv, pub, addr = books.read_wallet() signed_txs = [] for script in scripts: outputs = [{'value': 546, 'address': recipient_addr}] inputs = bitcoin.unspent(addr) for _input in inputs: if _input > 1092: input_tx = _input break outputs.append({'value': 0, 'script': script}) fee = fee tx = bitcoin.mksend(input_tx, outputs, addr, fee) signed_tx = bitcoin.sign(tx, 0, priv) if send: bitcoin.pushtx(signed_tx) signed_txs.append(signed_tx) if send: _write_message(recipient_addr, signed_txs) return signed_txs
def balance(address): v=b.unspent(address) out=0 for i in v: out+=i["value"] return out
def check(address, price): unspent_transactions = bitcoin.unspent( address) # Returns a list of dicts with the keys 'output' and 'value' total_balance = sum(transaction['value'] for transaction in unspent_transactions) # in satoshi return total_balance >= price
def check(address, price): unspent_transactions = bitcoin.unspent(address) # Returns a list of dicts with the keys 'output' and 'value' total_balance = sum(transaction['value'] for transaction in unspent_transactions) # in satoshi return total_balance >= price
def balance(address): v = b.unspent(address) out = 0 for i in v: out += i["value"] return out