-
Notifications
You must be signed in to change notification settings - Fork 37
/
proposal_handler.go
41 lines (33 loc) · 1.27 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
package keeper
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/peggyjv/sommelier/x/allocation/types"
)
// HandleAddManagedCellarsProposal is a handler for executing a passed community cellar addition proposal
func HandleAddManagedCellarsProposal(ctx sdk.Context, k Keeper, p types.AddManagedCellarsProposal) error {
for _, cellarID := range p.CellarIds {
cellar := types.Cellar{
Id: cellarID,
TickRanges: nil,
}
if _, ok := k.GetCellarByID(ctx, cellar.Address()); ok {
return fmt.Errorf("cellar with id %v already exists for proposal %v", cellarID, p)
}
k.SetCellar(ctx, cellar)
}
return nil
}
// HandleRemoveManagedCellarsProposal is a handler for executing a passed community cellar removal proposal
func HandleRemoveManagedCellarsProposal(ctx sdk.Context, k Keeper, p types.RemoveManagedCellarsProposal) error {
// todo: should we do any checks here? Is there any circumstance where a cellar can't/shouldn't be removed?
for _, cellarID := range p.CellarIds {
cellarAddr := common.HexToAddress(cellarID)
if _, ok := k.GetCellarByID(ctx, cellarAddr); !ok {
return fmt.Errorf("cellar with id %v not found for proposal %v", cellarAddr, p)
}
k.DeleteCellar(ctx, cellarAddr)
}
return nil
}