Unverified Commit 4ed39bac authored by Alexander Theißen's avatar Alexander Theißen Committed by GitHub
Browse files

Remove `DispatchRetCode` (#892)

* Remove `DispatchRetCode`

* Replace unwrap with expect
parent 35926e90
Pipeline #152844 passed with stages
in 31 minutes and 5 seconds
......@@ -95,28 +95,24 @@ impl Dispatch<'_> {
quote! {
#[cfg(not(test))]
#[no_mangle]
fn deploy() -> u32 {
::ink_lang::DispatchRetCode::from(
<#storage_ident as ::ink_lang::DispatchUsingMode>::dispatch_using_mode(
::ink_lang::DispatchMode::Instantiate,
),
fn deploy() {
<#storage_ident as ::ink_lang::DispatchUsingMode>::dispatch_using_mode(
::ink_lang::DispatchMode::Instantiate,
)
.to_u32()
.expect("failed to dispatch the constructor")
}
#[cfg(not(test))]
#[no_mangle]
fn call() -> u32 {
fn call() {
if #all_messages_deny_payment {
::ink_lang::deny_payment::<<#storage_ident as ::ink_lang::ContractEnv>::Env>()
.expect("caller transferred value even though all ink! message deny payments")
}
::ink_lang::DispatchRetCode::from(
<#storage_ident as ::ink_lang::DispatchUsingMode>::dispatch_using_mode(
::ink_lang::DispatchMode::Call,
),
<#storage_ident as ::ink_lang::DispatchUsingMode>::dispatch_using_mode(
::ink_lang::DispatchMode::Call,
)
.to_u32()
.expect("failed to dispatch the call")
}
}
}
......
......@@ -31,60 +31,3 @@ pub enum DispatchError {
CouldNotReadInput,
PaidUnpayableMessage,
}
impl DispatchError {
/// Converts `self` into an associated `u32` that FRAME contracts can handle.
#[inline]
pub fn to_u32(self) -> u32 {
DispatchRetCode::from(self).to_u32()
}
}
/// A return code indicating success or error in a compact form.
#[derive(Copy, Clone)]
#[doc(hidden)]
pub struct DispatchRetCode(u32);
impl DispatchRetCode {
/// Creates a return code indicating success.
#[inline]
pub fn success() -> Self {
Self(0)
}
/// Returns the `u32` representation of `self`.
///
/// # Note
///
/// This is useful to communicate back to FRAME contracts.
#[inline]
pub fn to_u32(self) -> u32 {
self.0
}
}
impl From<DispatchError> for DispatchRetCode {
#[inline]
fn from(err: DispatchError) -> Self {
match err {
DispatchError::UnknownSelector => Self(0x01),
DispatchError::UnknownInstantiateSelector => Self(0x02),
DispatchError::UnknownCallSelector => Self(0x03),
DispatchError::InvalidParameters => Self(0x04),
DispatchError::InvalidInstantiateParameters => Self(0x05),
DispatchError::InvalidCallParameters => Self(0x06),
DispatchError::CouldNotReadInput => Self(0x07),
DispatchError::PaidUnpayableMessage => Self(0x08),
}
}
}
impl From<DispatchResult> for DispatchRetCode {
#[inline]
fn from(res: DispatchResult) -> Self {
match res {
Ok(_) => Self::success(),
Err(err) => Self::from(err),
}
}
}
......@@ -58,7 +58,6 @@ pub use self::{
error::{
DispatchError,
DispatchResult,
DispatchRetCode,
},
events::{
BaseEvent,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment