mint_allowlist.gno
1.68 Kb · 57 lines
1package block
2
3import (
4 "chain"
5
6 "gno.land/p/akkadia/v0/accesscontrol"
7 "gno.land/r/akkadia/v0/admin"
8)
9
10const (
11 SetMintAllowlistEvent = "SetMintAllowlist"
12 RemoveMintAllowlistEvent = "RemoveMintAllowlist"
13)
14
15// SetMintAllowlist adds minters (comma-separated) to the allowlist for a block.
16// Each address is trimmed of whitespace and validated before storage.
17// Adds to existing allowlist; creates a new one if none exists.
18// Admin only.
19func SetMintAllowlist(cur realm, blockID uint32, minters string) {
20 assertNotFrozen()
21 accesscontrol.AssertIsAdmin(0, cur, admin.IsAdmin)
22
23 blockIDStr := blockIDToString(blockID)
24 if !blockStore.Has(blockID) {
25 panic("block not found: " + blockIDStr)
26 }
27 mintedBlockStore.SetMintAllowlist(blockID, parseMintAllowlistCSV(minters))
28
29 chain.Emit(SetMintAllowlistEvent,
30 "blockId", blockIDStr,
31 "minters", minters,
32 )
33}
34
35// RemoveMintAllowlist removes minters (comma-separated) from the allowlist for a block.
36// Each address is trimmed of whitespace and validated before lookup.
37// If the allowlist becomes empty, removes the block entry (= no restriction).
38// Admin only.
39func RemoveMintAllowlist(cur realm, blockID uint32, minters string) {
40 assertNotFrozen()
41 accesscontrol.AssertIsAdmin(0, cur, admin.IsAdmin)
42
43 blockIDStr := blockIDToString(blockID)
44 mintedBlockStore.RemoveMintAllowlist(blockID, parseMintAllowlistCSV(minters))
45
46 chain.Emit(RemoveMintAllowlistEvent,
47 "blockId", blockIDStr,
48 "minters", minters,
49 )
50}
51
52// GetMintAllowlist returns the list of allowed minter addresses.
53// Returns empty slice if no restriction is set.
54func GetMintAllowlist(blockID uint32) []string {
55 assertMigrationStateAvailable()
56 return mintedBlockStore.GetMintAllowlist(blockID)
57}