assert.gno
0.91 Kb ยท 42 lines
1package v1
2
3import (
4 "gno.land/p/nt/ufmt"
5 "gno.land/r/gnoswap/common"
6)
7
8// assertCallerIsProposer panics if the caller is not the proposer of the given proposal.
9func assertCallerIsProposer(gv *governanceV1, proposalID int64, caller address) {
10 proposal, exists := gv.getProposal(proposalID)
11 if !exists {
12 panic(errProposalNotFound)
13 }
14
15 if !proposal.IsProposer(caller) {
16 panic(errNotProposer)
17 }
18}
19
20func assertIsValidSmoothingPeriod(smoothingPeriod int64) {
21 if smoothingPeriod < 0 {
22 panic(errInvalidSmoothingPeriod)
23 }
24
25 if smoothingPeriod > maxSmoothingPeriod {
26 panic(errInvalidSmoothingPeriod)
27 }
28}
29
30func assertIsValidToken(tokenPath string) {
31 if tokenPath == "" {
32 panic(makeErrorWithDetails(
33 errInvalidInput, "tokenPath is empty"))
34 }
35
36 if err := common.IsRegistered(tokenPath); err != nil {
37 panic(makeErrorWithDetails(
38 errInvalidInput,
39 ufmt.Sprintf("token(%s) is not registered", tokenPath),
40 ))
41 }
42}