Skip to content

Commit

Permalink
paginate vsp accounts screen
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 committed Nov 13, 2019
1 parent c3c2e7f commit be41115
Show file tree
Hide file tree
Showing 6 changed files with 384 additions and 203 deletions.
46 changes: 22 additions & 24 deletions accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ def __init__(self, pubKeyEncrypted, privKeyEncrypted, name, coinID, netID):
self.netID = netID
self.net = None
setNetwork(self)
# For external addresses, the cursor can sit on the last seen address,
# For external addresses, the cursor can sit on the last seen address,
# so start the lastSeen at the 0th external address. This is necessary
# because the currentAddress method grabs the address at the current
# cursor position, rather than the next.
# because the currentAddress method grabs the address at the current
# cursor position, rather than the next.
self.lastSeenExt = 0
# For internal addresses, the cursor can sit below zero, since the
# addresses are always retrieved with with nextInternalAddress.
Expand Down Expand Up @@ -448,21 +448,19 @@ def addTxid(self, addr, txid):
txids = self.txs[addr]
if txid not in txids:
txids.append(txid)
try:
# Advance the cursors as necessary.
if addr in self.externalAddresses:
extIdx = self.externalAddresses.index(addr)
if extIdx > self.lastSeenExt:
diff = extIdx - self.lastSeenExt
self.lastSeenExt = extIdx
self.cursorExt = max(0, self.cursorExt-diff)
except ValueError:
try:
intIdx = self.internalAddresses.index(addr)
if intIdx > self.lastSeenInt:
diff = intIdx - self.lastSeenInt
self.lastSeenInt = intIdx
self.cursorInt = max(0, self.cursorInt-diff)
except ValueError:
raise Exception("attempting to add transaction %s for unknown address %s" % (txid, addr))
elif addr in self.internalAddresses:
intIdx = self.internalAddresses.index(addr)
if intIdx > self.lastSeenInt:
diff = intIdx - self.lastSeenInt
self.lastSeenInt = intIdx
self.cursorInt = max(0, self.cursorInt-diff)
def confirmTx(self, tx, blockHeight):
"""
Confirm a transaction. Sets height for any unconfirmed UTXOs in the
Expand Down Expand Up @@ -535,11 +533,11 @@ def nextExternalAddress(self):
"""
extAddrs = self.externalAddresses
addr = CrazyAddress
# Though unlikely, if an out or range key is generated, the account will
# Though unlikely, if an out or range key is generated, the account will
# generate an additional address
while addr == CrazyAddress:
# gap policy is to wrap. Wrapping brings the cursor back to index 1,
# since the index zero is the last seen address.
# gap policy is to wrap. Wrapping brings the cursor back to index 1,
# since the index zero is the last seen address.
self.cursorExt += 1
if self.cursorExt > self.gapLimit:
self.cursorExt = 1
Expand All @@ -557,11 +555,11 @@ def nextInternalAddress(self):
"""
intAddrs = self.internalAddresses
addr = CrazyAddress
# Though unlikely, if an out or range key is generated, the account will
# Though unlikely, if an out or range key is generated, the account will
# generate an additional address
while addr == CrazyAddress:
# gap policy is to wrap. Wrapping brings the cursor back to index 1,
# since the index zero is the last seen address.
# gap policy is to wrap. Wrapping brings the cursor back to index 1,
# since the index zero is the last seen address.
self.cursorInt += 1
if self.cursorInt > self.gapLimit:
self.cursorInt = 1
Expand All @@ -572,7 +570,7 @@ def nextInternalAddress(self):
return addr
def lastSeen(self, addrs):
"""
Find the index of the last seen address in the list of addresses.
Find the index of the last seen address in the list of addresses.
The last seen address is taken as the last address for which there is an
entry in the self.txs dict.
Expand Down Expand Up @@ -630,7 +628,7 @@ def watchAddrs(self):
return filterCrazyAddress(a)
def unseenAddrs(self):
return filterCrazyAddress(
[a for a in self.internalAddresses if a not in self.txs] +
[a for a in self.internalAddresses if a not in self.txs] +
[a for a in self.externalAddresses if a not in self.txs])
def currentAddress(self):
"""
Expand Down Expand Up @@ -1191,7 +1189,7 @@ def test_gap_handling(self):
account.gapLimit = gapLimit
listsAreEqual = lambda a, b: len(a) == len(b) and all(x == y for x,y in zip(a,b))
self.assertTrue(listsAreEqual(account.internalAddresses, internalAddrs[:gapLimit]))
# The external branch starts with the "last seen" at the zeroth address, so
# The external branch starts with the "last seen" at the zeroth address, so
# has one additional address to start.
self.assertTrue(listsAreEqual(account.externalAddresses, externalAddrs[:gapLimit+1]))

Expand All @@ -1200,7 +1198,7 @@ def test_gap_handling(self):
self.assertEqual(len(newAddrs), 1)
self.assertEqual(newAddrs[0], internalAddrs[5])

# The zeroth external address is considered "seen", so this should not
# The zeroth external address is considered "seen", so this should not
# change anything.
account.addTxid(externalAddrs[0], "somerandomtxid")
newAddrs = account.generateGapAddresses()
Expand All @@ -1212,7 +1210,7 @@ def test_gap_handling(self):
self.assertEqual(len(newAddrs), 1)
self.assertEqual(externalAddrs[1], account.currentAddress())

# cursor should be at index 0, last seen 1, max index 6, so calling
# cursor should be at index 0, last seen 1, max index 6, so calling
# nextExternalAddress 5 time should put the cursor at index 6, which is
# the gap limit.
for i in range(5):
Expand Down
6 changes: 4 additions & 2 deletions pydecred/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from tinydecred.util import tinyjson, helpers
from tinydecred.crypto.crypto import AddressSecpPubKey
from tinydecred.pydecred import txscript
from tinydecred.pydecred.stakepool import StakePool

log = helpers.getLogger("DCRACCT")

Expand Down Expand Up @@ -192,7 +193,8 @@ def setPool(self, pool):
Args:
pool (stakepool.StakePool): The stake pool object.
"""
self.stakePools = [pool] + [p for p in self.stakePools if p.url != pool.url]
assert isinstance(pool, StakePool)
self.stakePools = [pool] + [p for p in self.stakePools if p.apiKey != pool.apiKey]
def hasPool(self):
"""
hasPool will return True if the wallet has at least one pool set.
Expand Down Expand Up @@ -349,7 +351,7 @@ def sync(self, blockchain, signals):
requestedTxs += 1
self.addTxid(addr, txid)
addrs = self.generateGapAddresses()
log.info("%d address transactions sets fetched" % requestedTxs)
log.debug("%d address transactions sets fetched" % requestedTxs)

# start with a search for all known addresses
addresses = self.allAddresses()
Expand Down
Loading

0 comments on commit be41115

Please sign in to comment.