diff --git a/README.md b/README.md index c001800..5402822 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,8 @@ Running the following commands will start a Docker container in a data directory at `/ethereum-data` and the Rosetta API accessible at port `8080`. +The `NETWORK` environment variable can be set to `MAINNET`, `ROPSTEN`, `RINKEBY`, `GOERLI` or `TESTNET` (which defaults to `ROPSTEN`). + _It is possible to run `rosetta-ethereum` using a remote node by adding `-e "GETH="` to any online command._ diff --git a/configuration/configuration.go b/configuration/configuration.go index cc8e549..0b419db 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -39,10 +39,19 @@ const ( // to make outbound connections. Offline Mode = "OFFLINE" - // Mainnet is the Bitcoin Mainnet. + // Mainnet is the Ethereum Mainnet. Mainnet string = "MAINNET" - // Testnet is Bitcoin Testnet3. + // Ropsten is the Ethereum Ropsten testnet. + Ropsten string = "ROPSTEN" + + // Rinkeby is the Ethereum Rinkeby testnet. + Rinkeby string = "RINKEBY" + + // Goerli is the Ethereum Görli testnet. + Goerli string = "GOERLI" + + // Testnet defaults to `Ropsten` for backwards compatibility. Testnet string = "TESTNET" // DataDirectory is the default location for all @@ -117,14 +126,30 @@ func LoadConfiguration() (*Configuration, error) { config.GenesisBlockIdentifier = ethereum.MainnetGenesisBlockIdentifier config.Params = params.MainnetChainConfig config.GethArguments = ethereum.MainnetGethArguments - case Testnet: + case Testnet, Ropsten: config.Network = &types.NetworkIdentifier{ Blockchain: ethereum.Blockchain, - Network: ethereum.TestnetNetwork, + Network: ethereum.RopstenNetwork, } - config.GenesisBlockIdentifier = ethereum.TestnetGenesisBlockIdentifier + config.GenesisBlockIdentifier = ethereum.RopstenGenesisBlockIdentifier config.Params = params.RopstenChainConfig - config.GethArguments = ethereum.TestnetGethArguments + config.GethArguments = ethereum.RopstenGethArguments + case Rinkeby: + config.Network = &types.NetworkIdentifier{ + Blockchain: ethereum.Blockchain, + Network: ethereum.RinkebyNetwork, + } + config.GenesisBlockIdentifier = ethereum.RinkebyGenesisBlockIdentifier + config.Params = params.RinkebyChainConfig + config.GethArguments = ethereum.RinkebyGethArguments + case Goerli: + config.Network = &types.NetworkIdentifier{ + Blockchain: ethereum.Blockchain, + Network: ethereum.GoerliNetwork, + } + config.GenesisBlockIdentifier = ethereum.GoerliGenesisBlockIdentifier + config.Params = params.GoerliChainConfig + config.GethArguments = ethereum.GoerliGethArguments case "": return nil, errors.New("NETWORK must be populated") default: diff --git a/configuration/configuration_test.go b/configuration/configuration_test.go index 23c3a6e..bcb642a 100644 --- a/configuration/configuration_test.go +++ b/configuration/configuration_test.go @@ -84,6 +84,57 @@ func TestLoadConfiguration(t *testing.T) { GethArguments: ethereum.MainnetGethArguments, }, }, + "all set (ropsten)": { + Mode: string(Online), + Network: Ropsten, + Port: "1000", + cfg: &Configuration{ + Mode: Online, + Network: &types.NetworkIdentifier{ + Network: ethereum.RopstenNetwork, + Blockchain: ethereum.Blockchain, + }, + Params: params.RopstenChainConfig, + GenesisBlockIdentifier: ethereum.RopstenGenesisBlockIdentifier, + Port: 1000, + GethURL: DefaultGethURL, + GethArguments: ethereum.RopstenGethArguments, + }, + }, + "all set (rinkeby)": { + Mode: string(Online), + Network: Rinkeby, + Port: "1000", + cfg: &Configuration{ + Mode: Online, + Network: &types.NetworkIdentifier{ + Network: ethereum.RinkebyNetwork, + Blockchain: ethereum.Blockchain, + }, + Params: params.RinkebyChainConfig, + GenesisBlockIdentifier: ethereum.RinkebyGenesisBlockIdentifier, + Port: 1000, + GethURL: DefaultGethURL, + GethArguments: ethereum.RinkebyGethArguments, + }, + }, + "all set (goerli)": { + Mode: string(Online), + Network: Goerli, + Port: "1000", + cfg: &Configuration{ + Mode: Online, + Network: &types.NetworkIdentifier{ + Network: ethereum.GoerliNetwork, + Blockchain: ethereum.Blockchain, + }, + Params: params.GoerliChainConfig, + GenesisBlockIdentifier: ethereum.GoerliGenesisBlockIdentifier, + Port: 1000, + GethURL: DefaultGethURL, + GethArguments: ethereum.GoerliGethArguments, + }, + }, "all set (testnet)": { Mode: string(Online), Network: Testnet, @@ -91,19 +142,19 @@ func TestLoadConfiguration(t *testing.T) { cfg: &Configuration{ Mode: Online, Network: &types.NetworkIdentifier{ - Network: ethereum.TestnetNetwork, + Network: ethereum.RopstenNetwork, Blockchain: ethereum.Blockchain, }, Params: params.RopstenChainConfig, - GenesisBlockIdentifier: ethereum.TestnetGenesisBlockIdentifier, + GenesisBlockIdentifier: ethereum.RopstenGenesisBlockIdentifier, Port: 1000, GethURL: DefaultGethURL, - GethArguments: ethereum.TestnetGethArguments, + GethArguments: ethereum.RopstenGethArguments, }, }, "invalid mode": { Mode: "bad mode", - Network: Testnet, + Network: Ropsten, Port: "1000", err: errors.New("bad mode is not a valid mode"), }, @@ -115,7 +166,7 @@ func TestLoadConfiguration(t *testing.T) { }, "invalid port": { Mode: string(Offline), - Network: Testnet, + Network: Ropsten, Port: "bad port", err: errors.New("unable to parse port bad port"), }, diff --git a/ethereum/types.go b/ethereum/types.go index d167c0e..ed1058c 100644 --- a/ethereum/types.go +++ b/ethereum/types.go @@ -34,9 +34,17 @@ const ( // in MainnetNetworkIdentifier. MainnetNetwork string = "Mainnet" - // TestnetNetwork is the value of the network - // in TestnetNetworkIdentifier. - TestnetNetwork string = "Ropsten" + // RopstenNetwork is the value of the network + // in RopstenNetworkIdentifier. + RopstenNetwork string = "Ropsten" + + // RinkebyNetwork is the value of the network + // in RinkebyNetworkNetworkIdentifier. + RinkebyNetwork string = "RinkebyNetwork" + + // GoerliNetwork is the value of the network + // in GoerliNetworkNetworkIdentifier. + GoerliNetwork string = "GoerliNetwork" // Symbol is the symbol value // used in Currency. @@ -119,8 +127,14 @@ const ( ) var ( - // TestnetGethArguments are the arguments to start a ropsten geth instance. - TestnetGethArguments = fmt.Sprintf("%s --ropsten", MainnetGethArguments) + // RopstenGethArguments are the arguments to start a ropsten geth instance. + RopstenGethArguments = fmt.Sprintf("%s --ropsten", MainnetGethArguments) + + // RinkebyGethArguments are the arguments to start a rinkeby geth instance. + RinkebyGethArguments = fmt.Sprintf("%s --rinkeby", MainnetGethArguments) + + // GoerliGethArguments are the arguments to start a ropsten geth instance. + GoerliGethArguments = fmt.Sprintf("%s --goerli", MainnetGethArguments) // MainnetGenesisBlockIdentifier is the *types.BlockIdentifier // of the mainnet genesis block. @@ -129,13 +143,27 @@ var ( Index: GenesisBlockIndex, } - // TestnetGenesisBlockIdentifier is the *types.BlockIdentifier - // of the testnet genesis block. - TestnetGenesisBlockIdentifier = &types.BlockIdentifier{ + // RopstenGenesisBlockIdentifier is the *types.BlockIdentifier + // of the Ropsten genesis block. + RopstenGenesisBlockIdentifier = &types.BlockIdentifier{ Hash: params.RopstenGenesisHash.Hex(), Index: GenesisBlockIndex, } + // RinkebyGenesisBlockIdentifier is the *types.BlockIdentifier + // of the Ropsten genesis block. + RinkebyGenesisBlockIdentifier = &types.BlockIdentifier{ + Hash: params.RinkebyGenesisHash.Hex(), + Index: GenesisBlockIndex, + } + + // GoerliGenesisBlockIdentifier is the *types.BlockIdentifier + // of the Goerli genesis block. + GoerliGenesisBlockIdentifier = &types.BlockIdentifier{ + Hash: params.GoerliGenesisHash.Hex(), + Index: GenesisBlockIndex, + } + // Currency is the *types.Currency for all // Ethereum networks. Currency = &types.Currency{ diff --git a/services/construction_service_test.go b/services/construction_service_test.go index e468b5d..054ffe2 100644 --- a/services/construction_service_test.go +++ b/services/construction_service_test.go @@ -52,7 +52,7 @@ func forceMarshalMap(t *testing.T, i interface{}) map[string]interface{} { func TestConstructionService(t *testing.T) { networkIdentifier = &types.NetworkIdentifier{ - Network: ethereum.TestnetNetwork, + Network: ethereum.RopstenNetwork, Blockchain: ethereum.Blockchain, }