Skip to content

Commit 7d4852b

Browse files
authored
eth/catalyst: return methods by reflect (#32300)
Return the exposed methods in `ConsensusAPI` by reflection.
1 parent 62ac0e0 commit 7d4852b

File tree

1 file changed

+11
-35
lines changed

1 file changed

+11
-35
lines changed

eth/catalyst/api.go

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ package catalyst
2020
import (
2121
"errors"
2222
"fmt"
23+
"reflect"
2324
"strconv"
2425
"sync"
2526
"sync/atomic"
2627
"time"
28+
"unicode"
2729

2830
"github.com/ethereum/go-ethereum/beacon/engine"
2931
"github.com/ethereum/go-ethereum/common"
@@ -80,41 +82,6 @@ const (
8082
beaconUpdateWarnFrequency = 5 * time.Minute
8183
)
8284

83-
// All methods provided over the engine endpoint.
84-
var caps = []string{
85-
"engine_forkchoiceUpdatedV1",
86-
"engine_forkchoiceUpdatedV2",
87-
"engine_forkchoiceUpdatedV3",
88-
"engine_forkchoiceUpdatedWithWitnessV1",
89-
"engine_forkchoiceUpdatedWithWitnessV2",
90-
"engine_forkchoiceUpdatedWithWitnessV3",
91-
"engine_exchangeTransitionConfigurationV1",
92-
"engine_getPayloadV1",
93-
"engine_getPayloadV2",
94-
"engine_getPayloadV3",
95-
"engine_getPayloadV4",
96-
"engine_getPayloadV5",
97-
"engine_getBlobsV1",
98-
"engine_getBlobsV2",
99-
"engine_newPayloadV1",
100-
"engine_newPayloadV2",
101-
"engine_newPayloadV3",
102-
"engine_newPayloadV4",
103-
"engine_newPayloadWithWitnessV1",
104-
"engine_newPayloadWithWitnessV2",
105-
"engine_newPayloadWithWitnessV3",
106-
"engine_newPayloadWithWitnessV4",
107-
"engine_executeStatelessPayloadV1",
108-
"engine_executeStatelessPayloadV2",
109-
"engine_executeStatelessPayloadV3",
110-
"engine_executeStatelessPayloadV4",
111-
"engine_getPayloadBodiesByHashV1",
112-
"engine_getPayloadBodiesByHashV2",
113-
"engine_getPayloadBodiesByRangeV1",
114-
"engine_getPayloadBodiesByRangeV2",
115-
"engine_getClientVersionV1",
116-
}
117-
11885
var (
11986
// Number of blobs requested via getBlobsV2
12087
getBlobsRequestedCounter = metrics.NewRegisteredCounter("engine/getblobs/requested", nil)
@@ -916,6 +883,15 @@ func (api *ConsensusAPI) checkFork(timestamp uint64, forks ...forks.Fork) bool {
916883

917884
// ExchangeCapabilities returns the current methods provided by this node.
918885
func (api *ConsensusAPI) ExchangeCapabilities([]string) []string {
886+
valueT := reflect.TypeOf(api)
887+
caps := make([]string, 0, valueT.NumMethod())
888+
for i := 0; i < valueT.NumMethod(); i++ {
889+
name := []rune(valueT.Method(i).Name)
890+
if string(name) == "ExchangeCapabilities" {
891+
continue
892+
}
893+
caps = append(caps, "engine_"+string(unicode.ToLower(name[0]))+string(name[1:]))
894+
}
919895
return caps
920896
}
921897

0 commit comments

Comments
 (0)