Skip to content

Commit 64e4a81

Browse files
committed
refactor: use reflect.TypeFor
Signed-off-by: cuoguojida <cuoguojida@outlook.com>
1 parent f386433 commit 64e4a81

6 files changed

Lines changed: 8 additions & 10 deletions

File tree

bindings/legacy/v1.1.0-rc1/rewards/rewards.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,7 @@ func GetRewardSnapshotEvent(rp *rocketpool.RocketPool, index uint64, intervalSiz
203203
}
204204

205205
// Get the decoded data
206-
submissionPrototype := RewardSubmission{}
207-
submissionType := reflect.TypeOf(submissionPrototype)
206+
submissionType := reflect.TypeFor[RewardSubmission]()
208207
submission := reflect.ValueOf(values["submission"]).Convert(submissionType).Interface().(RewardSubmission)
209208
eventIntervalStartTime := values["intervalStartTime"].(*big.Int)
210209
eventIntervalEndTime := values["intervalEndTime"].(*big.Int)
@@ -266,8 +265,7 @@ func GetRewardSnapshotEventWithUpgrades(rp *rocketpool.RocketPool, index uint64,
266265
}
267266

268267
// Get the decoded data
269-
submissionPrototype := RewardSubmission{}
270-
submissionType := reflect.TypeOf(submissionPrototype)
268+
submissionType := reflect.TypeFor[RewardSubmission]()
271269
submission := reflect.ValueOf(values["submission"]).Convert(submissionType).Interface().(RewardSubmission)
272270
eventIntervalStartTime := values["intervalStartTime"].(*big.Int)
273271
eventIntervalEndTime := values["intervalEndTime"].(*big.Int)

shared/services/config/rocket-pool-config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,8 +837,8 @@ func (cfg *RocketPoolConfig) Deserialize(masterMap map[string]map[string]string)
837837
if exists {
838838
networkString, exists := smartnodeConfig[cfg.Smartnode.Network.ID]
839839
if exists {
840-
valueType := reflect.TypeOf(networkString)
841-
paramType := reflect.TypeOf(network)
840+
valueType := reflect.TypeFor[string]()
841+
paramType := reflect.TypeFor[config.Network]()
842842
if !valueType.ConvertibleTo(paramType) {
843843
return fmt.Errorf("can't get default network: value type %s cannot be converted to parameter type %s", valueType.Name(), paramType.Name())
844844
}

shared/types/config/parameter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (param *Parameter) Deserialize(serializedParams map[string]string, network
111111
if len(param.Options) < 1 {
112112
err = fmt.Errorf("this parameter is marked as a choice but does not have any options")
113113
} else {
114-
valueType := reflect.TypeOf(value)
114+
valueType := reflect.TypeFor[string]()
115115
paramType := reflect.TypeOf(param.Options[0].Value)
116116
if !valueType.ConvertibleTo(paramType) {
117117
err = fmt.Errorf("value type %s cannot be converted to parameter type %s", valueType.Name(), paramType.Name())

shared/types/eth2/fork/deneb/state_deneb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func getStateChunkSize() uint64 {
5252
// Use a static value to avoid multiple reflection calls
5353
storedChunkSize := beaconStateChunkSize.Load()
5454
if storedChunkSize == 0 {
55-
s := reflect.TypeOf(BeaconState{}).NumField()
55+
s := reflect.TypeFor[BeaconState]().NumField()
5656
beaconStateChunkSize.Store(uint64(s))
5757
storedChunkSize = uint64(s)
5858
}

shared/types/eth2/fork/electra/state_electra.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func getStateChunkSize() uint64 {
6363
// Use a static value to avoid multiple reflection calls
6464
storedChunkSize := beaconStateChunkSize.Load()
6565
if storedChunkSize == 0 {
66-
s := reflect.TypeOf(BeaconState{}).NumField()
66+
s := reflect.TypeFor[BeaconState]().NumField()
6767
beaconStateChunkSize.Store(uint64(s))
6868
storedChunkSize = uint64(s)
6969
}

shared/types/eth2/fork/fulu/state_fulu.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func getStateChunkSize() uint64 {
6666
// Use a static value to avoid multiple reflection calls
6767
storedChunkSize := beaconStateChunkSize.Load()
6868
if storedChunkSize == 0 {
69-
s := reflect.TypeOf(BeaconState{}).NumField()
69+
s := reflect.TypeFor[BeaconState]().NumField()
7070
beaconStateChunkSize.Store(uint64(s))
7171
storedChunkSize = uint64(s)
7272
}

0 commit comments

Comments
 (0)