Module containing Supply
type
Supply
tracks the supply of a given object type or an accumualtion of
actions. It tracks the current supply and guarantees that it cannot surpass
the maximum supply defined. Among others, this is used to keep track of
NFT supply for collections.
Structs
supply::Supply has drop, store
supply::Supply has drop, store
Fields:
Name | Type | Description |
---|---|---|
frozen
|
bool
|
|
max
|
u64
|
|
current
|
u64
|
Supply
tracks supply parameters
Supply
can be frozen, therefore making it impossible to change the
maximum supply.
Methods
public fun increase_maximum(
supply: &mut supply::Supply,
value: u64,
)
public fun increase_maximum(
supply: &mut supply::Supply,
value: u64,
)
Increases maximum supply
Panics
Panics if supply is frozen.
public fun decrease_maximum(
supply: &mut supply::Supply,
value: u64,
)
public fun decrease_maximum(
supply: &mut supply::Supply,
value: u64,
)
Decreases maximum supply
Panics
Panics if supply is frozen or if new maximum supply is smaller than current supply.
public fun increment(supply: &mut supply::Supply, value: u64)
public fun increment(supply: &mut supply::Supply, value: u64)
Increments current supply
Panics
Panics if new maximum supply exceeds maximum.
public fun freeze_supply(supply: &mut supply::Supply)
public fun freeze_supply(supply: &mut supply::Supply)
Freeze Supply
Panics
Panics if already frozen
public fun extend(supply: &mut supply::Supply, value: u64):
supply::Supply
public fun extend(supply: &mut supply::Supply, value: u64):
supply::Supply
Creates a new Supply
which is extended from the current Supply
The extend value is used as the maximum supply for the new Supply
,
while the current supply of the existing supply is incremented by the
value.
The existing Supply
must be frozen, thus the extended Supply
will
also be frozen.
Panics
Panics if not frozen or if value will cause maximum supply to be exceeded.
public fun merge(
supply: &mut supply::Supply,
other: supply::Supply,
)
public fun merge(
supply: &mut supply::Supply,
other: supply::Supply,
)
Merge two Supply
to one
Ideally, the merged Supply
will have been extended from the original
Supply
, as otherwise it may not be possible to merge the two
supplies.
Any excess supply on the merged Supply
will be decremented from the
original supply.
Panics
Panics if total supply will cause maximum or zero supply to be exceeded.
public fun assert_zero(supply: &supply::Supply)
public fun assert_zero(supply: &supply::Supply)
Asserts that current supply is zero
public fun assert_frozen(supply: &supply::Supply)
public fun assert_frozen(supply: &supply::Supply)
Asserts that supply is frozen
public fun assert_not_frozen(supply: &supply::Supply)
public fun assert_not_frozen(supply: &supply::Supply)
Asserts that supply is not frozen