diff --git a/.gitignore b/.gitignore index 0cadc0fa..3e71f65d 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,8 @@ /esdata .env *.log +# prevent accidental commit of key files +*.pem mytestnet/** diff --git a/cmd/scCallsExecutor/config/config.toml b/cmd/scCallsExecutor/config/config.toml index 8efb058f..17673137 100644 --- a/cmd/scCallsExecutor/config/config.toml +++ b/cmd/scCallsExecutor/config/config.toml @@ -4,7 +4,7 @@ NetworkAddress = "127.0.0.1:8085" ProxyMaxNoncesDelta = 7 ProxyFinalityCheck = true ProxyCacherExpirationSeconds = 600 -ProxyRestAPIEntityType = "observer" +ProxyRestAPIEntityType = "proxy" IntervalToResendTxsInSeconds = 60 PrivateKeyFile = "keys/multiversx.pem" PollingIntervalInMillis = 6000 diff --git a/cmd/scCallsExecutor/flags.go b/cmd/scCallsExecutor/flags.go index 1605b65a..658fd4eb 100644 --- a/cmd/scCallsExecutor/flags.go +++ b/cmd/scCallsExecutor/flags.go @@ -68,6 +68,21 @@ var ( Name: "log-logger-name", Usage: "Boolean option for logger name in the logs.", } + // networkAddress is used to specify the network address used + networkAddress = cli.StringFlag{ + Name: "network-address", + Usage: "The network address (gateway) to be used. Example: 'https://testnet-explorer.multiversx.com'", + } + // scProxyBech32Address is the smart contract address used to interact with this tool + scProxyBech32Address = cli.StringFlag{ + Name: "sc-proxy-address", + Usage: "The smart contract address in bech32 format to interact with", + } + // privateKeyFile is the MultiversX private key file used to issue transaction for the SC calls + privateKeyFile = cli.StringFlag{ + Name: "private-key-file", + Usage: "The MultiversX private key file used to issue transaction for the SC calls", + } ) func getFlags() []cli.Flag { @@ -80,6 +95,9 @@ func getFlags() []cli.Flag { logWithLoggerName, profileMode, restApiInterface, + networkAddress, + scProxyBech32Address, + privateKeyFile, } } func getFlagsConfig(ctx *cli.Context) config.ContextFlagsConfig { diff --git a/cmd/scCallsExecutor/main.go b/cmd/scCallsExecutor/main.go index abe4a413..c41a5cd5 100644 --- a/cmd/scCallsExecutor/main.go +++ b/cmd/scCallsExecutor/main.go @@ -72,7 +72,7 @@ func startRelay(ctx *cli.Context, version string) error { return errLogger } - log.Info("starting bridge node", "version", version, "pid", os.Getpid()) + log.Info("starting SC calls executor node", "version", version, "pid", os.Getpid()) err := logger.SetLogLevel(flagsConfig.LogLevel) if err != nil { @@ -93,6 +93,19 @@ func startRelay(ctx *cli.Context, version string) error { } } + if ctx.IsSet(scProxyBech32Address.Name) { + cfg.ScProxyBech32Address = ctx.GlobalString(scProxyBech32Address.Name) + log.Info("using flag-defined SC proxy address", "address", cfg.ScProxyBech32Address) + } + if ctx.IsSet(networkAddress.Name) { + cfg.NetworkAddress = ctx.GlobalString(networkAddress.Name) + log.Info("using flag-defined network address", "address", cfg.NetworkAddress) + } + if ctx.IsSet(privateKeyFile.Name) { + cfg.PrivateKeyFile = ctx.GlobalString(privateKeyFile.Name) + log.Info("using flag-defined private key file", "filename", cfg.PrivateKeyFile) + } + if len(cfg.NetworkAddress) == 0 { return fmt.Errorf("empty NetworkAddress in config file") } diff --git a/docker/scCallsExecutor-docker-compose.yml b/docker/scCallsExecutor-docker-compose.yml new file mode 100644 index 00000000..66e6bd06 --- /dev/null +++ b/docker/scCallsExecutor-docker-compose.yml @@ -0,0 +1,17 @@ +version: "3.9" + +services: + sc-calls-executor: + build: + context: .. + dockerfile: scCallsExecutor.Dockerfile + restart: unless-stopped + volumes: + - "../keys:/multiversx/keys" + # change the `network-address`, `sc-proxy-address` and `private-key-file` accordingly + entrypoint: "./scCallsExecutor \ + -log-level *:DEBUG \ + -log-save \ + -network-address https://devnet-gateway.multiversx.com \ + -sc-proxy-address erd1qqqqqqqqqqqqqpgq5l0743nyv45vdptmfh3jydkqtyzjqpgsrcjq8yuzxk \ + -private-key-file ./keys/walletKey.pem" diff --git a/scCallsExecutor.Dockerfile b/scCallsExecutor.Dockerfile new file mode 100644 index 00000000..f07085a6 --- /dev/null +++ b/scCallsExecutor.Dockerfile @@ -0,0 +1,26 @@ +FROM golang:1.20.7-bookworm AS builder +LABEL description="This Docker image builds the SC calls executor binary." + +WORKDIR /multiversx +COPY . . + +RUN go mod tidy + +WORKDIR /multiversx/cmd/scCallsExecutor + +RUN APPVERSION=$(git describe --tags --long --always | tail -c 11) && echo "package main\n\nfunc init() {\n\tappVersion = \"${APPVERSION}\"\n}" > local.go +RUN go mod tidy +RUN go build + +FROM ubuntu:22.04 AS runner +LABEL description="This Docker image runs SC calls executor binary." + +RUN apt-get update \ + && apt-get -y install git \ + && apt-get clean + +COPY --from=builder /multiversx/cmd/scCallsExecutor /multiversx + +WORKDIR /multiversx + +ENTRYPOINT ["./scCallsExecutor"]