0x0::warehouse

Module representing the NFT bookkeeping Warehouse type

Warehouse is an unprotected object used to store pre-minted NFTs for later withdrawal in a Venue. Additionally, it provides two randomized withdrawal mechanisms, a pseudo-random withdrawal, or a hidden commitment scheme.

Warehouse is an unprotected type that can be constructed independently before it is merged to a Venue, allowing Warehouse to be constructed while avoiding shared consensus transactions on Listing.

Structs

warehouse::RedeemCommitment has key

Fields:

Name Type Description
id object::UID

RedeemCommitment ID

hashed_sender_commitment vector<u8>

Hashed sender commitment

Sender will have to provide the pre-hashed value to be able to use this RedeemCommitment. This value can be pseudo-random as long as it is not predictable by the validator.

contract_commitment vector<u8>

Open commitment made by validator

Used for the client to commit a pseudo-random

warehouse::Warehouse<C> has store, key

Fields:

Name Type Description
id object::UID

Warehouse ID

nfts vector<object::ID>

NFTs that are currently on sale

total_deposited u64

Warehouse object

Methods

public fun new<C>(ctx: &mut tx_context::TxContext): 
    warehouse::Warehouse<C>

Create a new Warehouse

public entry fun init_warehouse<C>(
    ctx: &mut tx_context::TxContext,
)

Creates a Warehouse and transfers to transaction sender

public entry fun deposit_nft<C>(
    warehouse: &mut warehouse::Warehouse<C>,
    nft: nft::Nft<C>,
)

Deposits NFT to Warehouse

Endpoint is unprotected and relies on safely obtaining a mutable reference to Warehouse.

public fun redeem_nft<C>(
    warehouse: &mut warehouse::Warehouse<C>,
): nft::Nft<C>

Redeems NFT from Warehouse

Endpoint is unprotected and relies on safely obtaining a mutable reference to Warehouse.

Warehouse may not change the logical owner of an Nft when redeeming as this would allow royalties to be trivially bypassed.

Panics

Panics if Warehouse is empty.

public entry fun redeem_nft_and_transfer<C>(
    warehouse: &mut warehouse::Warehouse<C>,
    ctx: &mut tx_context::TxContext,
)

Redeems NFT from Warehouse and transfers to sender

See redeem_nft for more details.

Usage

Entry mint functions like suimarines::mint_nft take an Warehouse object to deposit into. Calling redeem_nft_and_transfer allows one to withdraw an NFT and own it directly.

Panics

Panics if Warehouse is empty.

public fun redeem_nft_at_index<C>(
    warehouse: &mut warehouse::Warehouse<C>,
    index: u64,
): nft::Nft<C>

Redeems NFT from specific index in Warehouse

Does not retain original order of NFTs in the bookkeeping vector.

Endpoint is unprotected and relies on safely obtaining a mutable reference to Warehouse.

Warehouse may not change the logical owner of an Nft when redeeming as this would allow royalties to be trivially bypassed.

Panics

Panics if index does not exist in Warehouse.

public entry fun redeem_nft_at_index_and_transfer<C>(
    warehouse: &mut warehouse::Warehouse<C>,
    index: u64,
    ctx: &mut tx_context::TxContext,
)

Redeems NFT from specific index in Warehouse and transfers to sender

See redeem_nft_at_index for more details.

Panics

Panics if index does not exist in Warehouse.

public fun redeem_pseudorandom_nft<C>(
    warehouse: &mut warehouse::Warehouse<C>,
    ctx: &mut tx_context::TxContext,
): nft::Nft<C>

Pseudo-randomly redeems NFT from Warehouse

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 Warehouse.

Warehouse may not change the logical owner of an Nft when redeeming as this would allow royalties to be trivially bypassed.

Panics

Panics if Warehouse is empty

public entry fun redeem_pseudorandom_nft_and_transfer<C>(
    warehouse: &mut warehouse::Warehouse<C>,
    ctx: &mut tx_context::TxContext,
)

Pseudo-randomly redeems specific NFT from Warehouse and transfers to sender

See redeem_pseudorandom_nft for more details.

Usage

Entry mint functions like suimarines::mint_nft take an Warehouse object to deposit into. Calling redeem_nft_and_transfer allows one to withdraw an NFT and own it directly.

public fun new_redeem_commitment(
    hashed_sender_commitment: vector<u8>,
    ctx: &mut tx_context::TxContext,
): warehouse::RedeemCommitment

Create a new RedeemCommitment

Contract commitment must be unfeasible to predict by the transaction sender. The underlying value of the commitment can be pseudo-random as long as it is not predictable by the validator.

Panics

Panics if commitment is not 32 bytes.

public entry fun init_redeem_commitment(
    hashed_sender_commitment: vector<u8>,
    ctx: &mut tx_context::TxContext,
)

Creates a new RedeemCommitment and transfers it to the transaction caller.

Contract commitment must be unfeasible to predict by the transaction caller. The underlying value of the commitment can be pseudo-random as long as it is not predictable by the validator.

Panics

Panics if commitment is not 32 bytes.

public fun redeem_random_nft<C>(
    warehouse: &mut warehouse::Warehouse<C>,
    commitment: warehouse::RedeemCommitment,
    user_commitment: vector<u8>,
    ctx: &mut tx_context::TxContext,
): nft::Nft<C>

Randomly redeems NFT from Warehouse

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 init_redeem_commitment.

Endpoint is unprotected and relies on safely obtaining a mutable reference to Warehouse.

Warehouse may not change the logical owner of an Nft when redeeming as this would allow royalties to be trivially bypassed.

Panics

Panics if Warehouse is empty or user_commitment does not match the hashed commitment in RedeemCommitment.

public entry fun redeem_random_nft_and_transfer<C>(
    warehouse: &mut warehouse::Warehouse<C>,
    commitment: warehouse::RedeemCommitment,
    user_commitment: vector<u8>,
    ctx: &mut tx_context::TxContext,
)

Randomly redeems NFT from Warehouse and transfers to sender

See redeem_random_nft for more details.

Panics

Panics if Warehouse is empty or user_commitment does not match the hashed commitment in RedeemCommitment.

public entry fun destroy<C>(
    warehouse: warehouse::Warehouse<C>,
)

Destroys Warehouse

Panics

Panics if Warehouse is not empty

public entry fun destroy_commitment(
    commitment: warehouse::RedeemCommitment,
)

Destroyes RedeemCommitment

public fun supply<C>(
    warehouse: &warehouse::Warehouse<C>,
): u64

Return how many Nft there are to sell

public fun is_empty<C>(
    warehouse: &warehouse::Warehouse<C>,
): bool

Return whether there are any Nft in the Warehouse

public fun nfts<C>(
    warehouse: &warehouse::Warehouse<C>,
): &vector<object::ID>

Returns list of all NFTs stored in Warehouse

public fun total_deposited<C>(
    warehouse: &warehouse::Warehouse<C>,
): u64

Return cumulated amount of Nfts deposited in the Warehouse

public fun total_redeemed<C>(
    warehouse: &warehouse::Warehouse<C>,
): u64

Return cumulated amount of Nfts redeemed in the Warehouse

public fun assert_is_empty<C>(
    warehouse: &warehouse::Warehouse<C>,
)

Asserts that Warehouse is empty