diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-02-09 02:25:52 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-02-13 20:00:09 +0800 |
commit | 205ea9580215cca4093dff22ec61222bc3a6ff96 (patch) | |
tree | af6c38683d64bb47c0a31ba166533701cf95ed15 /cmd/geth/main.go | |
parent | c5215fdd48231622dd56aba63a5187c6e42828d4 (diff) | |
download | dexon-205ea9580215cca4093dff22ec61222bc3a6ff96.tar.gz dexon-205ea9580215cca4093dff22ec61222bc3a6ff96.tar.zst dexon-205ea9580215cca4093dff22ec61222bc3a6ff96.zip |
accounts, cmd, internal, node: implement HD wallet self-derivation
Diffstat (limited to 'cmd/geth/main.go')
-rw-r--r-- | cmd/geth/main.go | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/cmd/geth/main.go b/cmd/geth/main.go index e324802b5..06dc55ba8 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -25,12 +25,14 @@ import ( "strings" "time" + "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/console" "github.com/ethereum/go-ethereum/contracts/release" "github.com/ethereum/go-ethereum/eth" + "github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/internal/debug" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger/glog" @@ -249,12 +251,38 @@ func startNode(ctx *cli.Context, stack *node.Node) { ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore) passwords := utils.MakePasswordList(ctx) - accounts := strings.Split(ctx.GlobalString(utils.UnlockedAccountFlag.Name), ",") - for i, account := range accounts { + unlocks := strings.Split(ctx.GlobalString(utils.UnlockedAccountFlag.Name), ",") + for i, account := range unlocks { if trimmed := strings.TrimSpace(account); trimmed != "" { unlockAccount(ctx, ks, trimmed, i, passwords) } } + // Register wallet event handlers to open and auto-derive wallets + events := make(chan accounts.WalletEvent, 16) + stack.AccountManager().Subscribe(events) + + go func() { + // Create an chain state reader for self-derivation + rpcClient, err := stack.Attach() + if err != nil { + utils.Fatalf("Failed to attach to self: %v", err) + } + stateReader := ethclient.NewClient(rpcClient) + + // Listen for wallet event till termination + for event := range events { + if event.Arrive { + if err := event.Wallet.Open(""); err != nil { + glog.V(logger.Info).Infof("New wallet appeared: %s, failed to open: %s", event.Wallet.URL(), err) + } else { + glog.V(logger.Info).Infof("New wallet appeared: %s, %s", event.Wallet.URL(), event.Wallet.Status()) + } + event.Wallet.SelfDerive(accounts.DefaultBaseDerivationPath, stateReader) + } else { + glog.V(logger.Info).Infof("Old wallet dropped: %s", event.Wallet.URL()) + } + } + }() // Start auxiliary services if enabled if ctx.GlobalBool(utils.MiningEnabledFlag.Name) { var ethereum *eth.Ethereum |