Skip to content

Commit

Permalink
recovery tool test unit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
goatpig committed Apr 11, 2014
1 parent e234901 commit 2769bd3
Show file tree
Hide file tree
Showing 5 changed files with 355 additions and 130 deletions.
19 changes: 17 additions & 2 deletions ArmoryQt.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def __init__(self, parent=None):
#Setup the signal to spawn progress dialogs from the main thread
self.connect(self, SIGNAL('initTrigger') , self.initTrigger)
self.connect(self, SIGNAL('spawnTrigger'), self.spawnTrigger)
self.connect(self, SIGNAL('checkForkedImports'), self.checkForkedImports)

# We want to determine whether the user just upgraded to a new version
self.firstLoadNewVersion = False
Expand Down Expand Up @@ -6176,6 +6177,18 @@ def initTrigger(self, toInit):
toInit.setup(self)
toInit.status = 1

#############################################################################
def checkForkedImports(self):

forkedImports = []

for wlt in self.walletMap:
if self.walletMap[wlt].hasForkedImports:
forkedImports.append(self.walletMap[wlt].uniqueIDB58)

if len(forkedImports):
DlgForkedImports(forkedImports, self, self).show()

#############################################################################
@AllowAsync
def CheckWalletConsistency(self, wallets, prgAt=None):
Expand All @@ -6193,6 +6206,7 @@ def CheckWalletConsistency(self, wallets, prgAt=None):
i=0
dlgrdy = [0]
nerrors = 0

for wlt in wallets:
if prgAt:
prgAt[0] = i
Expand All @@ -6201,7 +6215,7 @@ def CheckWalletConsistency(self, wallets, prgAt=None):
i = f +i

self.wltCstStatus = WalletConsistencyCheck(wallets[wlt], prgAt)
if self.wltCstStatus != 0:
if self.wltCstStatus != 0 and (not isinstance(self.wltCstStatus, dict) or self.wltCstStatus['nErrors'] != 0):
self.WltCstError(wallets[wlt], self.wltCstStatus, dlgrdy)
while not dlgrdy[0]:
time.sleep(0.01)
Expand All @@ -6217,12 +6231,13 @@ def CheckWalletConsistency(self, wallets, prgAt=None):
time.sleep(0.1)
if nerrors == 0:
self.emit(SIGNAL('UWCS'), [1, 'No Wallet Error Found', 10000, dlgrdy])
self.emit(SIGNAL('checkForkedImports'))
else:
while not dlgrdy:
self.emit(SIGNAL('UWCS'), [1, 'Found Errors in your Wallets!!!', 0, dlgrdy])
time.sleep(1)

#make sure nothing is running right before forcing the fix your wallet dialog up
#make sure nothing is running right before forcing the 'fix your wallet' dialog up
self.checkRdyForFix()

def checkRdyForFix(self):
Expand Down
44 changes: 26 additions & 18 deletions armoryengine/PyBtcWallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ def __init__(self):
#for progress dialog
self.mainWnd = None
self.parent = None

#flags the wallet if it has off chain imports (from a consistency repair)
self.hasForkedImports = False

#############################################################################
def getWalletVersion(self):
Expand Down Expand Up @@ -1963,25 +1966,30 @@ def readWalletFile(self, wltpath, verifyIntegrity=True, doScanNow=False):
newAddr.walletByteLoc = byteLocation + 21
# Fix byte errors in the address data
fixedAddrData = newAddr.serialize()
if newAddr.chainIndex > -3:
if not rawData==fixedAddrData:
self.walletFileSafeUpdate([ \
[WLT_UPDATE_MODIFY, newAddr.walletByteLoc, fixedAddrData]])
if newAddr.useEncryption:
newAddr.isLocked = True
self.addrMap[hashVal] = newAddr
if newAddr.chainIndex > self.lastComputedChainIndex:
self.lastComputedChainIndex = newAddr.chainIndex
self.lastComputedChainAddr160 = newAddr.getAddr160()
self.linearAddr160List.append(newAddr.getAddr160())
self.chainIndexMap[newAddr.chainIndex] = newAddr.getAddr160()

if not rawData==fixedAddrData:
self.walletFileSafeUpdate([ \
[WLT_UPDATE_MODIFY, newAddr.walletByteLoc, fixedAddrData]])
if newAddr.useEncryption:
newAddr.isLocked = True
self.addrMap[hashVal] = newAddr
if newAddr.chainIndex > self.lastComputedChainIndex:
self.lastComputedChainIndex = newAddr.chainIndex
self.lastComputedChainAddr160 = newAddr.getAddr160()

if newAddr.chainIndex < -2:
newAddr.chainIndex = -2
self.hasForkedImports = True

self.linearAddr160List.append(newAddr.getAddr160())
self.chainIndexMap[newAddr.chainIndex] = newAddr.getAddr160()

# Update the parallel C++ object that scans the blockchain for us
timeRng = newAddr.getTimeRange()
blkRng = newAddr.getBlockRange()
self.cppWallet.addScrAddress_5_(Hash160ToScrAddr(hashVal), \
timeRng[0], blkRng[0], \
timeRng[1], blkRng[1])
# Update the parallel C++ object that scans the blockchain for us
timeRng = newAddr.getTimeRange()
blkRng = newAddr.getBlockRange()
self.cppWallet.addScrAddress_5_(Hash160ToScrAddr(hashVal), \
timeRng[0], blkRng[0], \
timeRng[1], blkRng[1])

if dtype in (WLT_DATATYPE_ADDRCOMMENT, WLT_DATATYPE_TXCOMMENT):
self.commentsMap[hashVal] = rawData # actually ASCII data, here
Expand Down

0 comments on commit 2769bd3

Please sign in to comment.