-
Notifications
You must be signed in to change notification settings - Fork 182
/
proposal_handler.go
60 lines (52 loc) · 2.23 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package evm
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/okex/exchain/x/common"
"github.com/okex/exchain/x/evm/types"
govTypes "github.com/okex/exchain/x/gov/types"
)
// NewManageContractDeploymentWhitelistProposalHandler handles "gov" type message in "evm"
func NewManageContractDeploymentWhitelistProposalHandler(k *Keeper) govTypes.Handler {
return func(ctx sdk.Context, proposal *govTypes.Proposal) (err sdk.Error) {
switch content := proposal.Content.(type) {
case types.ManageContractDeploymentWhitelistProposal:
return handleManageContractDeploymentWhitelistProposal(ctx, k, proposal)
case types.ManageContractBlockedListProposal:
return handleManageContractBlockedlListProposal(ctx, k, proposal)
default:
return common.ErrUnknownProposalType(types.DefaultCodespace, content.ProposalType())
}
}
}
func handleManageContractDeploymentWhitelistProposal(ctx sdk.Context, k *Keeper, proposal *govTypes.Proposal) sdk.Error {
// check
manageContractDeploymentWhitelistProposal, ok := proposal.Content.(types.ManageContractDeploymentWhitelistProposal)
if !ok {
return types.ErrUnexpectedProposalType
}
csdb := types.CreateEmptyCommitStateDB(k.GeneratePureCSDBParams(), ctx)
if manageContractDeploymentWhitelistProposal.IsAdded {
// add deployer addresses into whitelist
csdb.SetContractDeploymentWhitelist(manageContractDeploymentWhitelistProposal.DistributorAddrs)
return nil
}
// remove deployer addresses from whitelist
csdb.DeleteContractDeploymentWhitelist(manageContractDeploymentWhitelistProposal.DistributorAddrs)
return nil
}
func handleManageContractBlockedlListProposal(ctx sdk.Context, k *Keeper, proposal *govTypes.Proposal) sdk.Error {
// check
manageContractBlockedListProposal, ok := proposal.Content.(types.ManageContractBlockedListProposal)
if !ok {
return types.ErrUnexpectedProposalType
}
csdb := types.CreateEmptyCommitStateDB(k.GeneratePureCSDBParams(), ctx)
if manageContractBlockedListProposal.IsAdded {
// add contract addresses into blocked list
csdb.SetContractBlockedList(manageContractBlockedListProposal.ContractAddrs)
return nil
}
// remove contract addresses from blocked list
csdb.DeleteContractBlockedList(manageContractBlockedListProposal.ContractAddrs)
return nil
}