Last active
December 19, 2015 04:10
-
-
Save ohac/0d57272453681e6aae22 to your computer and use it in GitHub Desktop.
add listsinceblock command to Electrum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/commands.py b/lib/commands.py | |
index ed351ba..7fdc459 100644 | |
--- a/lib/commands.py | |
+++ b/lib/commands.py | |
@@ -454,6 +454,20 @@ class Commands: | |
) | |
return out | |
+ @command('wn') | |
+ def listsinceblock(self, height=-1): | |
+ """Get all transactions in blocks since block [height], or all transactions if omitted.""" | |
+ out = [] | |
+ for item in self.wallet.list_since_block(int(height)): | |
+ height2, pos, tx_hash, conf, delta, timestamp = item | |
+ out.append({ | |
+ 'height':height2, | |
+ 'txid':tx_hash, | |
+ 'value':float(delta)/COIN if delta is not None else None, | |
+ 'confirmations':conf} | |
+ ) | |
+ return out | |
+ | |
@command('w') | |
def setlabel(self, key, label): | |
"""Assign a label to an item. Item may be a bitcoin address or a | |
@@ -661,6 +675,7 @@ command_options = { | |
'pending': (None, "--pending", "Show only pending requests."), | |
'expired': (None, "--expired", "Show only expired requests."), | |
'paid': (None, "--paid", "Show only paid requests."), | |
+ 'height': (None, "--height", "Block height."), | |
} | |
diff --git a/lib/wallet.py b/lib/wallet.py | |
index 9717c9a..ef8f7e6 100644 | |
--- a/lib/wallet.py | |
+++ b/lib/wallet.py | |
@@ -867,6 +867,31 @@ class Abstract_Wallet(PrintError): | |
return h2 | |
+ def list_since_block(self, lastheight=0, domain=None): | |
+ from collections import defaultdict | |
+ if domain is None: | |
+ domain = self.get_account_addresses(None) | |
+ | |
+ tx_deltas = defaultdict(int) | |
+ for addr in domain: | |
+ h = self.get_address_history(addr) | |
+ for tx_hash, height in h: | |
+ if height <= lastheight: continue | |
+ delta = self.get_tx_delta(tx_hash, addr) | |
+ if delta is None or tx_deltas[tx_hash] is None: | |
+ tx_deltas[tx_hash] = None | |
+ else: | |
+ tx_deltas[tx_hash] += delta | |
+ | |
+ history = [] | |
+ for tx_hash, delta in tx_deltas.items(): | |
+ conf, timestamp = self.get_confirmations(tx_hash) | |
+ height, pos = self.get_txpos(tx_hash) | |
+ history.append((height, pos, tx_hash, conf, delta, timestamp)) | |
+ history.sort(key = lambda x: (x[0], x[1])) | |
+ | |
+ return history | |
+ | |
def get_label(self, tx_hash): | |
label = self.labels.get(tx_hash, '') | |
return label |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment