accounts/usbwallet: if a confirmation is pending, skip refresh
This commit is contained in:
parent
26da6daaa9
commit
8ff7e55ab5
|
@ -58,7 +58,10 @@ type LedgerHub struct {
|
||||||
quit chan chan error
|
quit chan chan error
|
||||||
|
|
||||||
stateLock sync.RWMutex // Protects the internals of the hub from racey access
|
stateLock sync.RWMutex // Protects the internals of the hub from racey access
|
||||||
commsLock sync.RWMutex // Allows wallets to lock enumeration (TODO(karalabe): remove if hotplug lands on Windows)
|
|
||||||
|
// TODO(karalabe): remove if hotplug lands on Windows
|
||||||
|
commsPend int // Number of operations blocking enumeration
|
||||||
|
commsLock sync.Mutex // Lock protecting the pending counter and enumeration
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLedgerHub creates a new hardware wallet manager for Ledger devices.
|
// NewLedgerHub creates a new hardware wallet manager for Ledger devices.
|
||||||
|
@ -109,6 +112,10 @@ func (hub *LedgerHub) refreshWallets() {
|
||||||
// be to ditch enumeration in favor of hutplug events, but that don't work yet
|
// be to ditch enumeration in favor of hutplug events, but that don't work yet
|
||||||
// on Windows so if we need to hack it anyway, this is more elegant for now.
|
// on Windows so if we need to hack it anyway, this is more elegant for now.
|
||||||
hub.commsLock.Lock()
|
hub.commsLock.Lock()
|
||||||
|
if hub.commsPend > 0 { // A confirmation is pending, don't refresh
|
||||||
|
hub.commsLock.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for _, info := range hid.Enumerate(0, 0) { // Can't enumerate directly, one valid ID is the 0 wildcard
|
for _, info := range hid.Enumerate(0, 0) { // Can't enumerate directly, one valid ID is the 0 wildcard
|
||||||
for _, id := range ledgerDeviceIDs {
|
for _, id := range ledgerDeviceIDs {
|
||||||
|
|
|
@ -579,9 +579,15 @@ func (w *ledgerWallet) SignTx(account accounts.Account, tx *types.Transaction, c
|
||||||
|
|
||||||
// Ensure the device isn't screwed with while user confirmation is pending
|
// Ensure the device isn't screwed with while user confirmation is pending
|
||||||
// TODO(karalabe): remove if hotplug lands on Windows
|
// TODO(karalabe): remove if hotplug lands on Windows
|
||||||
w.hub.commsLock.RLock()
|
w.hub.commsLock.Lock()
|
||||||
defer w.hub.commsLock.RUnlock()
|
w.hub.commsPend++
|
||||||
|
w.hub.commsLock.Unlock()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
w.hub.commsLock.Lock()
|
||||||
|
w.hub.commsPend--
|
||||||
|
w.hub.commsLock.Unlock()
|
||||||
|
}()
|
||||||
return w.ledgerSign(path, account.Address, tx, chainID)
|
return w.ledgerSign(path, account.Address, tx, chainID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue