@@ -43,20 +43,21 @@ type updateWalletInfo struct {
4343}
4444type WalletManager struct {
4545 qtCore.QObject
46- WalletEnv core.WalletEnv
47- SeedGenerator core.SeedGenerator
48- wallets []* QWallet
49- addresseseByWallets map [string ](map [string ]* QAddress )
50- utilByWallets map [string ]* utilByWallet
51- markedAddress map [string ]int
52- outputsByAddress map [string ][]* QOutput
53- outputsByAddressMutex sync.Mutex
54- altManager core.AltcoinManager
55- signer core.BlockchainSignService
56- transactionAPI core.BlockchainTransactionAPI
57- walletsIterator core.WalletIterator
58- updaterChannel chan * updateWalletInfo
59- timerUpdate chan time.Duration
46+ WalletEnv core.WalletEnv
47+ SeedGenerator core.SeedGenerator
48+ wallets []* QWallet
49+ addresseseByWallets map [string ](map [string ]* QAddress )
50+ orderedAddressesByWallets map [string ][]* QAddress
51+ utilByWallets map [string ]* utilByWallet
52+ markedAddress map [string ]int
53+ outputsByAddress map [string ][]* QOutput
54+ outputsByAddressMutex sync.Mutex
55+ altManager core.AltcoinManager
56+ signer core.BlockchainSignService
57+ transactionAPI core.BlockchainTransactionAPI
58+ walletsIterator core.WalletIterator
59+ updaterChannel chan * updateWalletInfo
60+ timerUpdate chan time.Duration
6061
6162 _ func () `slot:"updateWalletEnvs"`
6263 _ func (wltId , address string ) `slot:"updateOutputs"`
@@ -123,6 +124,7 @@ func (walletM *WalletManager) init() {
123124 walletM .ConnectEditMarkAddress (walletM .editMarkAddress )
124125 walletM .ConnectMarkFieldOfAddress (walletM .markFieldOfAddress )
125126 walletM .addresseseByWallets = make (map [string ](map [string ]* QAddress ), 0 )
127+ walletM .orderedAddressesByWallets = make (map [string ][]* QAddress , 0 )
126128 walletM .utilByWallets = make (map [string ]* utilByWallet , 0 )
127129 walletM .outputsByAddress = make (map [string ][]* QOutput , 0 )
128130 walletM .SeedGenerator = new (sky.SeedService )
@@ -295,7 +297,8 @@ func (walletM *WalletManager) updateWalletEnvs() {
295297func (walletM * WalletManager ) initWalletAddresses (wltId string ) {
296298 logWalletManager .Info ("Updating Addresses" )
297299 wlt := walletM .WalletEnv .GetWalletSet ().GetWallet (wltId )
298- qAddresses := make (map [string ]* QAddress , 0 )
300+ qAddresses1 := make (map [string ]* QAddress , 0 )
301+ qAddresses2 := make ([]* QAddress , 0 )
299302 it , err := wlt .GetLoadedAddresses ()
300303 if err != nil {
301304 logWalletManager .WithError (err ).Warn ("Couldn't loaded addresses" )
@@ -313,25 +316,27 @@ func (walletM *WalletManager) initWalletAddresses(wltId string) {
313316 qAddress .SetAddressCoinHours ("N/A" )
314317 qml .QQmlEngine_SetObjectOwnership (qAddress , qml .QQmlEngine__CppOwnership )
315318
316- //qAddresses = append(qAddresses , qAddress)
317- qAddresses [addr .String ()] = qAddress
319+ qAddresses2 = append (qAddresses2 , qAddress )
320+ qAddresses1 [addr .String ()] = qAddress
318321 go walletM .getOutputs (wltId , addr .String ())
319322 }
320323
321- walletM .addresseseByWallets [wltId ] = qAddresses
324+ walletM .addresseseByWallets [wltId ] = qAddresses1
325+ walletM .orderedAddressesByWallets [wltId ] = qAddresses2
322326
323327}
324328
325329func (walletM * WalletManager ) updateAddresses (wltId string ) {
326- mutex := walletM .utilByWallets [wltId ].m
330+ mutex := & walletM .utilByWallets [wltId ].m
327331 sendChan := walletM .utilByWallets [wltId ].sendChannel
328332 addresses , ok := walletM .addresseseByWallets [wltId ]
329333 if ! ok {
330334 walletM .addresseseByWallets [wltId ] = make (map [string ]* QAddress )
335+ walletM .orderedAddressesByWallets [wltId ] = make ([]* QAddress , 0 )
331336 addresses = walletM .addresseseByWallets [wltId ]
332337 }
333- mutex .Lock ()
334- defer mutex .Unlock ()
338+ ( * mutex ) .Lock ()
339+ defer ( * mutex ) .Unlock ()
335340 logWalletManager .Info ("Updating Addresses" )
336341 wlt := walletM .WalletEnv .GetWalletSet ().GetWallet (wltId )
337342 if wlt == nil {
@@ -794,7 +799,6 @@ func (walletM *WalletManager) sendTo(wltId, destinationAddress, amount string) *
794799 }
795800 logWalletManager .Info ("Transaction created" )
796801 return qTxn
797-
798802}
799803
800804func (walletM * WalletManager ) signTxn (wltIds , address []string , source string , tmpPwd interface {}, index []int , qTxn * QTransaction ) * QTransaction {
@@ -857,7 +861,12 @@ func (walletM *WalletManager) signTxn(wltIds, address []string, source string, t
857861 logWalletManager .WithError (err ).Warnf ("No signer %s for wallet %v" , source , wlts [0 ])
858862 return nil
859863 }
860- if suid , err := signer .GetSignerUID (); err != nil && wlts [0 ].GetId () == string (suid ) {
864+ signerUid , err := signer .GetSignerUID ()
865+ if err != nil {
866+ logWalletManager .WithError (err ).Errorln ("unable to ger signer uuid" )
867+ return nil
868+ }
869+ if wlts [0 ].GetId () == string (signerUid ) {
861870 // NOTE the signer is the wallet it self
862871 signer = nil
863872 }
@@ -1071,16 +1080,13 @@ func (walletM *WalletManager) editWallet(id, label string) *QWallet {
10711080}
10721081
10731082func (walletM * WalletManager ) getAddresses (Id string ) []* QAddress {
1074- addrs , ok := walletM .addresseseByWallets [Id ]
1083+ addrs , ok := walletM .orderedAddressesByWallets [Id ]
10751084 if ! ok {
10761085 walletM .updateAddresses (Id )
1077- addrs = walletM .addresseseByWallets [Id ]
1078- }
1079- addresses := make ([]* QAddress , 0 )
1080- for _ , addr := range addrs {
1081- addresses = append (addresses , addr )
1086+ addrs = walletM .orderedAddressesByWallets [Id ]
10821087 }
1083- return addresses
1088+
1089+ return addrs
10841090}
10851091
10861092func fromWalletToQWallet (wlt core.Wallet , isEncrypted , withoutBalance bool ) * QWallet {
0 commit comments