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

feat(WithReplacementArgs): fix --use-reth-for-validation by replacing existing args #24

Merged
Merged
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
33 changes: 31 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"os/signal"
"path/filepath"
"reflect"
"slices"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -411,7 +412,7 @@ func setupServices(svcManager *serviceManager, out *output) error {
"--authrpc.jwtsecret", "{{.Dir}}/jwtsecret",
).
If(useRethForValidation, func(s *service) *service {
return s.WithArgs("--http.api", "eth,web3,net,rpc,flashbots")
return s.WithReplacementArgs("--http.api", "admin,eth,web3,net,rpc,flashbots")
}).
If(
semver.Compare(rethVersion, "v1.1.0") >= 0,
Expand Down Expand Up @@ -752,16 +753,44 @@ func (s *service) WithPort(name string, portNumber int) *service {
}

func (s *service) WithArgs(args ...string) *service {
// use template substitution to load constants
tmplVars := s.tmplVars()
for i, arg := range args {
args[i] = applyTemplate(arg, tmplVars)
}

s.args = append(s.args, args...)
return s
}

func (s *service) tmplVars() map[string]interface{} {
tmplVars := map[string]interface{}{
"Dir": s.srvMng.out.dst,
}
return tmplVars
}

// WithReplacementArgs finds the first occurrence of the first argument in the current arguments,
// and replaces it and len(args) - 1 more arguments with the new arguments.
//
// For example:
//
// s.WithArgs("a", "b", "c").WithReplacementArgs("b", "d") will result in ["a", "b", "d"]
func (s *service) WithReplacementArgs(args ...string) *service {
if len(args) == 0 {
return s
}
// use template substitution to load constants
tmplVars := s.tmplVars()
for i, arg := range args {
args[i] = applyTemplate(arg, tmplVars)
}

s.args = append(s.args, args...)
if i := slices.Index(s.args, args[0]); i != -1 {
s.args = slices.Replace(s.args, i, i+len(args), args...)
} else {
s.args = append(s.args, args...)
}
return s
}

Expand Down
Loading