diff options
author | Péter Szilágyi <peterke@gmail.com> | 2018-04-18 18:59:32 +0800 |
---|---|---|
committer | Guillaume Ballet <gballet@gmail.com> | 2019-04-08 19:19:37 +0800 |
commit | 114de0fe2a7ff43ec9811cc11a5f555795a716a0 (patch) | |
tree | 521d71c988429f1d9da46360d21486c42be75901 /console | |
parent | 475e8719baa05b135bd281b6a402d0cbf7f6c729 (diff) | |
download | go-tangerine-114de0fe2a7ff43ec9811cc11a5f555795a716a0.tar go-tangerine-114de0fe2a7ff43ec9811cc11a5f555795a716a0.tar.gz go-tangerine-114de0fe2a7ff43ec9811cc11a5f555795a716a0.tar.bz2 go-tangerine-114de0fe2a7ff43ec9811cc11a5f555795a716a0.tar.lz go-tangerine-114de0fe2a7ff43ec9811cc11a5f555795a716a0.tar.xz go-tangerine-114de0fe2a7ff43ec9811cc11a5f555795a716a0.tar.zst go-tangerine-114de0fe2a7ff43ec9811cc11a5f555795a716a0.zip |
accounts/scwallet, console: user friendly card opening
Diffstat (limited to 'console')
-rw-r--r-- | console/bridge.go | 56 |
1 files changed, 47 insertions, 9 deletions
diff --git a/console/bridge.go b/console/bridge.go index 33277cf6e..03d97e0ef 100644 --- a/console/bridge.go +++ b/console/bridge.go @@ -23,6 +23,7 @@ import ( "strings" "time" + "github.com/ethereum/go-ethereum/accounts/scwallet" "github.com/ethereum/go-ethereum/accounts/usbwallet" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rpc" @@ -104,22 +105,59 @@ func (b *bridge) OpenWallet(call otto.FunctionCall) (response otto.Value) { if err == nil { return val } - // Wallet open failed, report error unless it's a PIN entry - if strings.HasSuffix(err.Error(), usbwallet.ErrTrezorPINNeeded.Error()) { + + // Wallet open failed, report error unless it's a PIN or PUK entry + switch { + case strings.HasSuffix(err.Error(), usbwallet.ErrTrezorPINNeeded.Error()): val, err = b.readPinAndReopenWallet(call) if err == nil { return val } - } - // Check if the user needs to input a passphrase - if !strings.HasSuffix(err.Error(), usbwallet.ErrTrezorPassphraseNeeded.Error()) { - throwJSException(err.Error()) - } - val, err = b.readPassphraseAndReopenWallet(call) - if err != nil { + val, err = b.readPassphraseAndReopenWallet(call) + if err != nil { + throwJSException(err.Error()) + } + + case strings.HasSuffix(err.Error(), scwallet.ErrPUKNeeded.Error()): + // PUK input requested, fetch from the user and call open again + if input, err := b.prompter.PromptPassword("Please enter current PUK: "); err != nil { + throwJSException(err.Error()) + } else { + passwd, _ = otto.ToValue(input) + } + if val, err = call.Otto.Call("jeth.openWallet", nil, wallet, passwd); err != nil { + if !strings.HasSuffix(err.Error(), scwallet.ErrPINNeeded.Error()) { + throwJSException(err.Error()) + } else { + // PIN input requested, fetch from the user and call open again + if input, err := b.prompter.PromptPassword("Please enter current PIN: "); err != nil { + throwJSException(err.Error()) + } else { + passwd, _ = otto.ToValue(input) + } + if val, err = call.Otto.Call("jeth.openWallet", nil, wallet, passwd); err != nil { + throwJSException(err.Error()) + } + } + } + + case strings.HasSuffix(err.Error(), scwallet.ErrPINNeeded.Error()): + // PIN input requested, fetch from the user and call open again + if input, err := b.prompter.PromptPassword("Please enter current PIN: "); err != nil { + throwJSException(err.Error()) + } else { + passwd, _ = otto.ToValue(input) + } + if val, err = call.Otto.Call("jeth.openWallet", nil, wallet, passwd); err != nil { + throwJSException(err.Error()) + } + + default: + // Unknown error occurred, drop to the user throwJSException(err.Error()) } return val +>>>>>>> accounts/scwallet, console: user friendly card opening } func (b *bridge) readPassphraseAndReopenWallet(call otto.FunctionCall) (otto.Value, error) { |