Bitcoin Forum
May 17, 2024, 12:20:19 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: One Page Python Example of how to DUMP all addresses with value on btc blockchai  (Read 70 times)
btc-room101 (OP)
Member
**
Offline Offline

Activity: 182
Merit: 30


View Profile WWW
November 13, 2022, 12:15:34 AM
 #1

Ok, here is one page of python to DUMP bitcoin addresses or anything for that matter you wish to dump to a file, by condition;

Note you must have a full bitcoin server running on your LAN
You must install the python library's, you should have a unix computer, you should have a 8 core cpu with 16gb or more ram, if your doing 8gb bloom filters to process the addresses, then you need +8gb of RAM, I use 32gb and 32 core amd cpus;

For hacking of bitcoin of course once you have the addresses and the made the 8gb bloom filter, then you can use a basic mining rig with gpus, but you still need +8gb of ram to hold the bloom-filter in memory.

This example gets the best block, which is the newest block, if you want to dump the entire blockchain, then you just change that number to '1', but in the real world you do this crap by batches, say 10k blocks at a time and then put the stuff in different files; If you were to run this code from '1' to best it could take a week to do the dump; So its best to dump in 8 hour shifts;

The point here is to keep it simple, and to be able to extract anything you want; For me I just want addresses, and once I have them, I can use other code to reformat the addresses into other BTC address formats;

This example I have a process that checks the 'bitcoin-cli getinfo' looks for a new block, then this routine is called which strips all high value addresses from the new block, and then add's them to the main 8gb bloom-filter, so that the bloom always has ALL the valuable addresses of BTC for all time;

But you do as you wish, explain to me what you want to DUMP, and I'll provide the code-glue here so you can see how to do this stuff; Again the point is to keep it simple and be able to maintain the code yourself;

Ignore all the pickle stuff, its useful for debugging or building very special dumps, say you want a dump of just your addresses, then pickle is a good way to go;

from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
import pickle

def addrlistVout( txid ):
#    rpc_connection = AuthServiceProxy("http://%s:%s@192.168.1.8:8332"%(rpc_user, rpc_password))
    addrlist = []
    raw = rpc_connection.getrawtransaction(txid)
    decode =rpc_connection.decoderawtransaction(raw)
    for vl in decode['vout']:
        if ( 'scriptPubKey' in vl ) and vl['value']>0 :
            sl = vl['scriptPubKey']
#            print(vl['scriptPubKey'])
            if ( 'addresses' in sl ) :
                for al in sl['addresses']:
                    addrlist.append(al)
#                    print ( al )
    return ( addrlist )

def findunique( nl, ol ):
    newlist=[]
    for i in nl:
        if ( i not in ol ):
            newlist.append(i)
    return( newlist )

def loadaddrlist():
    with open('addrlist.pkl','rb') as fp:
        addrlist=pickle.load(fp)
    fp.close()
    return(addrlist)

def saveaddrlist(addrlist):
    with open('addrlist.pkl','wb') as fp:
        pickle.dump(addrlist,fp)
    fp.close()

# remove duplicates if needed, as needed
def cleanaddrlist() :
    addrlist = loadaddrlist()
    newlist=[]
    for i in addrlist:
        for j in i :
            if len(j)>32:
                newlist.append(j)
    al = list(set(newlist))
    saveaddrlist(al)

def writeaddresslist(addrlist):
# address written as base58.txt becaues b58.perl generates hex.txt which is  fed to blf
    thefile = open('address.txt', 'w')
    for i in addrlist:
#                print( i )
                thefile.write("%s\n" % i )
    thefile.close()

if __name__ == '__main__':

    rpc_user = "hacker"
    rpc_password = "1234"
    rpc_connection = AuthServiceProxy("http://%s:%s@127.0.0.1:8332"%(rpc_user, rpc_password))

    best_block_hash = rpc_connection.getbestblockhash()
    blk = rpc_connection.getblock(best_block_hash)

# dump current block count height

    print( "getblockcount = %s" % rpc_connection.getblockcount() )

    txlist=[]
    alist=[]

    for txid in blk['tx']:
        txlist.append( txid )
        al=addrlistVout( txid )
        alist.append( al )

# make list & remove duplicates in list
    newlist=[]
    for i in alist:
        for j in i:
            newlist.append(j)

    addrl = list(set(newlist))

    print( "%d Transactions in block" % len(txlist) )
    print( "Unique Address %d in block" % len(addrl) )

    addrlist=loadaddrlist()

    uni = findunique( addrl, addrlist )

    print( "New Addresses Added to List %d" % len(uni) )
    addrlist.append(uni)

    saveaddrlist(addrlist)


# *** write the UNIQUE address list to text file

    thefile = open('base58.txt', 'w')

    for i in uni:
#                print( i )
        if ( len(i)==34 ) :           
            thefile.write("%s\n" % i )
    thefile.close()
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!