Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

v1 source realm

Package assets is Sinopia's immutable asset store for uploaded collections (docs/uploaded-collections.md §4–§6, §0a)....

Overview

Package assets is Sinopia's immutable asset store for uploaded collections (docs/uploaded-collections.md §4–§6, §0a). An artist creates a store, declares artworks (on-chain bytes or IPFS CIDs, each with its sha256, editions, a creator-assigned tier and trait values), uploads the on-chain bytes in chunks, and seals it. A sealed store never changes: the upload engine (r/…/engines/upload) binds one sealed store to one Draft collection and reads its art from here.

Guarantees (design §14):

  • only the store's owner writes, and only from a wallet (direct MsgCall, IsUserCall); nothing here accepts or holds coins;
  • a store is Draft until Seal, which is irreversible: records, titles, dictionaries and bytes are immutable afterwards;
  • an "on-chain" artwork is complete only when every byte is stored, its sha256 equals the declared one and media.CheckImage passed (magic + dimensions; SVG through safe.AssertSVG, 16 KiB cap);
  • an "ipfs" artwork always says ipfs; a raw CID's digest is checked against the declared sha256 on chain;
  • every user string passed safe.AssertText; JSON goes through safe.JSONWriter.

Storage is paid by the owner who writes it, and only the owner can free Draft data (Truncate), so refunds go back to the payer (T8).

Constants 1

const MaxArtworks, MaxSlots, MaxEditions, MaxTraitTypes, MaxTiers, MaxDictValues, MaxStoreValues, MaxNameLen, MaxValueLen, MaxTitleLen, MaxLabelLen, MaxStoreOnchainBytes, MaxChunk, SegmentBytes, MaxBatch, MaxPage

 1const (
 2	MaxArtworks          = 10_000 // = core MaxSupplyCap
 3	MaxSlots             = 10_000 // Bind requires slots == maxSupply
 4	MaxEditions          = 10_000
 5	MaxTraitTypes        = 8 // core-path manifest slots "Trait 1".."Trait 8" (was 16)
 6	MaxTiers             = 8
 7	MaxDictValues        = 100 // distinct values per trait type (was 255)
 8	MaxStoreValues       = 255 // distinct values over all trait types of a store (new; u8 id + 1 in a record)
 9	MaxNameLen           = 20  // trait type and tier names
10	MaxValueLen          = 32  // trait values (was 40)
11	MaxTitleLen          = 64  // artwork titles (= engine.MaxTraitLen)
12	MaxLabelLen          = 64
13	MaxStoreOnchainBytes = 4 << 20 // ~430 GNOT of deposit at 100 ugnot/B
14	MaxChunk             = 262_144 // per AppendBytes call; a tx carries ~540 KB raw (WP0)
15	SegmentBytes         = 32_768  // byte-log value size (~6% key overhead, measured)
16	MaxBatch             = 100     // records per AddArtworks
17	MaxPage              = 20      // Artworks page (was 50)
18)
source

Limits (design §4 as amended by §0a / D4, and by the UP-M1 review fix: every read of the largest store these limits allow must stay far below the 3B query gas cap; worst cases are locked by zz_worst_gas_test.gno in r/reader).

Functions 19

func AddArtworks

crossing Action
1func AddArtworks(cur realm, storeID, batch string) string
source

AddArtworks declares up to MaxBatch artworks, one per '\n'-separated line:

Example
1kind|mime|size|sha256|cid|editions|tier|title|v1|…|vN

with exactly one value per trait type of the store (N = len(traitTypes)):

  • kind "chain" | "ipfs"; mime "svg" | "png" | "webp" | "jpeg";
  • size: decimal bytes, chain svg <= 16,384, chain raster <= 262,144, ipfs raw <= 1 MiB, ipfs dag-pb <= 50 MiB; the store's on-chain total stays <= 4 MiB;
  • sha256: 64 lower-case hex of the file bytes, unique in the store (use editions for copies);
  • cid: "" for chain; for ipfs a CIDv1 (media.ParseCIDv1): raw codec ⇒ its digest must equal sha256 (verified binding), dag-pb ⇒ digest stored;
  • editions 1..10,000 (the store's slots stay <= 10,000);
  • tier "" or one of the store's tiers; title <= 64 bytes;
  • values "" (none) or <= 32 bytes, no leading/trailing space; at most 100 distinct values per trait type and 255 over all types of a store.

Returns "first-last" (0-based indexes). Event ArtworkAdded per line.

func AppendBytes

crossing Action
1func AppendBytes(cur realm, storeID string, idx, offset int64, chunk []byte)
source

AppendBytes stores the next chunk of an on-chain artwork. Bytes arrive in artwork order: idx must be the lowest incomplete on-chain artwork and offset its Have (resume = read Have). chunk is a []byte argument (the keeper decodes the MsgCall's base64 natively, WP0), 1..MaxChunk bytes. When the artwork is complete its sha256 must equal the declared one and media.CheckImage must pass, else the call panics and nothing is stored. Event ArtworkComplete{store, idx}.

func ArtworkAt

Action
1func ArtworkAt(storeID string, idx int64) media.Artwork
source

ArtworkAt is the typed artwork record (a copy).

func ArtworkBytes

Action
1func ArtworkBytes(storeID string, idx int64) string
source

ArtworkBytes is the raw file of a complete on-chain artwork, "" for an incomplete or IPFS one. Only complete files passed sha256 + CheckImage.

func ArtworkDataURI

Action
1func ArtworkDataURI(storeID string, idx int64) string
source

ArtworkDataURI is "data:<mime>;base64,…" for a complete on-chain artwork, "" otherwise. mime is one of the four checked types (ENG-I3: no free-form media type ever reaches a data URI).

func ArtworkJSON

Action
1func ArtworkJSON(storeID string, idx int64) string
source

ArtworkJSON is the JSON object of one artwork (also used by the upload engine's reads so both realms emit one shape).

func ArtworkMeta

Action
1func ArtworkMeta(storeID string, idx int64) media.Artwork
source

ArtworkMeta is ArtworkAt without SHA256, Digest and CID (left ""): the cheap form for trait reads (a CID costs ~1.4M gas to encode in the VM).

func Artworks

Action
1func Artworks(storeID string, offset, limit int64) string
source

Artworks is one page of records as JSON (limit <= MaxPage = 20): [{index, kind, mime, mimeType, size, have, complete, editions, slotStart, slotEnd, sha256, digest, cid, title, tier, traits:[{trait_type,value}]}]. kind is "chain" | "ipfs"; digest is the dag-pb root ("" otherwise); cid is "" for on-chain artworks. Built from parts escaped once at write time (type names, tiers, trait values) and joined once (UP-M1).

func Composition

Action
1func Composition(storeID string) string
source

Composition is the set composition (design §8, D8 "drop table") as JSON: {store, sealed, artworks, slots,

Example
1tiers:[{name, artworks, slots}] (low -> high), untiered:{artworks, slots},
2traits:[{trait_type, values:[{value, artworks, slots}], none:{artworks, slots}}]}.

"slots" counts editions, i.e. the odds of a token: slots/total slots. O(tiers + distinct values): the counters are kept by AddArtworks / Truncate and the names are escaped once, so the largest store the limits allow stays far below the query gas cap (UP-M1).

func CountsJSON

Action
1func CountsJSON(storeID string, idx, edition []int64) string
source

CountsJSON aggregates the real-name trait counts of a set of tokens, given each token's artwork index and edition (from SlotArtwork), as the members of a JSON object: "Tier":{tier:n}, then each creator trait type {value:n} in store order, "Edition":{"e/E":n} (artworks with E > 1) and "Storage":{"On-chain"|"IPFS":n}; types and values with no count are left out. Names are the JSON escaped once at write time, values in dictionary order (review UP-M1: no per-read escaping, integer counters only).

func Info

Action
1func Info(storeID string) media.StoreInfo
source

Info is the typed store header for other realms (a copy).

func NewStore

crossing Action
1func NewStore(cur realm, label, traitTypes, tiers string) string
source

NewStore creates an empty Draft store owned by the calling wallet. traitTypes and tiers are '|'-separated name lists ("" = none): at most 16 trait types and 8 tiers (tiers ordered low -> high), names 1..20 bytes, no ':' and no leading/trailing space, unique ignoring case; "Tier", "Edition", "Storage", "Status" and "Artwork" are reserved trait types. Returns the store id. Event StoreCreated{store, owner}.

func Render

1func Render(path string) string
source

Render stays minimal and prints no creator text; uploaded collections are browsed in the gallery realm.

func Seal

crossing Action
1func Seal(cur realm, storeID string)
source

Seal freezes a store for good. It needs at least one artwork and every on-chain artwork complete. Event StoreSealed{store, artworks, slots, onchainN, ipfsN, onchainBytes}.

func SlotArtwork

Action
1func SlotArtwork(storeID string, slot int64) (idx, edition int64)
source

SlotArtwork maps a slot (0..slots-1) to its artwork index and 1-based edition: artwork i covers [slotEnd(i-1), slotEnd(i)). O(log n).

func Store

Action
1func Store(storeID string) string
source

Store is the store header as JSON: {id, owner, label, state, createdHeight, sealedHeight, artworks, slots, onchainN, ipfsN, onchainBytes, received, complete, nextUpload, badge, traitTypes, tiers}. received = on-chain bytes stored so far; nextUpload = index of the artwork AppendBytes expects next (-1 when every on-chain artwork is complete); badge = media.Badge.

func TierSlots

Action
1func TierSlots(storeID string) (tiers []string, slots []int64, untiered int64)
source

TierSlots is the typed tier part of Composition: tier names (low -> high), the slots each holds, and the slots of untiered artworks. O(tiers).

func Truncate

crossing Action
1func Truncate(cur realm, storeID string, keep int64)
source

Truncate drops artworks keep..n-1 of a Draft store and cuts the byte log back, freeing their storage (the chain refunds the signer, i.e. the owner who paid it). Trait values first used by dropped artworks stay in the dictionary (with zero counts; they still count towards MaxStoreValues). Event StoreTruncated{store, keep}.

Dependencies

Source Files 4