Skip to content

Commit

Permalink
Merge branch 'stdevAlDen_t353_improve_code_quality4hw_signer' into st…
Browse files Browse the repository at this point in the history
…devAlDen_t255_hardware_wallet_operations ref #255
  • Loading branch information
Alvaro Denis committed Mar 10, 2020
2 parents 9b54a17 + 1051dfe commit bc2f544
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 177 deletions.
127 changes: 0 additions & 127 deletions src/coin/mocks/PersistibleSet.go

This file was deleted.

6 changes: 1 addition & 5 deletions src/coin/skycoin/models/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,11 +825,7 @@ func NewWalletDirectory(dirPath string) *WalletDirectory {
type WalletDirectory struct {
// Implements WallentEnv interface
WalletDir string
wltService core.PersistibleSet
}

func (wd *WalletDirectory) SetWltService(wltSrv core.PersistibleSet) {
wd.wltService = wltSrv
wltService *SkycoinLocalWallet
}

func lookupWallet(env core.WalletEnv, firstAddr string) (core.Wallet, error) {
Expand Down
5 changes: 0 additions & 5 deletions src/core/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ type WalletSet interface {
SupportedWalletTypes() []string
}

type PersistibleSet interface {
WalletSet
WalletStorage
}

// WalletStorage provides access to the underlying wallets data store
type WalletStorage interface {
// Encrypt protects wallet data using cryptography
Expand Down
10 changes: 2 additions & 8 deletions src/models/history/historyManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,8 @@ func (hm *HistoryManager) updateTxns() {
logHistoryManager.Warn("Couldn't get address iterator")
continue
}
var newTxnsFinded bool

for addressIterator.Next() {
newTxnsFinded = false
txnsIterator := addressIterator.Value().GetCryptoAccount().ListTransactions()
if txnsIterator == nil {
logHistoryManager.Warn("Couldn't get transaction iterator")
Expand Down Expand Up @@ -186,15 +185,10 @@ func (hm *HistoryManager) updateTxns() {
if corrupted {
continue
}
newTxnsFinded = true
hm.NewTransactions()
hm.txnFinded[txnsIterator.Value().GetId()] = struct{}{}
}
}
if newTxnsFinded {
models.Helper.RunInMain(func() {
hm.NewTransactions()
})
}

}
}
Expand Down
66 changes: 36 additions & 30 deletions src/models/walletsManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,21 @@ type updateWalletInfo struct {
}
type WalletManager struct {
qtCore.QObject
WalletEnv core.WalletEnv
SeedGenerator core.SeedGenerator
wallets []*QWallet
addresseseByWallets map[string](map[string]*QAddress)
utilByWallets map[string]*utilByWallet
markedAddress map[string]int
outputsByAddress map[string][]*QOutput
outputsByAddressMutex sync.Mutex
altManager core.AltcoinManager
signer core.BlockchainSignService
transactionAPI core.BlockchainTransactionAPI
walletsIterator core.WalletIterator
updaterChannel chan *updateWalletInfo
timerUpdate chan time.Duration
WalletEnv core.WalletEnv
SeedGenerator core.SeedGenerator
wallets []*QWallet
addresseseByWallets map[string](map[string]*QAddress)
orderedAddressesByWallets map[string][]*QAddress
utilByWallets map[string]*utilByWallet
markedAddress map[string]int
outputsByAddress map[string][]*QOutput
outputsByAddressMutex sync.Mutex
altManager core.AltcoinManager
signer core.BlockchainSignService
transactionAPI core.BlockchainTransactionAPI
walletsIterator core.WalletIterator
updaterChannel chan *updateWalletInfo
timerUpdate chan time.Duration

_ func() `slot:"updateWalletEnvs"`
_ func(wltId, address string) `slot:"updateOutputs"`
Expand Down Expand Up @@ -123,6 +124,7 @@ func (walletM *WalletManager) init() {
walletM.ConnectEditMarkAddress(walletM.editMarkAddress)
walletM.ConnectMarkFieldOfAddress(walletM.markFieldOfAddress)
walletM.addresseseByWallets = make(map[string](map[string]*QAddress), 0)
walletM.orderedAddressesByWallets = make(map[string][]*QAddress, 0)
walletM.utilByWallets = make(map[string]*utilByWallet, 0)
walletM.outputsByAddress = make(map[string][]*QOutput, 0)
walletM.SeedGenerator = new(sky.SeedService)
Expand Down Expand Up @@ -295,7 +297,8 @@ func (walletM *WalletManager) updateWalletEnvs() {
func (walletM *WalletManager) initWalletAddresses(wltId string) {
logWalletManager.Info("Updating Addresses")
wlt := walletM.WalletEnv.GetWalletSet().GetWallet(wltId)
qAddresses := make(map[string]*QAddress, 0)
qAddresses1 := make(map[string]*QAddress, 0)
qAddresses2 := make([]*QAddress, 0)
it, err := wlt.GetLoadedAddresses()
if err != nil {
logWalletManager.WithError(err).Warn("Couldn't loaded addresses")
Expand All @@ -313,25 +316,27 @@ func (walletM *WalletManager) initWalletAddresses(wltId string) {
qAddress.SetAddressCoinHours("N/A")
qml.QQmlEngine_SetObjectOwnership(qAddress, qml.QQmlEngine__CppOwnership)

//qAddresses = append(qAddresses, qAddress)
qAddresses[addr.String()] = qAddress
qAddresses2 = append(qAddresses2, qAddress)
qAddresses1[addr.String()] = qAddress
go walletM.getOutputs(wltId, addr.String())
}

walletM.addresseseByWallets[wltId] = qAddresses
walletM.addresseseByWallets[wltId] = qAddresses1
walletM.orderedAddressesByWallets[wltId] = qAddresses2

}

func (walletM *WalletManager) updateAddresses(wltId string) {
mutex := walletM.utilByWallets[wltId].m
mutex := &walletM.utilByWallets[wltId].m
sendChan := walletM.utilByWallets[wltId].sendChannel
addresses, ok := walletM.addresseseByWallets[wltId]
if !ok {
walletM.addresseseByWallets[wltId] = make(map[string]*QAddress)
walletM.orderedAddressesByWallets[wltId] = make([]*QAddress, 0)
addresses = walletM.addresseseByWallets[wltId]
}
mutex.Lock()
defer mutex.Unlock()
(*mutex).Lock()
defer (*mutex).Unlock()
logWalletManager.Info("Updating Addresses")
wlt := walletM.WalletEnv.GetWalletSet().GetWallet(wltId)
if wlt == nil {
Expand Down Expand Up @@ -794,7 +799,6 @@ func (walletM *WalletManager) sendTo(wltId, destinationAddress, amount string) *
}
logWalletManager.Info("Transaction created")
return qTxn

}

func (walletM *WalletManager) signTxn(wltIds, address []string, source string, tmpPwd interface{}, index []int, qTxn *QTransaction) *QTransaction {
Expand Down Expand Up @@ -857,7 +861,12 @@ func (walletM *WalletManager) signTxn(wltIds, address []string, source string, t
logWalletManager.WithError(err).Warnf("No signer %s for wallet %v", source, wlts[0])
return nil
}
if suid, err := signer.GetSignerUID(); err != nil && wlts[0].GetId() == string(suid) {
signerUid, err := signer.GetSignerUID()
if err != nil {
logWalletManager.WithError(err).Errorln("unable to ger signer uuid")
return nil
}
if wlts[0].GetId() == string(signerUid) {
// NOTE the signer is the wallet it self
signer = nil
}
Expand Down Expand Up @@ -1071,16 +1080,13 @@ func (walletM *WalletManager) editWallet(id, label string) *QWallet {
}

func (walletM *WalletManager) getAddresses(Id string) []*QAddress {
addrs, ok := walletM.addresseseByWallets[Id]
addrs, ok := walletM.orderedAddressesByWallets[Id]
if !ok {
walletM.updateAddresses(Id)
addrs = walletM.addresseseByWallets[Id]
}
addresses := make([]*QAddress, 0)
for _, addr := range addrs {
addresses = append(addresses, addr)
addrs = walletM.orderedAddressesByWallets[Id]
}
return addresses

return addrs
}

func fromWalletToQWallet(wlt core.Wallet, isEncrypted, withoutBalance bool) *QWallet {
Expand Down
2 changes: 0 additions & 2 deletions src/models/walletsModel.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,6 @@ func (walletModel *WalletModel) data(index *core.QModelIndex, role int) *core.QV
}
return false
}
// FIXME: consider a double checking here instead of hadHwConnected
// be careful this can have a big performance impact
return core.NewQVariant1(valInSlice())
}
case Expand:
Expand Down

0 comments on commit bc2f544

Please sign in to comment.