@@ -3,8 +3,8 @@ package distribution
33import (
44 "embed"
55 "fmt"
6+
67 sdk "github.com/cosmos/cosmos-sdk/types"
7- "github.com/cosmos/evm/x/vm/statedb"
88
99 "github.com/ethereum/go-ethereum/accounts/abi"
1010 "github.com/ethereum/go-ethereum/common"
@@ -86,47 +86,48 @@ func (p Precompile) RequiredGas(input []byte) uint64 {
8686
8787// Run executes the precompiled contract distribution methods defined in the ABI.
8888func (p Precompile ) Run (evm * vm.EVM , contract * vm.Contract , readOnly bool ) ([]byte , error ) {
89- return p .ExecuteWithBalanceHandling (
90- evm , contract , readOnly , p .IsTransaction ,
91- func (ctx sdk.Context , contract * vm.Contract , stateDB * statedb.StateDB , method * abi.Method , args []interface {}) ([]byte , error ) {
92- switch method .Name {
93- // Custom transactions
94- case ClaimRewardsMethod :
95- return p .ClaimRewards (ctx , contract , stateDB , method , args )
96- // Distribution transactions
97- case SetWithdrawAddressMethod :
98- return p .SetWithdrawAddress (ctx , contract , stateDB , method , args )
99- case WithdrawDelegatorRewardMethod :
100- return p .WithdrawDelegatorReward (ctx , contract , stateDB , method , args )
101- case WithdrawValidatorCommissionMethod :
102- return p .WithdrawValidatorCommission (ctx , contract , stateDB , method , args )
103- case FundCommunityPoolMethod :
104- return p .FundCommunityPool (ctx , contract , stateDB , method , args )
105- case DepositValidatorRewardsPoolMethod :
106- return p .DepositValidatorRewardsPool (ctx , contract , stateDB , method , args )
107- // Distribution queries
108- case ValidatorDistributionInfoMethod :
109- return p .ValidatorDistributionInfo (ctx , contract , method , args )
110- case ValidatorOutstandingRewardsMethod :
111- return p .ValidatorOutstandingRewards (ctx , contract , method , args )
112- case ValidatorCommissionMethod :
113- return p .ValidatorCommission (ctx , contract , method , args )
114- case ValidatorSlashesMethod :
115- return p .ValidatorSlashes (ctx , contract , method , args )
116- case DelegationRewardsMethod :
117- return p .DelegationRewards (ctx , contract , method , args )
118- case DelegationTotalRewardsMethod :
119- return p .DelegationTotalRewards (ctx , contract , method , args )
120- case DelegatorValidatorsMethod :
121- return p .DelegatorValidators (ctx , contract , method , args )
122- case DelegatorWithdrawAddressMethod :
123- return p .DelegatorWithdrawAddress (ctx , contract , method , args )
124- case CommunityPoolMethod :
125- return p .CommunityPool (ctx , contract , method , args )
126- }
127- return nil , nil
128- },
129- )
89+ return p .SetupAndRun (evm , contract , readOnly , p .IsTransaction , p .HandleMethod )
90+ }
91+
92+ // HandleMethod handles the execution of each method
93+ func (p Precompile ) HandleMethod (ctx sdk.Context , contract * vm.Contract , stateDB vm.StateDB , method * abi.Method , args []interface {}) ([]byte , error ) {
94+ switch method .Name {
95+ // Custom transactions
96+ case ClaimRewardsMethod :
97+ return p .ClaimRewards (ctx , contract , stateDB , method , args )
98+ // Distribution transactions
99+ case SetWithdrawAddressMethod :
100+ return p .SetWithdrawAddress (ctx , contract , stateDB , method , args )
101+ case WithdrawDelegatorRewardMethod :
102+ return p .WithdrawDelegatorReward (ctx , contract , stateDB , method , args )
103+ case WithdrawValidatorCommissionMethod :
104+ return p .WithdrawValidatorCommission (ctx , contract , stateDB , method , args )
105+ case FundCommunityPoolMethod :
106+ return p .FundCommunityPool (ctx , contract , stateDB , method , args )
107+ case DepositValidatorRewardsPoolMethod :
108+ return p .DepositValidatorRewardsPool (ctx , contract , stateDB , method , args )
109+ // Distribution queries
110+ case ValidatorDistributionInfoMethod :
111+ return p .ValidatorDistributionInfo (ctx , contract , method , args )
112+ case ValidatorOutstandingRewardsMethod :
113+ return p .ValidatorOutstandingRewards (ctx , contract , method , args )
114+ case ValidatorCommissionMethod :
115+ return p .ValidatorCommission (ctx , contract , method , args )
116+ case ValidatorSlashesMethod :
117+ return p .ValidatorSlashes (ctx , contract , method , args )
118+ case DelegationRewardsMethod :
119+ return p .DelegationRewards (ctx , contract , method , args )
120+ case DelegationTotalRewardsMethod :
121+ return p .DelegationTotalRewards (ctx , contract , method , args )
122+ case DelegatorValidatorsMethod :
123+ return p .DelegatorValidators (ctx , contract , method , args )
124+ case DelegatorWithdrawAddressMethod :
125+ return p .DelegatorWithdrawAddress (ctx , contract , method , args )
126+ case CommunityPoolMethod :
127+ return p .CommunityPool (ctx , contract , method , args )
128+ default :
129+ return nil , fmt .Errorf (cmn .ErrUnknownMethod , method .Name )
130+ }
130131}
131132
132133// IsTransaction checks if the given method name corresponds to a transaction or query.
0 commit comments