diff --git a/api/config.go b/api/config.go index 8f7d7e3e..8459a12e 100644 --- a/api/config.go +++ b/api/config.go @@ -15,7 +15,10 @@ var DefaultGasPrice = big.NewInt(8049999872) // - whether JSON-RPC is exposed HTTP/WebSocket or both // - some connection timeout options etc type Config struct { - ChainID *big.Int - Coinbase common.Address - GasPrice *big.Int + ChainID *big.Int + Coinbase common.Address + GasPrice *big.Int + Host string + Port int + AccessURL string } diff --git a/cmd/server/main.go b/cmd/server/main.go index ff7f7977..e9bfb0dc 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -21,10 +21,7 @@ import ( "github.com/rs/zerolog" ) -const ( - defaultAccessURL = grpc.EmulatorHost - coinbaseAddr = "0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb" -) +const coinbaseAddr = "0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb" var blockExecutedType = (types.EVMLocation{}).TypeID(nil, string(types.EventTypeBlockExecuted)) var txExecutedType = (types.EVMLocation{}).TypeID(nil, string(types.EventTypeTransactionExecuted)) @@ -35,22 +32,40 @@ var evmEventTypes = []string{ } func main() { - var network, coinbase string + var network, coinbase, host string var gasPrice int64 + var port int - flag.StringVar(&network, "network", "testnet", "network to connect the gateway to") + flag.StringVar(&network, "network", "emulator", "network to connect the gateway to") flag.StringVar(&coinbase, "coinbase", coinbaseAddr, "coinbase address to use for fee collection") + flag.StringVar(&host, "host", "", "address to run the gateway") flag.Int64Var(&gasPrice, "gasPrice", api.DefaultGasPrice.Int64(), "gas price for transactions") + flag.IntVar(&port, "port", 8545, "port to run the gateway") flag.Parse() config := &api.Config{ - Coinbase: common.HexToAddress(coinbase), - GasPrice: big.NewInt(gasPrice), + Coinbase: common.HexToAddress(coinbase), + GasPrice: big.NewInt(gasPrice), + Host: host, + Port: port, + AccessURL: grpc.EmulatorHost, } + if network == "testnet" { config.ChainID = api.FlowEVMTestnetChainID + config.AccessURL = grpc.TestnetHost } else if network == "mainnet" { config.ChainID = api.FlowEVMMainnetChainID + config.AccessURL = grpc.MainnetHost + } else if network == "canarynet" { + config.ChainID = api.FlowEVMTestnetChainID + config.AccessURL = grpc.CanarynetHost + } else if network == "crescendo" { + config.ChainID = api.FlowEVMTestnetChainID + config.AccessURL = grpc.CrescendoHost + } else if network == "emulator" { + config.ChainID = api.FlowEVMTestnetChainID + config.AccessURL = grpc.EmulatorHost } else { panic(fmt.Errorf("unknown network: %s", network)) } @@ -61,14 +76,19 @@ func main() { logger := zerolog.New(zerolog.NewConsoleWriter()).With().Timestamp().Logger() runServer(config, store, logger) - runIndexer(ctx, store, logger) + runIndexer(config, ctx, store, logger) runtime.Goexit() } -func runIndexer(ctx context.Context, store *storage.Store, logger zerolog.Logger) { +func runIndexer( + config *api.Config, + ctx context.Context, + store *storage.Store, + logger zerolog.Logger, +) { flowClient, err := grpc.NewBaseClient( - defaultAccessURL, + config.AccessURL, goGrpc.WithTransportCredentials(insecure.NewCredentials()), ) if err != nil { @@ -93,7 +113,7 @@ func runIndexer(ctx context.Context, store *storage.Store, logger zerolog.Logger var err error flowClient, err := grpc.NewBaseClient( - defaultAccessURL, + config.AccessURL, goGrpc.WithTransportCredentials(insecure.NewCredentials()), ) if err != nil { @@ -180,7 +200,7 @@ func runIndexer(ctx context.Context, store *storage.Store, logger zerolog.Logger func runServer(config *api.Config, store *storage.Store, logger zerolog.Logger) { srv := api.NewHTTPServer(logger, rpc.DefaultHTTPTimeouts) - flowClient, err := api.NewFlowClient(grpc.EmulatorHost) + flowClient, err := api.NewFlowClient(config.AccessURL) if err != nil { panic(err) } @@ -190,7 +210,7 @@ func runServer(config *api.Config, store *storage.Store, logger zerolog.Logger) srv.EnableRPC(supportedAPIs) srv.EnableWS(supportedAPIs) - srv.SetListenAddr("", 8545) + srv.SetListenAddr(config.Host, config.Port) err = srv.Start() if err != nil { diff --git a/go.mod b/go.mod index d1292cfd..018ca35f 100644 --- a/go.mod +++ b/go.mod @@ -185,3 +185,7 @@ require ( lukechampine.com/blake3 v1.2.1 // indirect rsc.io/tmplfunc v0.0.3 // indirect ) + +// TODO(m-Peter): Temporary workaround to unblock the build process +// CGO_ENABLED=0 go build -o evm-gateway ./cmd/server/main.go fails! +replace github.com/onflow/crypto => github.com/onflow/crypto v0.24.9 diff --git a/go.sum b/go.sum index 41d6df19..aedf1c3f 100644 --- a/go.sum +++ b/go.sum @@ -1807,8 +1807,8 @@ github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f/go.mod h1:xvP61FoOs github.com/onflow/cadence v1.0.0-M3/go.mod h1:odXGZZ/wGNA5mwT8bC9v8u8EXACHllB2ABSZK65TGL8= github.com/onflow/cadence v1.0.0-M6 h1:3Y5xFrmOGMCAaHKNjEwCbnDFlkwZHDzeOtrcX9beWMA= github.com/onflow/cadence v1.0.0-M6/go.mod h1:a4mccDU90hmuxCLUFzs9J/ANG/rYbFa36h4Z0bBAqNU= -github.com/onflow/crypto v0.25.0 h1:BeWbLsh3ZD13Ej+Uky6kg1PL1ZIVBDVX+2MVBNwqddg= -github.com/onflow/crypto v0.25.0/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI= +github.com/onflow/crypto v0.24.9 h1:jYP1qdwid0qCineFzBFlxBchg710A7RuSWpTqxaOdog= +github.com/onflow/crypto v0.24.9/go.mod h1:J/V7IEVaqjDajvF8K0B/SJPJDgAOP2G+LVLeb0hgmbg= github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240206003101-928bf99024d7 h1:OI/4F2NK/X/4x3dTUFFDGtuOsSa9pX+jjBeSEcBrY/M= github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240206003101-928bf99024d7/go.mod h1:GK+Ik1K3L3v8xmHmRQv5yxJz81lYhdYSNm0PQ63Xrws= github.com/onflow/flow-core-contracts/lib/go/templates v0.15.2-0.20240206003101-928bf99024d7 h1:WAx8ftVz1BeXiKvQ9gLKEf1J3NBWK26Pbczd0iH4C6I= @@ -2014,6 +2014,7 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= github.com/supranational/blst v0.3.8-0.20220526154634-513d2456b344/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= +github.com/supranational/blst v0.3.10/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4= github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=