def sync_alladdress_balance(): # TODO: sync_alladdress_balance - use transation lock # TODO: sync_alladdress_balance - performance enhancement adrlist = models.BitcoinAddress.objects.all() for address in adrlist: address_text = address.address balance = bci.unspent(address_text) if len(balance) > 0: address.least_received_confirmed = balance[0]['value'] address.save()
def trade(sender_addr, value, target_addr, fee=0.0001, change_addr=None): unspent_outputs = unspent(sender_addr) satoshis_value = covert_satoshis(value) satoshis_fee = covert_satoshis(fee) inputs, change = select_outputs(unspent_outputs, satoshis_value, satoshis_fee) if inputs: if not change_addr: change_addr = sender_addr outputs = build_tx_params(target_addr, satoshis_value, change_addr, change) tx = mktx(inputs, outputs) print "构建的建议信息是:" print "由%s --->>> %s转账%sBTC, 手续费为%sBTC, 找零地址:%s" % ( sender_addr, target_addr, value, fee, change_addr) print "-----" * 30 print tx print "#####" * 30 print deserialize(tx) print "*****" * 30 else: print "余额不足"
'801314cd462b98c64dd4c3f4d6474cad11ea39d5', # the '9f3ecb56e8b3cf977b958b044b2b039f7ae6f036', # coffee 'cffe3e032a686cc3f2c9e417865afa8a52ed962b', # god '2d6351944aa38af6aa46d4a74cbb9016cf19ee7e', # wallet '000000c5d31b915f2a74c3f51259c09d21808d3e', '5d14a857fce8da8edfb8f7d1c4bbc316622b7227', # password1 'cd1d7e863f891c493e093ada840ef5a67ad2d6cc', # peter '3b4df4363caa9e3bd9da58020d3080be8230a4ae', ] if __name__ == '__main__': rich = '1Ki3WTEEqTLPNsN5cGTsMkL2sJ4m5mdCXT' hrich = bci.history(rich) print("RICH", rich, len(hrich), len(bci.unspent(rich))) # foundf = open( "found.txt", "a" ) #h160_list = 'found-hot.hex' h160_list = 'found-uniq.hex' #h160_list = 'found-big.hex' print('*** Reading: ', h160_list) lin = 1 # need to skip first line from chkblf with open(h160_list, 'r') as f: lines = f.read().splitlines() print('lines', len(lines)) for l in lines:
def test_pytool_unspent(self): # 3CVVtR2coaLqBbav3XcP8VdekR4CvdtYCg is kent's personal bitcoin address . you are welcome send you bicoin to this address !! balance = bci.unspent('3CVVtR2coaLqBbav3XcP8VdekR4CvdtYCg')[0]['value'] self.assertEqual(balance, 500000, 'use pybitcoion tool to get balance fail')
from bitcoin.main import random_key, privtoaddr, sum from bitcoin.bci import unspent import time def record(priv): print "find this lucky!" with open('priv.txt', 'a') as _file: _file.writelines(priv + "\n") while True: priv = random_key() addr = privtoaddr(priv) time.sleep(1) try: utxo = unspent(addr) if utxo: record(priv) except Exception as e: time.sleep(10)