Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build errors #50

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
48 changes: 34 additions & 14 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
Loading