pprintScript(binScript) print '' print '*' * 80 print '\n\nScanning Blockchain for transactions...', addrStr1 = hex_to_binary("abda0c878dd7b4197daa9622d96704a606d2cd14") addrStr2 = hex_to_binary("11b366edfc0a8b66feebae5c2e25a7b6a5d1cf31") addrStr3 = hex_to_binary("f62242a747ec1cb02afd56aac978faf05b90462e") addrStr4 = hex_to_binary("baa72d8650baec634cdc439c1b84a982b2e596b2") addrStr5 = hex_to_binary("6300bf4c5c2a724c280b893807afb976ec78a92b") addrStr6 = hex_to_binary('0e0aec36fe2545fb31a41164fb6954adcd96b342') # The _1_ methods are to avoid quirks with SWIG related using overloaded methods # requiring arguments that were typemap'd (BinaryData, in this case) cppWallet = Cpp.BtcWallet() cppWallet.addAddress_1_(addrStr1) cppWallet.addAddress_1_(addrStr2) cppWallet.addAddress_1_(addrStr3) bdm.scanBlockchainForTx_FromScratch(cppWallet) print 'Done!' print 'Wallet addresses: ', cppWallet.getNumAddr() for i in range(cppWallet.getNumAddr()): addr = cppWallet.getAddrByIndex(i) print '\t', hash160_to_addrStr(addr.getAddrStr20()), print '\tBalance:', coin2str(addr.getBalance()) print 'Getting Ledger for addresses:' ledger1 = cppWallet.getTxLedger() for i, l in enumerate(ledger1):
def addAddress(self, addrData, pubKeyStr='', firstSeenData=[], lastSeenData=[]): """ There are a plethora of ways to add your key/address/wallet data to a PyBtcWallet object: - PubKeyHash160 (only the 20-byte address) - Public Key (which computes address) - Private Key (which computes public key and address) - Private and Public key (assumes they match, skips verification) - Existing PyBtcAddress object Scanning the blockchain for transactions is remarkably faster when you have information about the first and last time we've seen data in the blockchain. That way, we can skip over parts of the chain where wallet data couldn't possibly exist. """ print 'Adding new address to wallet: ', addr160 = None if isinstance(addrData, PyBtcAddress) and addrData.isInitialized(): addr160 = addrData.getAddr160() self.addrMap[addr160] = addrData elif isinstance(addrData, str): if len(addrData) == 20: addr160 = addrData self.addrMap[addr160] = PyBtcAddress( ).createFromPublicKeyHash160(addr160) elif 64 <= len(addrData) <= 65: addr160 = hash160(addrData.rjust(65, '\x04')) self.addrMap[addr160] = PyBtcAddress().createFromPublicKey( pubKeyStr) elif len(addrData) == 32: newPrivAddr = PyBtcAddress() if len(pubKeyStr) > 0: newPrivAddr.createFromKeyData(addrData, pubKeyStr, False) else: newPrivAddr.createFromPrivateKey(addrData) addr160 = newPrivAddr.getAddr160() self.addrMap[addr160] = newPrivAddr else: print '<ERROR>' raise BadAddressError, 'Improper address supplied to "addAddress()"' print binary_to_hex(addr160) # Now make sure the C++ wallet is sync'd addrObj = self.addrMap[addr160] cppAddr = Cpp.BtcAddress() cppAddr.setAddrStr20(addr160) if addrObj.hasPubKey(): cppAddr.setPubKey65(addrObj.pubKey_serialize()) if addrObj.hasPrivKey(): cppAddr.setPrivKey32(addrObj.privKey_serialize()) if len(firstSeenData) > 0: cppAddr.setFirstTimestamp(firstSeenData[0]) if len(firstSeenData) > 1: cppAddr.setFirstBlockNum(firstSeenData[1]) if len(lastSeenData) > 0: cppAddr.setLastTimestamp(lastSeenData[0]) if len(lastSeenData) > 1: cppAddr.setLastBlockNum(lastSeenData[1]) if not self.cppWallet: self.cppWallet = Cpp.BtcWallet() self.cppWallet.addAddress_BtcAddress_(cppAddr)