@@ -37,6 +37,54 @@ def stopThread(self):
3737
3838 super (addressGenerator , self ).stopThread ()
3939
40+  def  save_address (
41+  self , version , stream , ripe , label , signing_key , encryption_key 
42+  ):
43+  """Write essential address config values and reload cryptors""" 
44+  address  =  encodeAddress (version , stream , ripe )
45+  try :
46+  config .add_section (address )
47+  except  configparser .DuplicateSectionError :
48+  self .logger .info (
49+  '%s already exists. Not adding it again.' , address )
50+  queues .UISignalQueue .put ((
51+  'updateStatusBar' ,
52+  _translate (
53+  "MainWindow" , "%1 is already in 'Your Identities'." 
54+  " Not adding it again." ).arg (address )
55+  ))
56+  return  False 
57+ 58+  self .logger .debug ('label: %s' , label )
59+  signingKeyWIF  =  highlevelcrypto .encodeWalletImportFormat (signing_key )
60+  encryptionKeyWIF  =  highlevelcrypto .encodeWalletImportFormat (
61+  encryption_key )
62+  config .set (address , 'label' , label )
63+  config .set (address , 'enabled' , 'true' )
64+  config .set (address , 'decoy' , 'false' )
65+  config .set (address , 'privsigningkey' , signingKeyWIF .decode ())
66+  config .set (address , 'privencryptionkey' , encryptionKeyWIF .decode ())
67+  config .save ()
68+ 69+  queues .UISignalQueue .put ((
70+  'writeNewAddressToTable' , (label , address , stream )))
71+ 72+  shared .myECCryptorObjects [ripe ] =  highlevelcrypto .makeCryptor (
73+  hexlify (encryption_key ))
74+  shared .myAddressesByHash [ripe ] =  address 
75+  tag  =  highlevelcrypto .double_sha512 (
76+  encodeVarint (version ) +  encodeVarint (stream ) +  ripe )[32 :]
77+  shared .myAddressesByTag [tag ] =  address 
78+ 79+  if  version  ==  3 :
80+  # If this is a chan address, the worker thread won't send out 
81+  # the pubkey over the network. 
82+  queues .workerQueue .put (('sendOutOrStoreMyV3Pubkey' , ripe ))
83+  elif  version  ==  4 :
84+  queues .workerQueue .put (('sendOutOrStoreMyV4Pubkey' , address ))
85+ 86+  return  address 
87+ 4088 def  run (self ):
4189 """ 
4290 Process the requests for addresses generation 
@@ -155,27 +203,14 @@ def run(self):
155203 # The user must have a pretty fast computer. 
156204 # time.time() - startTime equaled zero. 
157205 pass 
158-  address  =  encodeAddress (
159-  addressVersionNumber , streamNumber , ripe )
160- 161-  privSigningKeyWIF  =  highlevelcrypto .encodeWalletImportFormat (
162-  privSigningKey )
163-  privEncryptionKeyWIF  =  highlevelcrypto .encodeWalletImportFormat (
164-  potentialPrivEncryptionKey )
165- 166-  config .add_section (address )
167-  config .set (address , 'label' , label )
168-  config .set (address , 'enabled' , 'true' )
169-  config .set (address , 'decoy' , 'false' )
206+ 207+  address  =  self .save_address (
208+  addressVersionNumber , streamNumber , ripe , label ,
209+  privSigningKey , potentialPrivEncryptionKey )
170210 config .set (address , 'noncetrialsperbyte' , str (
171211 nonceTrialsPerByte ))
172212 config .set (address , 'payloadlengthextrabytes' , str (
173213 payloadLengthExtraBytes ))
174-  config .set (
175-  address , 'privsigningkey' , privSigningKeyWIF .decode ())
176-  config .set (
177-  address , 'privencryptionkey' ,
178-  privEncryptionKeyWIF .decode ())
179214 config .save ()
180215
181216 # The API and the join and create Chan functionality 
@@ -189,15 +224,6 @@ def run(self):
189224 "Done generating address. Doing work necessary" 
190225 " to broadcast it..." )
191226 ))
192-  queues .UISignalQueue .put (('writeNewAddressToTable' , (
193-  label , address , streamNumber )))
194-  shared .reloadMyAddressHashes ()
195-  if  addressVersionNumber  ==  3 :
196-  queues .workerQueue .put ((
197-  'sendOutOrStoreMyV3Pubkey' , ripe ))
198-  elif  addressVersionNumber  ==  4 :
199-  queues .workerQueue .put ((
200-  'sendOutOrStoreMyV4Pubkey' , address ))
201227
202228 elif  command  in  (
203229 'createDeterministicAddresses' , 'createChan' ,
@@ -281,83 +307,28 @@ def run(self):
281307 if  command  ==  'getDeterministicAddress' :
282308 saveAddressToDisk  =  False 
283309
284-  if  saveAddressToDisk  and  live :
285-  privSigningKeyWIF  =  \
286-  highlevelcrypto .encodeWalletImportFormat (
287-  potentialPrivSigningKey )
288-  privEncryptionKeyWIF  =  \
289-  highlevelcrypto .encodeWalletImportFormat (
290-  potentialPrivEncryptionKey )
291- 292-  try :
293-  config .add_section (address )
294-  addressAlreadyExists  =  False 
295-  except  configparser .DuplicateSectionError :
296-  addressAlreadyExists  =  True 
297- 298-  if  addressAlreadyExists :
299-  self .logger .info (
300-  '%s already exists. Not adding it again.' ,
301-  address 
302-  )
303-  queues .UISignalQueue .put ((
304-  'updateStatusBar' ,
305-  _translate (
306-  "MainWindow" ,
307-  "%1 is already in 'Your Identities'." 
308-  " Not adding it again." 
309-  ).arg (address )
310-  ))
311-  else :
312-  self .logger .debug ('label: %s' , label )
313-  config .set (address , 'label' , label )
314-  config .set (address , 'enabled' , 'true' )
315-  config .set (address , 'decoy' , 'false' )
316-  if  command  in  ('createChan' , 'joinChan' ):
317-  config .set (address , 'chan' , 'true' )
318-  config .set (
319-  address , 'noncetrialsperbyte' ,
320-  str (nonceTrialsPerByte ))
321-  config .set (
322-  address , 'payloadlengthextrabytes' ,
323-  str (payloadLengthExtraBytes ))
324-  config .set (
325-  address , 'privsigningkey' ,
326-  privSigningKeyWIF .decode ())
327-  config .set (
328-  address , 'privencryptionkey' ,
329-  privEncryptionKeyWIF .decode ())
330-  config .save ()
331- 332-  queues .UISignalQueue .put ((
333-  'writeNewAddressToTable' ,
334-  (label , address , str (streamNumber ))
335-  ))
336-  listOfNewAddressesToSendOutThroughTheAPI .append (
337-  address )
338-  shared .myECCryptorObjects [ripe ] =  \
339-  highlevelcrypto .makeCryptor (
340-  hexlify (potentialPrivEncryptionKey ))
341-  shared .myAddressesByHash [ripe ] =  address 
342-  tag  =  highlevelcrypto .double_sha512 (
343-  encodeVarint (addressVersionNumber )
344-  +  encodeVarint (streamNumber ) +  ripe 
345-  )[32 :]
346-  shared .myAddressesByTag [tag ] =  address 
347-  if  addressVersionNumber  ==  3 :
348-  # If this is a chan address, 
349-  # the worker thread won't send out 
350-  # the pubkey over the network. 
351-  queues .workerQueue .put ((
352-  'sendOutOrStoreMyV3Pubkey' , ripe ))
353-  elif  addressVersionNumber  ==  4 :
354-  queues .workerQueue .put ((
355-  'sendOutOrStoreMyV4Pubkey' , address ))
356-  queues .UISignalQueue .put ((
357-  'updateStatusBar' ,
358-  _translate (
359-  "MainWindow" , "Done generating address" )
360-  ))
310+  if  saveAddressToDisk  and  live  and  self .save_address (
311+  addressVersionNumber , streamNumber , ripe , label ,
312+  potentialPrivSigningKey , potentialPrivEncryptionKey 
313+  ):
314+  if  command  in  ('createChan' , 'joinChan' ):
315+  config .set (address , 'chan' , 'true' )
316+  config .set (
317+  address , 'noncetrialsperbyte' ,
318+  str (nonceTrialsPerByte ))
319+  config .set (
320+  address , 'payloadlengthextrabytes' ,
321+  str (payloadLengthExtraBytes ))
322+  config .save ()
323+ 324+  listOfNewAddressesToSendOutThroughTheAPI .append (
325+  address )
326+ 327+  queues .UISignalQueue .put ((
328+  'updateStatusBar' ,
329+  _translate (
330+  "MainWindow" , "Done generating address" )
331+  ))
361332 elif  saveAddressToDisk  and  not  live  \
362333 and  not  config .has_section (address ):
363334 listOfNewAddressesToSendOutThroughTheAPI .append (
0 commit comments