-
Notifications
You must be signed in to change notification settings - Fork 181
/
proposal_handler.go
38 lines (34 loc) · 1.2 KB
/
proposal_handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package feesplit
import (
ethcommon "github.com/ethereum/go-ethereum/common"
sdk "github.com/okex/exchain/libs/cosmos-sdk/types"
sdkerrors "github.com/okex/exchain/libs/cosmos-sdk/types/errors"
"github.com/okex/exchain/x/common"
"github.com/okex/exchain/x/feesplit/types"
govTypes "github.com/okex/exchain/x/gov/types"
)
// NewProposalHandler handles "gov" type message in "feesplit"
func NewProposalHandler(k *Keeper) govTypes.Handler {
return func(ctx sdk.Context, proposal *govTypes.Proposal) (err sdk.Error) {
switch content := proposal.Content.(type) {
case types.FeeSplitSharesProposal:
return handleFeeSplitSharesProposal(ctx, k, content)
default:
return common.ErrUnknownProposalType(types.DefaultCodespace, content.ProposalType())
}
}
}
func handleFeeSplitSharesProposal(ctx sdk.Context, k *Keeper, p types.FeeSplitSharesProposal) sdk.Error {
for _, share := range p.Shares {
contract := ethcommon.HexToAddress(share.ContractAddr)
_, found := k.GetFeeSplit(ctx, contract)
if !found {
return sdkerrors.Wrapf(
types.ErrFeeSplitContractNotRegistered,
"contract %s is not registered", share.ContractAddr,
)
}
k.SetContractShare(ctx, contract, share.Share)
}
return nil
}