Skip to content

Commit

Permalink
cmd/swarm: remove unneeded clientaccountmanager.go
Browse files Browse the repository at this point in the history
  • Loading branch information
jpeletier committed Jul 21, 2018
1 parent 51d4b71 commit 8296320
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 110 deletions.
103 changes: 0 additions & 103 deletions cmd/swarm/clientaccountmanager.go

This file was deleted.

28 changes: 22 additions & 6 deletions cmd/swarm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,6 @@ var defaultSubcommandHelp = cli.Command{
Hidden: true,
}

type AccountManagerProvider interface {
AccountManager() *accounts.Manager
}

var defaultNodeConfig = node.DefaultConfig

// This init function sets defaults so cmd/swarm can run alongside geth.
Expand Down Expand Up @@ -597,7 +593,7 @@ func registerBzzService(bzzconfig *bzzapi.Config, stack *node.Node) {
}
}

func getAccount(bzzaccount string, ctx *cli.Context, provider AccountManagerProvider) *ecdsa.PrivateKey {
func getAccount(bzzaccount string, ctx *cli.Context, stack *node.Node) *ecdsa.PrivateKey {
//an account is mandatory
if bzzaccount == "" {
utils.Fatalf(SWARM_ERR_NO_BZZACCOUNT)
Expand All @@ -608,12 +604,32 @@ func getAccount(bzzaccount string, ctx *cli.Context, provider AccountManagerProv
return key
}
// Otherwise try getting it from the keystore.
am := provider.AccountManager()
am := stack.AccountManager()
ks := am.Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)

return decryptStoreAccount(ks, bzzaccount, utils.MakePasswordList(ctx))
}

// getPrivKey returns the private key of the specified bzzaccount
// Used only by client commands, such as `resource`
func getPrivKey(ctx *cli.Context) *ecdsa.PrivateKey {
// booting up the swarm node just as we do in bzzd action
bzzconfig, err := buildConfig(ctx)
if err != nil {
utils.Fatalf("unable to configure swarm: %v", err)
}
cfg := defaultNodeConfig
if _, err := os.Stat(bzzconfig.Path); err == nil {
cfg.DataDir = bzzconfig.Path
}
utils.SetNodeConfig(ctx, &cfg)
stack, err := node.New(&cfg)
if err != nil {
utils.Fatalf("can't create node: %v", err)
}
return getAccount(bzzconfig.BzzAccount, ctx, stack)
}

func decryptStoreAccount(ks *keystore.KeyStore, account string, passwords []string) *ecdsa.PrivateKey {
var a accounts.Account
var err error
Expand Down
2 changes: 1 addition & 1 deletion cmd/swarm/mru.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

func NewGenericSigner(ctx *cli.Context) mru.Signer {
return mru.NewGenericSigner(getClientAccount(ctx))
return mru.NewGenericSigner(getPrivKey(ctx))
}

// swarm resource create <frequency> [--name <name>] [--data <0x Hexdata> [--multihash=false]]
Expand Down

0 comments on commit 8296320

Please sign in to comment.