Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

assert.gno

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