Struct cw_multi_test::ContractWrapper

source ·
pub struct ContractWrapper<T1, T2, T3, E1, E2, E3, C = Empty, Q = Empty, T4 = Empty, E4 = AnyError, E5 = AnyError, T6 = Empty, E6 = AnyError>{ /* private fields */ }
Expand description

This structure wraps the Contract trait implementor and provides generic access to the contract’s entry-points.

List of generic types used in ContractWrapper:

  • T1 type of message passed to execute entry-point.
  • T2 type of message passed to instantiate entry-point.
  • T3 type of message passed to query entry-point.
  • T4 type of message passed to sudo entry-point.
  • instead of T5, always the Reply type is used in reply entry-point.
  • T6 type of message passed to migrate entry-point.
  • E1 type of error returned from execute entry-point.
  • E2 type of error returned from instantiate entry-point.
  • E3 type of error returned from query entry-point.
  • E4 type of error returned from sudo entry-point.
  • E5 type of error returned from reply entry-point.
  • E6 type of error returned from migrate entry-point.
  • C type of custom message returned from all entry-points except query.
  • Q type of custom query in Querier passed as ‘Deps’ or ‘DepsMut’ to all entry-points.

The following table summarizes the purpose of all generic types used in ContractWrapper.

┌─────────────┬────────────────┬─────────────────────┬─────────┬─────────┬───────┬───────┐
│  Contract   │    Contract    │                     │         │         │       │       │
│ entry-point │    wrapper     │    Closure type     │ Message │ Message │ Error │ Query │
│             │    member      │                     │   IN    │   OUT   │  OUT  │       │
╞═════════════╪════════════════╪═════════════════════╪═════════╪═════════╪═══════╪═══════╡
│     (1)     │                │                     │         │         │       │       │
╞═════════════╪════════════════╪═════════════════════╪═════════╪═════════╪═══════╪═══════╡
│ execute     │ execute_fn     │ ContractClosure     │   T1    │    C    │  E1   │   Q   │
├─────────────┼────────────────┼─────────────────────┼─────────┼─────────┼───────┼───────┤
│ instantiate │ instantiate_fn │ ContractClosure     │   T2    │    C    │  E2   │   Q   │
├─────────────┼────────────────┼─────────────────────┼─────────┼─────────┼───────┼───────┤
│ query       │ query_fn       │ QueryClosure        │   T3    │ Binary  │  E3   │   Q   │
├─────────────┼────────────────┼─────────────────────┼─────────┼─────────┼───────┼───────┤
│ sudo        │ sudo_fn        │ PermissionedClosure │   T4    │    C    │  E4   │   Q   │
├─────────────┼────────────────┼─────────────────────┼─────────┼─────────┼───────┼───────┤
│ reply       │ reply_fn       │ ReplyClosure        │  Reply  │    C    │  E5   │   Q   │
├─────────────┼────────────────┼─────────────────────┼─────────┼─────────┼───────┼───────┤
│ migrate     │ migrate_fn     │ PermissionedClosure │   T6    │    C    │  E6   │   Q   │
└─────────────┴────────────────┴─────────────────────┴─────────┴─────────┴───────┴───────┘

The general schema depicting which generic type is used in entry points is shown below. Entry point, when called, is provided minimum two arguments: custom query of type Q (inside Deps or DepsMut) and input message of type T1, T2, T3, T4, Reply or T6. As a result, entry point returns custom output message of type Response<C> or Binary and an error of type E1, E2, E3, E4, E5 or E6.

   entry_point(query, .., message_in) -> Result<message_out, error>
                 ┬           ┬                      ┬          ┬
            Q >──┘           │                      │          └──> E1,E2,E3,E4,E5,E6
   T1,T2,T3,T4,Reply,T6 >────┘                      └─────────────> C,Binary

Generic type C defines a custom message that is specific for the whole blockchain. Similarly, the generic type Q defines a custom query that is also specific to the whole blockchain. Other generic types are specific to the implemented contract. So all smart contracts used in the same blockchain will have the same types for C and Q, but each contract may use different type for other generic types. It means that e.g. T1 in smart contract A may differ from T1 in smart contract B.

Implementations§

source§

impl<T1, T2, T3, E1, E2, E3, C, Q> ContractWrapper<T1, T2, T3, E1, E2, E3, C, Q>
where T1: DeserializeOwned + 'static, T2: DeserializeOwned + 'static, T3: DeserializeOwned + 'static, E1: Display + Debug + Send + Sync + 'static, E2: Display + Debug + Send + Sync + 'static, E3: Display + Debug + Send + Sync + 'static, C: CustomMsg + 'static, Q: CustomQuery + DeserializeOwned + 'static,

source

pub fn new( execute_fn: fn(deps: DepsMut<'_, Q>, env: Env, info: MessageInfo, msg: T1) -> Result<Response<C>, E1>, instantiate_fn: fn(deps: DepsMut<'_, Q>, env: Env, info: MessageInfo, msg: T2) -> Result<Response<C>, E2>, query_fn: fn(deps: Deps<'_, Q>, env: Env, msg: T3) -> Result<Binary, E3> ) -> Self

Creates a new contract wrapper with default settings.

source

pub fn new_with_empty( execute_fn: fn(deps: DepsMut<'_, Empty>, env: Env, info: MessageInfo, msg: T1) -> Result<Response<Empty>, E1>, instantiate_fn: fn(deps: DepsMut<'_, Empty>, env: Env, info: MessageInfo, msg: T2) -> Result<Response<Empty>, E2>, query_fn: fn(deps: Deps<'_, Empty>, env: Env, msg: T3) -> Result<Binary, E3> ) -> Self

This will take a contract that returns Response<Empty> and will upgrade it to Response<C> if needed, to be compatible with a chain-specific extension.

source§

impl<T1, T2, T3, E1, E2, E3, C, Q, T4, E4, E5, T6, E6> ContractWrapper<T1, T2, T3, E1, E2, E3, C, Q, T4, E4, E5, T6, E6>
where T1: DeserializeOwned, T2: DeserializeOwned, T3: DeserializeOwned, T4: DeserializeOwned, T6: DeserializeOwned, E1: Display + Debug + Send + Sync, E2: Display + Debug + Send + Sync, E3: Display + Debug + Send + Sync, E4: Display + Debug + Send + Sync, E5: Display + Debug + Send + Sync, E6: Display + Debug + Send + Sync, C: CustomMsg + 'static, Q: CustomQuery + DeserializeOwned + 'static,

source

pub fn with_sudo<T4A, E4A>( self, sudo_fn: fn(deps: DepsMut<'_, Q>, env: Env, msg: T4A) -> Result<Response<C>, E4A> ) -> ContractWrapper<T1, T2, T3, E1, E2, E3, C, Q, T4A, E4A, E5, T6, E6>
where T4A: DeserializeOwned + 'static, E4A: Display + Debug + Send + Sync + 'static,

Populates ContractWrapper with contract’s sudo entry-point and custom message type.

source

pub fn with_sudo_empty<T4A, E4A>( self, sudo_fn: fn(deps: DepsMut<'_, Empty>, env: Env, msg: T4A) -> Result<Response<Empty>, E4A> ) -> ContractWrapper<T1, T2, T3, E1, E2, E3, C, Q, T4A, E4A, E5, T6, E6>
where T4A: DeserializeOwned + 'static, E4A: Display + Debug + Send + Sync + 'static,

Populates ContractWrapper with contract’s sudo entry-point and Empty as a custom message.

source

pub fn with_reply<E5A>( self, reply_fn: fn(deps: DepsMut<'_, Q>, env: Env, msg: Reply) -> Result<Response<C>, E5A> ) -> ContractWrapper<T1, T2, T3, E1, E2, E3, C, Q, T4, E4, E5A, T6, E6>
where E5A: Display + Debug + Send + Sync + 'static,

Populates ContractWrapper with contract’s reply entry-point and custom message type.

source

pub fn with_reply_empty<E5A>( self, reply_fn: fn(deps: DepsMut<'_, Empty>, env: Env, msg: Reply) -> Result<Response<Empty>, E5A> ) -> ContractWrapper<T1, T2, T3, E1, E2, E3, C, Q, T4, E4, E5A, T6, E6>
where E5A: Display + Debug + Send + Sync + 'static,

Populates ContractWrapper with contract’s reply entry-point and Empty as a custom message.

source

pub fn with_migrate<T6A, E6A>( self, migrate_fn: fn(deps: DepsMut<'_, Q>, env: Env, msg: T6A) -> Result<Response<C>, E6A> ) -> ContractWrapper<T1, T2, T3, E1, E2, E3, C, Q, T4, E4, E5, T6A, E6A>
where T6A: DeserializeOwned + 'static, E6A: Display + Debug + Send + Sync + 'static,

Populates ContractWrapper with contract’s migrate entry-point and custom message type.

source

pub fn with_migrate_empty<T6A, E6A>( self, migrate_fn: fn(deps: DepsMut<'_, Empty>, env: Env, msg: T6A) -> Result<Response<Empty>, E6A> ) -> ContractWrapper<T1, T2, T3, E1, E2, E3, C, Q, T4, E4, E5, T6A, E6A>
where T6A: DeserializeOwned + 'static, E6A: Display + Debug + Send + Sync + 'static,

Populates ContractWrapper with contract’s migrate entry-point and Empty as a custom message.

Trait Implementations§

source§

impl<T1, T2, T3, E1, E2, E3, C, T4, E4, E5, T6, E6, Q> Contract<C, Q> for ContractWrapper<T1, T2, T3, E1, E2, E3, C, Q, T4, E4, E5, T6, E6>
where T1: DeserializeOwned, T2: DeserializeOwned, T3: DeserializeOwned, T4: DeserializeOwned, T6: DeserializeOwned, E1: Display + Debug + Send + Sync + 'static, E2: Display + Debug + Send + Sync + 'static, E3: Display + Debug + Send + Sync + 'static, E4: Display + Debug + Send + Sync + 'static, E5: Display + Debug + Send + Sync + 'static, E6: Display + Debug + Send + Sync + 'static, C: CustomMsg, Q: CustomQuery + DeserializeOwned,

source§

fn execute( &self, deps: DepsMut<'_, Q>, env: Env, info: MessageInfo, msg: Vec<u8> ) -> AnyResult<Response<C>>

Calls execute on wrapped Contract trait implementor.

source§

fn instantiate( &self, deps: DepsMut<'_, Q>, env: Env, info: MessageInfo, msg: Vec<u8> ) -> AnyResult<Response<C>>

Calls instantiate on wrapped Contract trait implementor.

source§

fn query(&self, deps: Deps<'_, Q>, env: Env, msg: Vec<u8>) -> AnyResult<Binary>

Calls query on wrapped Contract trait implementor.

source§

fn sudo( &self, deps: DepsMut<'_, Q>, env: Env, msg: Vec<u8> ) -> AnyResult<Response<C>>

Calls sudo on wrapped Contract trait implementor. Returns an error when the contract does not implement sudo.

source§

fn reply( &self, deps: DepsMut<'_, Q>, env: Env, reply_data: Reply ) -> AnyResult<Response<C>>

Calls reply on wrapped Contract trait implementor. Returns an error when the contract does not implement reply.

source§

fn migrate( &self, deps: DepsMut<'_, Q>, env: Env, msg: Vec<u8> ) -> AnyResult<Response<C>>

Calls migrate on wrapped Contract trait implementor. Returns an error when the contract does not implement migrate.

Auto Trait Implementations§

§

impl<T1, T2, T3, E1, E2, E3, C, Q, T4, E4, E5, T6, E6> Freeze for ContractWrapper<T1, T2, T3, E1, E2, E3, C, Q, T4, E4, E5, T6, E6>

§

impl<T1, T2, T3, E1, E2, E3, C = Empty, Q = Empty, T4 = Empty, E4 = Error, E5 = Error, T6 = Empty, E6 = Error> !RefUnwindSafe for ContractWrapper<T1, T2, T3, E1, E2, E3, C, Q, T4, E4, E5, T6, E6>

§

impl<T1, T2, T3, E1, E2, E3, C = Empty, Q = Empty, T4 = Empty, E4 = Error, E5 = Error, T6 = Empty, E6 = Error> !Send for ContractWrapper<T1, T2, T3, E1, E2, E3, C, Q, T4, E4, E5, T6, E6>

§

impl<T1, T2, T3, E1, E2, E3, C = Empty, Q = Empty, T4 = Empty, E4 = Error, E5 = Error, T6 = Empty, E6 = Error> !Sync for ContractWrapper<T1, T2, T3, E1, E2, E3, C, Q, T4, E4, E5, T6, E6>

§

impl<T1, T2, T3, E1, E2, E3, C, Q, T4, E4, E5, T6, E6> Unpin for ContractWrapper<T1, T2, T3, E1, E2, E3, C, Q, T4, E4, E5, T6, E6>

§

impl<T1, T2, T3, E1, E2, E3, C = Empty, Q = Empty, T4 = Empty, E4 = Error, E5 = Error, T6 = Empty, E6 = Error> !UnwindSafe for ContractWrapper<T1, T2, T3, E1, E2, E3, C, Q, T4, E4, E5, T6, E6>

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<U> As for U

source§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. 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> 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
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.