Module sui::display
Defines a Display struct which defines the way an Object should be displayed. The intention is to keep data as independent from its display as possible, protecting the development process and keeping it separate from the ecosystem agreements.
Each of the fields of the Display object should allow for pattern substitution and filling-in the pieces using the data from the object T.
More entry functions might be added in the future depending on the use cases.
- Struct Display
- Struct DisplayCreated
- Struct VersionUpdated
- Constants
- Function new
- Function new_with_fields
- Function create_and_keep
- Function update_version
- Function add
- Function add_multiple
- Function edit
- Function remove
- Function is_authorized
- Function version
- Function fields
- Function create_internal
- Function add_internal
use std::address;
use std::ascii;
use std::bcs;
use std::option;
use std::string;
use std::type_name;
use std::vector;
use sui::accumulator;
use sui::accumulator_metadata;
use sui::accumulator_settlement;
use sui::address;
use sui::bag;
use sui::bcs;
use sui::dynamic_field;
use sui::event;
use sui::hash;
use sui::hex;
use sui::object;
use sui::package;
use sui::party;
use sui::transfer;
use sui::tx_context;
use sui::types;
use sui::vec_map;
Struct Display
The Display
Each of the display properties should support patterns outside of the system, making it simpler to customize Display based on the property values of an Object.
// Example of a display object
Display<0x...::capy::Capy> {
fields:
<name, "Capy { genes }">
<link, "https://capy.art/capy/{ id }">
<image, "https://api.capy.art/capy/{ id }/svg">
<description, "Lovely Capy, one of many">
}
Uses only String type due to external-facing nature of the object, the property names have a priority over their types.
public struct Display<phantom T: key> has key, store
Fields
-
id: sui::object::UID -
fields: sui::vec_map::VecMap<std::string::String, std::string::String> - Contains fields for display. Currently supported fields are: name, link, image and description.
-
version: u16 - Version that can only be updated manually by the Publisher.
Struct DisplayCreated
Event: emitted when a new Display object has been created for type T. Type signature of the event corresponds to the type while id serves for the discovery.
Since Sui RPC supports querying events by type, finding a Display for the T would be as simple as looking for the first event with
Display<T>.
public struct DisplayCreated<phantom T: key> has copy, drop
Fields
-
id: sui::object::ID
Struct VersionUpdated
Version of Display got updated -
public struct VersionUpdated<phantom T: key> has copy, drop
Fields
Constants
For when T does not belong to the package Publisher.
const ENotOwner: u64 = 0;
For when vectors passed into one of the multiple insert functions don't match in their lengths.
const EVecLengthMismatch: u64 = 1;
Function new
Create an empty Display object. It can either be shared empty or filled
with data right away via cheaper set_owned method.
public fun new<T: key>(pub: &sui::package::Publisher, ctx: &mut sui::tx_context::TxContext): sui::display::Display<T>
Implementation
public fun new<T: key>(pub: &Publisher, ctx: &mut TxContext): Display<T> {
assert!(is_authorized<T>(pub), ENotOwner);
create_internal(ctx)
}