From 5fb1c2a6012ea687a6d2c72faf8a2b4298cd9e32 Mon Sep 17 00:00:00 2001 From: nolash Date: Sat, 24 Dec 2016 13:07:44 +0100 Subject: [PATCH] swarm: read format and comment docs, updated fixes ethereum/go-ethereum#3444 --- cmd/swarm/main.go | 8 +++----- swarm/api/config.go | 14 +++++++------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/cmd/swarm/main.go b/cmd/swarm/main.go index 3551a59da4..fc6e9127d3 100644 --- a/cmd/swarm/main.go +++ b/cmd/swarm/main.go @@ -76,8 +76,6 @@ var ( SwarmNetworkIdFlag = cli.IntFlag{ Name: "bzznetworkid", Usage: "Network identifier (integer, default 3=swarm testnet)", - // defining this here means we can't distinguish if it was passed at cmd line or system default when deciding to use saved values from config - //Value: network.NetworkId, } SwarmConfigPathFlag = cli.StringFlag{ Name: "bzzconfig", @@ -238,7 +236,7 @@ func bzzd(ctx *cli.Context) error { } func registerBzzService(ctx *cli.Context, stack *node.Node) { - + prvkey := getAccount(ctx, stack) chbookaddr := common.HexToAddress(ctx.GlobalString(ChequebookAddrFlag.Name)) @@ -246,7 +244,7 @@ func registerBzzService(ctx *cli.Context, stack *node.Node) { if bzzdir == "" { bzzdir = stack.InstanceDir() } - + bzzconfig, err := bzzapi.NewConfig(bzzdir, chbookaddr, prvkey, ctx.GlobalUint64(SwarmNetworkIdFlag.Name)) if err != nil { utils.Fatalf("unable to configure swarm: %v", err) @@ -277,7 +275,7 @@ func registerBzzService(ctx *cli.Context, stack *node.Node) { func getAccount(ctx *cli.Context, stack *node.Node) *ecdsa.PrivateKey { keyid := ctx.GlobalString(SwarmAccountFlag.Name) - + if keyid == "" { utils.Fatalf("Option %q is required", SwarmAccountFlag.Name) } diff --git a/swarm/api/config.go b/swarm/api/config.go index 72822f3d98..acb861cbfe 100644 --- a/swarm/api/config.go +++ b/swarm/api/config.go @@ -70,7 +70,7 @@ func NewConfig(path string, contract common.Address, prvKey *ecdsa.PrivateKey, n pubkey := crypto.FromECDSAPub(&prvKey.PublicKey) pubkeyhex := common.ToHex(pubkey) keyhex := crypto.Sha3Hash(pubkey).Hex() - + self = &Config{ SyncParams: network.NewSyncParams(dirpath), HiveParams: network.NewHiveParams(dirpath), @@ -89,12 +89,12 @@ func NewConfig(path string, contract common.Address, prvKey *ecdsa.PrivateKey, n if networkId == 0 { self.NetworkId = network.NetworkId } - + if err != nil { if !os.IsNotExist(err) { return } - + // file does not exist // write out config file err = self.Save() @@ -103,7 +103,7 @@ func NewConfig(path string, contract common.Address, prvKey *ecdsa.PrivateKey, n } return } - + // file exists, deserialise err = json.Unmarshal(data, self) if err != nil { @@ -116,13 +116,13 @@ func NewConfig(path string, contract common.Address, prvKey *ecdsa.PrivateKey, n if keyhex != self.BzzKey { return nil, fmt.Errorf("bzz key does not match the one in the config file %v != %v", keyhex, self.BzzKey) } - + if networkId != 0 { self.NetworkId = networkId } - + self.Swap.SetKey(prvKey) - + if (self.EnsRoot == common.Address{}) { self.EnsRoot = ensRootAddress }