pub use crate::traits::errors::{
PSP34Error,
PSP34ReceiverError,
};
use brush::traits::{
AccountId,
Balance,
};
use ink_prelude::vec::Vec;
use ink_primitives::Key;
#[cfg(feature = "std")]
use ink_storage::traits::StorageLayout;
use ink_storage::traits::{
ExtKeyPtr,
KeyPtr,
PackedAllocate,
PackedLayout,
SpreadAllocate,
SpreadLayout,
};
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, scale::Encode, scale::Decode, SpreadLayout, PackedLayout)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo, StorageLayout))]
pub enum Id {
U8(u8),
U16(u16),
U32(u32),
U64(u64),
U128(u128),
Bytes(Vec<u8>),
}
impl SpreadAllocate for Id {
fn allocate_spread(ptr: &mut KeyPtr) -> Self {
ptr.next_for::<Id>();
Id::U8(0)
}
}
impl PackedAllocate for Id {
#[inline]
fn allocate_packed(&mut self, _at: &Key) {}
}
#[brush::wrapper]
pub type PSP34Ref = dyn PSP34;
#[brush::trait_definition]
pub trait PSP34 {
#[ink(message)]
fn collection_id(&self) -> Id;
#[ink(message)]
fn balance_of(&self, owner: AccountId) -> u32;
#[ink(message)]
fn owner_of(&self, id: Id) -> Option<AccountId>;
#[ink(message)]
fn allowance(&self, owner: AccountId, operator: AccountId, id: Option<Id>) -> bool;
#[ink(message)]
fn approve(&mut self, operator: AccountId, id: Option<Id>, approved: bool) -> Result<(), PSP34Error>;
#[ink(message)]
fn transfer(&mut self, to: AccountId, id: Id, data: Vec<u8>) -> Result<(), PSP34Error>;
#[ink(message)]
fn total_supply(&self) -> Balance;
}
#[brush::wrapper]
pub type PSP34ReceiverRef = dyn PSP34Receiver;
#[brush::trait_definition]
pub trait PSP34Receiver {
#[ink(message)]
fn before_received(
&mut self,
operator: AccountId,
from: AccountId,
id: Id,
data: Vec<u8>,
) -> Result<(), PSP34ReceiverError>;
}