Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

cmd/swarm: make bzzaccount flag optional and add bzzkeyhex flag #1531

Merged
merged 12 commits into from
Jul 4, 2019
Merged
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ FROM alpine:3.9
RUN apk --no-cache add ca-certificates && update-ca-certificates
COPY --from=builder /swarm/build/bin/swarm /usr/local/bin/
COPY --from=geth /usr/local/bin/geth /usr/local/bin/
COPY docker/run.sh /run.sh
ENTRYPOINT ["/run.sh"]
ENTRYPOINT ["/usr/local/bin/swarm"]
3 changes: 1 addition & 2 deletions Dockerfile.alltools
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ FROM alpine:3.9
RUN apk --no-cache add ca-certificates
COPY --from=builder /swarm/build/bin/* /usr/local/bin/
COPY --from=geth /usr/local/bin/geth /usr/local/bin/
COPY docker/run.sh /run.sh
COPY docker/run-smoke.sh /run-smoke.sh
ENTRYPOINT ["/run.sh"]
ENTRYPOINT ["/usr/local/bin/swarm"]
39 changes: 29 additions & 10 deletions cmd/swarm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,19 +353,38 @@ func registerBzzService(bzzconfig *bzzapi.Config, stack *node.Node) {

func getAccount(bzzaccount string, ctx *cli.Context, stack *node.Node) *ecdsa.PrivateKey {
//an account is mandatory
if bzzaccount == "" {
utils.Fatalf(SwarmErrNoBZZAccount)
}
// Try to load the arg as a hex key file.
if key, err := crypto.LoadECDSA(bzzaccount); err == nil {
log.Info("Swarm account key loaded", "address", crypto.PubkeyToAddress(key.PublicKey))
return key
}
// Otherwise try getting it from the keystore.
am := stack.AccountManager()
ks := am.Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)

return decryptStoreAccount(ks, bzzaccount, utils.MakePasswordList(ctx))
if bzzaccount == "" {
// Check the local keystore for existing accounts
accounts := ks.Accounts()
if len(accounts) > 0 {
// Default to the first account if none was set
skylenet marked this conversation as resolved.
Show resolved Hide resolved
bzzaccount = accounts[0].Address.Hex()
} else {
// Create an account
account, err := ks.NewAccount("")
if err != nil {
utils.Fatalf("failed creating an account: %v", err)
}
bzzaccount = account.Address.Hex()
}
} else {
// Try to load the arg as a hex key file.
if key, err := crypto.LoadECDSA(bzzaccount); err == nil {
log.Info("Swarm account key loaded", "address", crypto.PubkeyToAddress(key.PublicKey))
return key
}
}
// Otherwise try getting it from the keystore
var passwords []string
if path := ctx.GlobalString(utils.PasswordFileFlag.Name); path == "" {
passwords = []string{""}
} else {
passwords = utils.MakePasswordList(ctx)
}
return decryptStoreAccount(ks, bzzaccount, passwords)
}

// getPrivKey returns the private key of the specified bzzaccount
Expand Down
26 changes: 0 additions & 26 deletions docker/run.sh

This file was deleted.