def GetNext(self): kk = pycoin.key.BIP32Node.BIP32Node.from_hwif(self.xpub) for i in range(99999): keypath = "0/%d.pub" % i addr = kk.subkey_for_path(keypath).address() #print i, j, addr ledger = blockchain_info.blockchain(addr, False) if ledger.tx_count() == 0: return addr
def list_addresses(self, filterName=''): balance = {} for i in range(len(self.addresses)): person = self.addresses[i] name = person.items()[0][0] if '' != filterName and name != filterName: continue balance[name] = {} for j in range(len(person.items()[0][1])): addr = person.items()[0][1][j].items()[0][1] desc = person.items()[0][1][j].items()[0][0] if len(addr) == 3: # multisig deterministic hierarchical wallet kk0 = pycoin.key.BIP32Node.BIP32Node.from_hwif(addr[0]) kk1 = pycoin.key.BIP32Node.BIP32Node.from_hwif(addr[1]) kk2 = pycoin.key.BIP32Node.BIP32Node.from_hwif(addr[2]) for k in range( 4 ): # device (0), web (1) or exchange (2) for case hardware wallet. idx (3) used for non-case for j in range( 2): # receive (0) and change (1) addresses gap = 0 found = False for i in range(99999): if k == 3: # regular keypath = "%d/%d.pub" % (j, i) else: # case keypath = "%d/%d/%d.pub" % (k, j, i) #print(keypath) sub0 = kk0.subkey_for_path(keypath).sec() sub1 = kk1.subkey_for_path(keypath).sec() sub2 = kk2.subkey_for_path(keypath).sec() if k == 3: # regular sub = sorted([sub0, sub1, sub2]) else: # case sub = [sub0, sub1, sub2] underlying_script = ScriptMultisig( n=2, sec_keys=[sub[0], sub[1], sub[2]]).script() addr = address_for_pay_to_script( underlying_script, netcode="BTC") ledger = blockchain_info.blockchain( addr, False) bal = ledger.balance() if ledger.tx_count != 0: found = True if found: print desc, i, j, k, addr, bal if bal == 0: if 0 == ledger.tx_count(): gap += 1 if gap > 20: break
def list_addresses(self, filterName = ''): balance = {} for i in range(len(self.addresses)): person = self.addresses[i] name = person.items()[0][0] if '' != filterName and name != filterName: continue balance[name] = {} for j in range(len(person.items()[0][1])): addr = person.items()[0][1][j].items()[0][1] desc = person.items()[0][1][j].items()[0][0] if len(addr) == 3: # multisig deterministic hierarchical wallet kk0 = pycoin.key.BIP32Node.BIP32Node.from_hwif(addr[0]) kk1 = pycoin.key.BIP32Node.BIP32Node.from_hwif(addr[1]) kk2 = pycoin.key.BIP32Node.BIP32Node.from_hwif(addr[2]) for k in range(4): # device (0), web (1) or exchange (2) for case hardware wallet. idx (3) used for non-case for j in range(2): # receive (0) and change (1) addresses gap = 0 found = False for i in range(99999): if k == 3: # regular keypath = "%d/%d.pub" % (j, i) else: # case keypath = "%d/%d/%d.pub" % (k, j, i) #print(keypath) sub0 = kk0.subkey_for_path(keypath).sec() sub1 = kk1.subkey_for_path(keypath).sec() sub2 = kk2.subkey_for_path(keypath).sec() if k == 3: # regular sub = sorted([sub0, sub1, sub2]) else: # case sub = [sub0, sub1, sub2] underlying_script = ScriptMultisig(n=2, sec_keys=[sub[0], sub[1], sub[2]]).script() addr = address_for_pay_to_script(underlying_script, netcode="BTC") ledger = blockchain_info.blockchain(addr, False) bal = ledger.balance() if ledger.tx_count != 0: found = True if found: print desc, i, j, k, addr, bal if bal == 0: if 0 == ledger.tx_count(): gap += 1 if gap > 20: break
def balances(self, filterName = ''): balance = {} for i in range(len(self.addresses)): person = self.addresses[i] name = person.items()[0][0] if '' != filterName and name != filterName: continue balance[name] = {} for j in range(len(person.items()[0][1])): addr = person.items()[0][1][j].items()[0][1] desc = person.items()[0][1][j].items()[0][0] if len(addr) == 3: # multisig deterministic hierarchical wallet kk0 = pycoin.key.BIP32Node.BIP32Node.from_hwif(addr[0]) kk1 = pycoin.key.BIP32Node.BIP32Node.from_hwif(addr[1]) kk2 = pycoin.key.BIP32Node.BIP32Node.from_hwif(addr[2]) for j in range(2): # receive and change addresses gap = 0 for i in range(99999): keypath = "%d/%d.pub" % (j, i) #print(keypath) sub0 = kk0.subkey_for_path(keypath).sec() sub1 = kk1.subkey_for_path(keypath).sec() sub2 = kk2.subkey_for_path(keypath).sec() #print i, j, addr underlying_script = ScriptMultisig(n=2, sec_keys=[sub0, sub1, sub2]).script() addr = address_for_pay_to_script(underlying_script, netcode="BTC") ledger = blockchain_info.blockchain(addr, False) bal = ledger.balance() balance[name][addr] = [bal, '%s_%s_%d' % (desc, 'P' if 0 == j else 'Chg', i)] if bal == 0: if 0 == ledger.tx_count(): gap += 1 if gap > 10: break elif len(addr) < 40: # regular address ledger = blockchain_info.blockchain(addr, False) bal = ledger.balance() balance[name][addr] = [bal, desc] elif 'xpub' == addr[0:4]: # deterministic hierarchical public key kk = pycoin.key.BIP32Node.BIP32Node.from_hwif(addr) for j in range(2): # receive and change addresses gap = 0 for i in range(99999): keypath = "%d/%d.pub" % (j, i) #print(keypath) addr = kk.subkey_for_path(keypath).address() #print i, j, addr ledger = blockchain_info.blockchain(addr, False) bal = ledger.balance() balance[name][addr] = [bal, '%s_%s_%d' % (desc, 'P' if 0 == j else 'Chg', i)] if bal == 0: if 0 == ledger.tx_count(): gap += 1 if gap > 10: break else: kk = pycoin.key.electrum.ElectrumWallet(addr) for i in range(20): for j in range(2): keypath = "%d/%d" % (j, i) addr = kk.subkey(keypath).address() #print i, j, addr ledger = blockchain_info.blockchain(addr, False) bal = ledger.balance() balance[name][addr] = [bal, '%s_%s_%d' % (desc, 'P' if 0 == j else 'Chg', i)] return balance
acc = None for d in dirs: print d if os.path.isfile(d + '/mining.json'): acc = accounts.accounts(d + '/mining.json') break for i in range(len(acc.addresses)): person = acc.addresses[i] name = person.items()[0][0] for j in range(len(person.items()[0][1])): addr = person.items()[0][1][j].items()[0][1] addresses.append(addr) day = now for addr in reversed(addresses): ledger = blockchain_info.blockchain(addr, True) txs = ledger.get_transactions() ledgers[addr] = ledger dates = txs.keys() if len(dates): dates.sort() if dates[0] < day: day = dates[0] sum = 0 sumday = 0 csvwriter = csv.writer(open('earnings.csv', 'wb'), delimiter=',') row = ['day', 'val', 'valInCHFnow', 'valInUSDnow', 'valInCHFthen', 'priceCHFthen'] csvwriter.writerow(row) days = []