From 9ba9274ea5c0826296786b58e17df758f5272a2a Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Sat, 20 Jan 2018 12:17:59 -0500 Subject: [PATCH] Use network id from command line Former-commit-id: 78c94954b281ba8b12802e7b54c0d1ceeda36a30 [formerly 907fdb09efcd3b4cc31aee5d9a2e354dfb84e093] Former-commit-id: a9e66d5a14df26edbb4e2eedc1416e29284677cc --- cmd/geth/shardingcmd.go | 2 +- sharding/client.go | 22 ++++++++++++++-------- sharding/client_test.go | 2 +- sharding/vmc.go | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/cmd/geth/shardingcmd.go b/cmd/geth/shardingcmd.go index 090654890..73e4034fd 100644 --- a/cmd/geth/shardingcmd.go +++ b/cmd/geth/shardingcmd.go @@ -13,7 +13,7 @@ var ( Name: "shard", Usage: "Start a sharding client", ArgsUsage: "[endpoint]", - Flags: append(append(consoleFlags, utils.DataDirFlag), utils.PasswordFileFlag), + Flags: []cli.Flag{utils.DataDirFlag, utils.PasswordFileFlag, utils.NetworkIdFlag}, Category: "SHARDING COMMANDS", Description: "TODO(prestonvanloon)- Add sharding client description", } diff --git a/sharding/client.go b/sharding/client.go index ef919cf84..70d9d665e 100644 --- a/sharding/client.go +++ b/sharding/client.go @@ -19,10 +19,11 @@ const ( // Client for sharding. Communicates to geth node via JSON RPC. type Client struct { - endpoint string // Endpoint to JSON RPC - client *ethclient.Client // Ethereum RPC client. - keystore *keystore.KeyStore // Keystore containing the single signer - ctx *cli.Context // Command line context + endpoint string // Endpoint to JSON RPC + client *ethclient.Client // Ethereum RPC client. + keystore *keystore.KeyStore // Keystore containing the single signer + ctx *cli.Context // Command line context + networkID uint64 // Ethereum network ID } // MakeShardingClient for interfacing with geth full node. @@ -40,13 +41,18 @@ func MakeShardingClient(ctx *cli.Context) *Client { if err != nil { panic(err) // TODO(prestonvanloon): handle this } - ks := keystore.NewKeyStore(keydir, scryptN, scryptP) + networkID := uint64(1) + if ctx.GlobalIsSet(utils.NetworkIdFlag.Name) { + networkID = ctx.GlobalUint64(utils.NetworkIdFlag.Name) + } + return &Client{ - endpoint: endpoint, - keystore: ks, - ctx: ctx, + endpoint: endpoint, + keystore: ks, + ctx: ctx, + networkID: networkID, } } diff --git a/sharding/client_test.go b/sharding/client_test.go index 85f67db82..e0378afb5 100644 --- a/sharding/client_test.go +++ b/sharding/client_test.go @@ -21,7 +21,7 @@ import ( cli "gopkg.in/urfave/cli.v1" ) -// FakeEthService based on implementation of internal/ethapi +// FakeEthService based on implementation of internal/ethapi.Client type FakeEthService struct { mu sync.Mutex diff --git a/sharding/vmc.go b/sharding/vmc.go index 5425a0904..1c03aa04c 100644 --- a/sharding/vmc.go +++ b/sharding/vmc.go @@ -81,7 +81,7 @@ func (c *Client) deployVMC() (*common.Address, error) { } tx := types.NewContractCreation(nonce, new(big.Int).SetInt64(0) /*amount*/, contractGasLimit, suggestedGasPrice, abiBytecode) - signed, err := c.keystore.SignTx(accounts[0], tx, new(big.Int).SetInt64(1000) /*chainId*/) // TODO(prestonvanloon): reference chain ID from flag + signed, err := c.keystore.SignTx(accounts[0], tx, new(big.Int).SetUint64(c.networkID)) if err != nil { return nil, fmt.Errorf("unable to sign transaction: %v", err) }