Skip to content

Commit f0a399b

Browse files
envestccCopilot
andauthored
fix: return error instead of nil in ethabi EncodeToEth methods (#4784)
Six ethabi files incorrectly returned nil instead of err when Outputs.Pack() failed, silently swallowing the error. This fix ensures the actual error is propagated to callers. Files fixed: - action/protocol/rewarding/ethabi/availablebalance.go - action/protocol/rewarding/ethabi/totalbalance.go - action/protocol/rewarding/ethabi/unclaimedbalance.go - action/protocol/staking/ethabi/common/candidatebyname.go - action/protocol/staking/ethabi/common/stake_totalstakingamount.go - action/protocol/staking/ethabi/common/types.go Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a70ad6b commit f0a399b

File tree

6 files changed

+6
-6
lines changed

6 files changed

+6
-6
lines changed

action/protocol/rewarding/ethabi/availablebalance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (r *AvailableBalanceStateContext) EncodeToEth(resp *iotexapi.ReadStateRespo
5959

6060
data, err := _availableBalanceMethod.Outputs.Pack(total)
6161
if err != nil {
62-
return "", nil
62+
return "", err
6363
}
6464

6565
return hex.EncodeToString(data), nil

action/protocol/rewarding/ethabi/totalbalance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (r *TotalBalanceStateContext) EncodeToEth(resp *iotexapi.ReadStateResponse)
5959

6060
data, err := _totalBalanceMethod.Outputs.Pack(total)
6161
if err != nil {
62-
return "", nil
62+
return "", err
6363
}
6464

6565
return hex.EncodeToString(data), nil

action/protocol/rewarding/ethabi/unclaimedbalance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (r *UnclaimedBalanceStateContext) EncodeToEth(resp *iotexapi.ReadStateRespo
8181

8282
data, err := _unclaimedBalanceMethod.Outputs.Pack(total)
8383
if err != nil {
84-
return "", nil
84+
return "", err
8585
}
8686

8787
return hex.EncodeToString(data), nil

action/protocol/staking/ethabi/common/candidatebyname.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (r *CandidateByNameStateContext) EncodeToEth(resp *iotexapi.ReadStateRespon
7979

8080
data, err := r.Method.Outputs.Pack(cand)
8181
if err != nil {
82-
return "", nil
82+
return "", err
8383
}
8484
return hex.EncodeToString(data), nil
8585
}

action/protocol/staking/ethabi/common/stake_totalstakingamount.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (r *TotalStakingAmountStateContext) EncodeToEth(resp *iotexapi.ReadStateRes
5959

6060
data, err := r.Method.Outputs.Pack(total)
6161
if err != nil {
62-
return "", nil
62+
return "", err
6363
}
6464
return hex.EncodeToString(data), nil
6565
}

action/protocol/staking/ethabi/common/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func EncodeVoteBucketListToEth(outputs abi.Arguments, buckets *iotextypes.VoteBu
100100

101101
data, err := outputs.Pack(args)
102102
if err != nil {
103-
return "", nil
103+
return "", err
104104
}
105105
return hex.EncodeToString(data), nil
106106
}

0 commit comments

Comments
 (0)