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

1.39 Kb · 50 lines
 1package launchpad
 2
 3import (
 4	ufmt "gno.land/p/nt/ufmt/v0"
 5)
 6
 7// assertIsDepositOwner asserts that the caller is the owner of the deposit.
 8// Panics if the caller is not the owner of the deposit.
 9func (lp *launchpadV1) assertIsDepositOwner(depositID string, caller address) {
10	deposit, err := lp.getDeposit(depositID)
11	if err != nil {
12		panic(err.Error())
13	}
14
15	if !deposit.IsDepositor(caller) {
16		panic(makeErrorWithDetails(errInvalidOwner, ufmt.Sprintf("(%s)", caller.String())).Error())
17	}
18}
19
20// assertIsValidAmount panics if the amount is zero.
21func assertIsValidAmount(amount int64) {
22	if amount < minimumDepositAmount {
23		panic(makeErrorWithDetails(
24			errInvalidAmount,
25			ufmt.Sprintf("amount(%d) should greater than minimum deposit amount(%d)", amount, minimumDepositAmount),
26		))
27	}
28
29	if (amount % minimumDepositAmount) != 0 {
30		panic(makeErrorWithDetails(
31			errInvalidAmount,
32			ufmt.Sprintf("amount(%d) must be a multiple of 1_000_000", amount),
33		))
34	}
35}
36
37// assertHasProject asserts that the caller is the owner of at least one project.
38// Panics if the caller is not the owner of any project.
39func (lp *launchpadV1) assertHasProject(caller address) {
40	if !lp.store.GetProjectRecipients().Has(caller.String()) {
41		panic(makeErrorWithDetails(
42			errInvalidOwner,
43			ufmt.Sprintf("caller %s is not the owner of any project", caller.String()),
44		))
45	}
46}
47
48func assertNotImplementYet() {
49	panic("NotImplementYet")
50}