Module of Inventory
type, a type-erased wrapper around Warehouse
and
Factory
.
Additionally, Inventory
is responsible for providing a safe interface to
change the logical owner of NFTs redeemed from it.
Structs
inventory::Inventory<C> has store, key
inventory::Inventory<C> has store, key
Fields:
Name | Type | Description |
---|---|---|
id
|
object::UID
|
|
allowlist
|
transfer_allowlist::Allowlist
|
Internal |
A type-erased wrapper around Warehouse
and Factory
Methods
public fun from_warehouse<C>(
witness: witness::Witness<C>,
warehouse: warehouse::Warehouse<C>,
ctx: &mut tx_context::TxContext,
): inventory::Inventory<C>
public fun from_warehouse<C>(
witness: witness::Witness<C>,
warehouse: warehouse::Warehouse<C>,
ctx: &mut tx_context::TxContext,
): inventory::Inventory<C>
Create a new Inventory
from a Warehouse
public fun from_factory<C>(
witness: witness::Witness<C>,
factory: factory::Factory<C>,
ctx: &mut tx_context::TxContext,
): inventory::Inventory<C>
public fun from_factory<C>(
witness: witness::Witness<C>,
factory: factory::Factory<C>,
ctx: &mut tx_context::TxContext,
): inventory::Inventory<C>
Create a new Inventory
from a Factory
public entry fun deposit_nft<C>(
inventory: &mut inventory::Inventory<C>,
nft: nft::Nft<C>,
)
public entry fun deposit_nft<C>(
inventory: &mut inventory::Inventory<C>,
nft: nft::Nft<C>,
)
Deposits NFT to Inventory
Endpoint is unprotected and relies on safely obtaining a mutable
reference to Inventory
.
Panics
Panics if Inventory
is not a Warehouse
.
public fun redeem_nft<C>(
inventory: &mut inventory::Inventory<C>,
owner: address,
ctx: &mut tx_context::TxContext,
): nft::Nft<C>
public fun redeem_nft<C>(
inventory: &mut inventory::Inventory<C>,
owner: address,
ctx: &mut tx_context::TxContext,
): nft::Nft<C>
Redeems NFT from Inventory
Endpoint is unprotected and relies on safely obtaining a mutable
reference to Inventory
.
Panics
Panics if no supply is available.
public entry fun redeem_nft_and_transfer<C>(
inventory: &mut inventory::Inventory<C>,
owner: address,
ctx: &mut tx_context::TxContext,
)
public entry fun redeem_nft_and_transfer<C>(
inventory: &mut inventory::Inventory<C>,
owner: address,
ctx: &mut tx_context::TxContext,
)
Redeems NFT from Inventory
and transfers to owner
See redeem_nft
for more details
Panics
Panics if no supply is available.
public fun redeem_pseudorandom_nft<C>(
inventory: &mut inventory::Inventory<C>,
owner: address,
ctx: &mut tx_context::TxContext,
): nft::Nft<C>
public fun redeem_pseudorandom_nft<C>(
inventory: &mut inventory::Inventory<C>,
owner: address,
ctx: &mut tx_context::TxContext,
): nft::Nft<C>
Pseudo-randomly redeems NFT from Inventory
Endpoint is susceptible to validator prediction of the resulting index,
use random_redeem_nft
instead.
Endpoint is unprotected and relies on safely obtaining a mutable
reference to Inventory
.
If the underlying Inventory
is a Factory
then logic will fallback to
using sequential withdraw.
Panics
Panics if there is no supply left.
public entry fun redeem_pseudorandom_nft_and_transfer<C>(
inventory: &mut inventory::Inventory<C>,
owner: address,
ctx: &mut tx_context::TxContext,
)
public entry fun redeem_pseudorandom_nft_and_transfer<C>(
inventory: &mut inventory::Inventory<C>,
owner: address,
ctx: &mut tx_context::TxContext,
)
Pseudo-randomly redeems NFT from Inventory
and transfers to owner
See redeem_pseudorandom_nft
for more details.
Panics
Panics if there is no supply left.
public fun redeem_random_nft<C>(
inventory: &mut inventory::Inventory<C>,
commitment: warehouse::RedeemCommitment,
user_commitment: vector<u8>,
owner: address,
ctx: &mut tx_context::TxContext,
): nft::Nft<C>
public fun redeem_random_nft<C>(
inventory: &mut inventory::Inventory<C>,
commitment: warehouse::RedeemCommitment,
user_commitment: vector<u8>,
owner: address,
ctx: &mut tx_context::TxContext,
): nft::Nft<C>
Randomly redeems NFT from Inventory
Requires a RedeemCommitment
created by the user in a separate
transaction to ensure that validators may not bias results favorably.
You can obtain a RedeemCommitment
by calling
warehouse::init_redeem_commitment
.
Endpoint is unprotected and relies on safely obtaining a mutable
reference to Inventory
.
If the underlying Inventory
is a Factory
then logic will fallback to
using sequential withdraw.
Panics
Panics if there is no supply left or user_commitment
does not match
the hashed commitment in RedeemCommitment
.
public entry fun redeem_random_nft_and_transfer<C>(
inventory: &mut inventory::Inventory<C>,
commitment: warehouse::RedeemCommitment,
user_commitment: vector<u8>,
owner: address,
ctx: &mut tx_context::TxContext,
)
public entry fun redeem_random_nft_and_transfer<C>(
inventory: &mut inventory::Inventory<C>,
commitment: warehouse::RedeemCommitment,
user_commitment: vector<u8>,
owner: address,
ctx: &mut tx_context::TxContext,
)
Randomly redeems NFT from Inventory
and transfers to owner
See redeem_random_nft
for more details.
Panics
Panics if there is no supply left or user_commitment
does not match
the hashed commitment in RedeemCommitment
.
public fun is_empty<C>(
inventory: &inventory::Inventory<C>,
): bool
public fun is_empty<C>(
inventory: &inventory::Inventory<C>,
): bool
Returns whether Inventory
has any remaining supply
public fun supply<C>(
inventory: &inventory::Inventory<C>,
): option::Option<u64>
public fun supply<C>(
inventory: &inventory::Inventory<C>,
): option::Option<u64>
Returns the available supply in Inventory
If the Inventory
is a Factory
with unregulated supply then none
will be returned.
Panics
Panics if supply was exceeded.
public fun is_warehouse<C>(
inventory: &inventory::Inventory<C>,
): bool
public fun is_warehouse<C>(
inventory: &inventory::Inventory<C>,
): bool
Returns whether Inventory
is a Warehouse
public fun is_factory<C>(
inventory: &inventory::Inventory<C>,
): bool
public fun is_factory<C>(
inventory: &inventory::Inventory<C>,
): bool
Returns whether Inventory
is a Factory
public fun borrow_warehouse<C>(
inventory: &inventory::Inventory<C>,
): &warehouse::Warehouse<C>
public fun borrow_warehouse<C>(
inventory: &inventory::Inventory<C>,
): &warehouse::Warehouse<C>
Borrows Inventory
as Warehouse
Panics
Panics if Inventory
is a Factory
public fun borrow_factory<C>(
inventory: &inventory::Inventory<C>,
): &factory::Factory<C>
public fun borrow_factory<C>(
inventory: &inventory::Inventory<C>,
): &factory::Factory<C>
Borrows Inventory
as Factory
Panics
Panics if Inventory
is a Warehouse
public fun borrow_factory_mut<C>(
inventory: &mut inventory::Inventory<C>,
): &mut factory::Factory<C>
public fun borrow_factory_mut<C>(
inventory: &mut inventory::Inventory<C>,
): &mut factory::Factory<C>
Mutably borrows Inventory
as Factory
Panics
Panics if Inventory
is a Warehouse
public fun assert_warehouse<C>(
inventory: &inventory::Inventory<C>,
)
public fun assert_warehouse<C>(
inventory: &inventory::Inventory<C>,
)
Asserts that Inventory
is a Warehouse
Panics
Panics if Inventory
is not a Warehouse
public fun assert_factory<C>(
inventory: &inventory::Inventory<C>,
)
public fun assert_factory<C>(
inventory: &inventory::Inventory<C>,
)
Asserts that Inventory
is a Factory
Panics
Panics if Inventory
is not a Factory