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

badges.gno

1.54 Kb · 101 lines
  1package badges
  2
  3import (
  4	"gno.land/p/nt/seqid/v0"
  5	"gno.land/p/nym-helox118/grc721"
  6	"gno.land/r/nym-helox118/pearlpass"
  7)
  8
  9var (
 10	token  *grc721.Token
 11	ledger *grc721.PrivateLedger
 12	issued = map[address]string{}
 13)
 14
 15func CreateCollection(cur realm) {
 16	if !cur.IsCurrent() {
 17		panic("invalid realm")
 18	}
 19
 20	if token != nil {
 21		panic("collection already created")
 22	}
 23
 24	var collectionID seqid.ID
 25
 26	token, ledger = grc721.NewToken(
 27		"Pearl Passport Badges",
 28		"PBADGE",
 29		collectionID,
 30		cur,
 31	)
 32}
 33
 34func MintMyBadge(cur realm) {
 35	if !cur.IsCurrent() {
 36		panic("invalid realm")
 37	}
 38
 39	if ledger == nil {
 40		panic("collection has not been created")
 41	}
 42
 43	owner := cur.Previous().Address()
 44
 45	if issued[owner] != "" {
 46		panic("badge already minted")
 47	}
 48
 49	badge := pearlpass.GetBadge(owner)
 50
 51	if badge == "No badge" {
 52		panic("complete a Pearl Passport quest first")
 53	}
 54
 55	tokenID := owner.String()
 56
 57	err := ledger.Mint(
 58		owner,
 59		grc721.TokenID(tokenID),
 60	)
 61	if err != nil {
 62		panic(err)
 63	}
 64
 65	issued[owner] = badge
 66}
 67
 68func GetMyBadge(owner address) string {
 69	return issued[owner]
 70}
 71
 72func OwnerOf(tokenID string) address {
 73	if token == nil {
 74		panic("collection has not been created")
 75	}
 76
 77	owner, err := token.OwnerOf(grc721.TokenID(tokenID))
 78	if err != nil {
 79		panic(err)
 80	}
 81
 82	return owner
 83}
 84
 85func TotalSupply() int64 {
 86	if token == nil {
 87		return 0
 88	}
 89
 90	return token.TotalSupply()
 91}
 92
 93func Render(_ string) string {
 94	if token == nil {
 95		return "Pearl Passport Badges belum dibuat."
 96	}
 97
 98	return "Pearl Passport Badges\n" +
 99		"Symbol: PBADGE\n" +
100		"Mint satu badge untuk setiap wallet."
101}