Skip to main content

SimpleWalletBase

Struct SimpleWalletBase 

Source
#[repr(C)]
pub struct SimpleWalletBase;
Expand description

A simple wallet contract base contract to be used by other contracts.

See the module description for details.

Implementations§

Source§

impl SimpleWalletBase

Source

pub fn initialize(public_key: &[u8; 32]) -> Result<WalletState, ContractError>

Returns initial state with a provided public key

Source

pub fn authorize( state: &WalletState, header: &TransactionHeader, read_slots: &TxHandlerSlots, write_slots: &TxHandlerSlots, payload: &TxHandlerPayload, seal: &TxHandlerSeal, ) -> Result<(), ContractError>

Reads state of owner and returns Ok(()) if authorization succeeds

Source

pub fn execute( env: &mut Env<'_>, header: &TransactionHeader, read_slots: &TxHandlerSlots, write_slots: &TxHandlerSlots, payload: &TxHandlerPayload, seal: &TxHandlerSeal, ) -> Result<(), ContractError>

Executes provided transactions in the payload.

IMPORTANT:

  • must only be called with trusted input, for example, successful signature verification in SimpleWalletBase::authorize() implies transaction was seen and verified by the user
  • remember to also SimpleWalletBase::increase_nonce() afterward unless there is a very good reason not to (like when wallet was replaced with another implementation containing a different state)

The caller must set themselves as a context or else error will be returned.

Source

pub fn increase_nonce(state: &WalletState) -> Result<WalletState, ContractError>

Returns state with increased nonce

Source

pub fn change_public_key( state: &WalletState, public_key: &[u8; 32], ) -> Result<WalletState, ContractError>

Returns a new state with a changed public key

Trait Implementations§

Source§

impl Clone for SimpleWalletBase

Source§

fn clone(&self) -> SimpleWalletBase

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Contract for SimpleWalletBase

Source§

const MAIN_CONTRACT_METADATA: &[u8]

Main contract metadata, see ContractMetadataKind for encoding details. Read more
Source§

type Slot = ()

Slot type used by this contract
Source§

type Tmp = ()

Tmp type used by this contract
Source§

fn code() -> impl Deref<Target = VariableBytes<{ ::ab_contracts_macros::__private::MAX_CODE_SIZE }>>

Something that can be used as “code” in native execution environment and primarily used for testing. Read more
Source§

impl Copy for SimpleWalletBase

Source§

impl Debug for SimpleWalletBase

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl TrivialType for SimpleWalletBase

Source§

const METADATA: &[u8]

Data structure metadata in binary form, describing shape and types of the contents, see [IoTypeMetadataKind] for encoding details.
§

const SIZE: u32 = _

§

unsafe fn read_unaligned(bytes: &[u8]) -> Option<Self>

Read unaligned value from memory. Read more
§

unsafe fn read_unaligned_unchecked(bytes: &[u8]) -> Self

Similar to [Self::read_unaligned()], but doesn’t do any checks at all. Read more
§

unsafe fn from_bytes(bytes: &[u8]) -> Option<&Self>

Create a reference to a type, which is represented by provided memory. Read more
§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> &Self

Similar to [Self::from_bytes()], but doesn’t do any checks at all. Read more
§

unsafe fn from_bytes_mut(bytes: &mut [u8]) -> Option<&mut Self>

Create a mutable reference to a type, which is represented by provided memory. Read more
§

unsafe fn from_bytes_mut_unchecked(bytes: &mut [u8]) -> &mut Self

Similar to [Self::from_bytes_mut()], but doesn’t do any checks at all. Read more
§

fn as_bytes(&self) -> &[u8; ab_io_type::trivial_type::SIZE_OF::<Self>]

Access the underlying byte representation of a data structure
§

unsafe fn as_bytes_mut( &mut self, ) -> &mut [u8; ab_io_type::trivial_type::SIZE_OF::<Self>]

Access the underlying mutable byte representation of a data structure. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> IoType for T
where T: TrivialType,

§

const METADATA: &'static [u8] = T::METADATA

Data structure metadata in binary form, describing shape and types of the contents, see IoTypeMetadataKind for encoding details
§

type PointerType = T

Pointer with a trivial type that this IoType represents
§

fn size(&self) -> u32

Number of bytes that are currently used to store data
§

fn capacity(&self) -> u32

Number of bytes are allocated right now
§

unsafe fn set_size(&mut self, size: u32)

Set the number of used bytes Read more
§

unsafe fn from_ptr<'a>( ptr: &'a NonNull<<T as IoType>::PointerType>, size: &'a u32, capacity: u32, ) -> impl Deref<Target = T> + 'a

Create a reference to a type, which is represented by provided memory. Read more
§

unsafe fn from_mut_ptr<'a>( ptr: &'a mut NonNull<<T as IoType>::PointerType>, _size: &'a mut u32, capacity: u32, ) -> impl DerefMut + 'a

Create a mutable reference to a type, which is represented by provided memory. Read more
§

unsafe fn as_ptr( &self, ) -> impl Deref<Target = NonNull<<T as IoType>::PointerType>>

Get a raw pointer to the underlying data with no checks. Read more
§

unsafe fn as_mut_ptr(&mut self) -> impl DerefMut

Get an exclusive raw pointer to the underlying data with no checks. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.