def listunspent(self, addr): key = self.address_to_key(addr) if key is None: raise BaseException('Invalid Bitcoin address', addr) out = [] with self.db_utxo.lock: for k, v in self.db_utxo.db.iterator(start=key): if not k.startswith(key): break if len(k) == KEYLENGTH: txid = k[20:52].encode('hex') txpos = bytes4_to_int(k[52:56]) h = bytes4_to_int(v[8:12]) v = bytes8_to_int(v[0:8]) out.append({ 'tx_hash': txid, 'tx_pos': txpos, 'height': h, 'value': v }) if len(out) == 1000: print_log('max utxo reached', addr) break out.sort(key=lambda x: x['height']) return out
def get_history(self, addr): out = [] o = self.listunspent(addr) for item in o: out.append((item['height'], item['tx_hash'])) h = self.db_hist.get(addr) while h: item = h[0:80] h = h[80:] txi = item[0:32].encode('hex') hi = bytes4_to_int(item[36:40]) txo = item[40:72].encode('hex') ho = bytes4_to_int(item[76:80]) out.append((hi, txi)) out.append((ho, txo)) # uniqueness out = set(out) # sort by height then tx_hash out = sorted(out) return map(lambda x: {'height': x[0], 'tx_hash': x[1]}, out)
def get_history(self, addr): out = [] o = self.listunspent(addr) for item in o: out.append((item['height'], item['tx_hash'])) h = self.db_hist.get(addr) while h: item = h[0:80] h = h[80:] txi = item[0:32].encode('hex') hi = bytes4_to_int(item[36:40]) txo = item[40:72].encode('hex') ho = bytes4_to_int(item[76:80]) out.append((hi, txi)) out.append((ho, txo)) # uniqueness out = set(out) # sort by height then tx_hash out = sorted(out) return map(lambda x: {'height':x[0], 'tx_hash':x[1]}, out)
def listunspent(self, addr): key = self.address_to_key(addr) if key is None: raise BaseException('Invalid Reddcoin address', addr) out = [] with self.db_utxo.lock: for k, v in self.db_utxo.db.iterator(start=key): if not k.startswith(key): break if len(k) == KEYLENGTH: txid = k[20:52].encode('hex') txpos = bytes4_to_int(k[52:56]) h = bytes4_to_int(v[8:12]) v = bytes8_to_int(v[0:8]) out.append({'tx_hash': txid, 'tx_pos':txpos, 'height': h, 'value':v}) if len(out) == 1000: print_log('max utxo reached', addr) break out.sort(key=lambda x:x['height']) return out
def listunspent(self, addr): key = self.address_to_key(addr) if key is None: raise BaseException("Invalid Bitcoin address", addr) out = [] with self.db_utxo.lock: for k, v in self.db_utxo.db.iterator(start=key): if not k.startswith(key): break if len(k) == KEYLENGTH: txid = k[20:52].encode("hex") txpos = bytes4_to_int(k[52:56]) h = bytes4_to_int(v[8:12]) v = bytes8_to_int(v[0:8]) out.append({"tx_hash": txid, "tx_pos": txpos, "height": h, "value": v}) if len(out) == 1000: print_log("max utxo reached", addr) break out.sort(key=lambda x: x["height"]) return out
def set_spent(self, addr, txi, txid, index, height, undo): key = self.address_to_key(addr) leaf = key + txi s = self.delete_key(leaf) value = bytes8_to_int(s[0:8]) in_height = bytes4_to_int(s[8:12]) undo[leaf] = value, in_height # delete backlink txi-> addr self.db_addr.delete(txi) # add to history s = self.db_hist.get(addr) if s is None: s = '' txo = (txid + int_to_hex4(index) + int_to_hex4(height)).decode('hex') s += txi + int_to_bytes4(in_height) + txo s = s[-80 * self.pruning_limit:] self.db_hist.put(addr, s)
def set_spent(self, addr, txi, txid, index, height, undo): key = self.address_to_key(addr) leaf = key + txi s = self.delete_key(leaf) value = bytes8_to_int(s[0:8]) in_height = bytes4_to_int(s[8:12]) undo[leaf] = value, in_height # delete backlink txi-> addr self.db_addr.delete(txi) # add to history s = self.db_hist.get(addr) if s is None: s = '' txo = (txid + int_to_hex4(index) + int_to_hex4(height)).decode('hex') s += txi + int_to_bytes4(in_height) + txo s = s[ -80*self.pruning_limit:] self.db_hist.put(addr, s)