diff --git a/concordium-cis2/src/cis2_client.rs b/concordium-cis2/src/cis2_client.rs index deae46cb..5e3bd8a9 100644 --- a/concordium-cis2/src/cis2_client.rs +++ b/concordium-cis2/src/cis2_client.rs @@ -20,39 +20,7 @@ const TRANSFER_ENTRYPOINT_NAME: EntrypointName = EntrypointName::new_unchecked(" const UPDATE_OPERATOR_ENTRYPOINT_NAME: EntrypointName = EntrypointName::new_unchecked("updateOperator"); -/// Wrapper for `Cis2Error`. This allows for various traits to be -/// implemented. -#[derive(Debug)] -pub struct Cis2ErrorWrapper(Cis2Error); - -impl From> for Cis2ErrorWrapper { - fn from(e: Cis2Error) -> Self { Cis2ErrorWrapper(e) } -} - -impl AsRef> for Cis2ErrorWrapper { - fn as_ref(&self) -> &Cis2Error { &self.0 } -} - -impl Serial for Cis2ErrorWrapper { - fn serial(&self, out: &mut W) -> Result<(), W::Err> { self.0.serial(out) } -} - -impl Deserial for Cis2ErrorWrapper { - fn deserial(source: &mut R) -> ParseResult { - let tag = source.read_u8()?; - match tag { - 0 => Ok(Cis2ErrorWrapper(Cis2Error::InvalidTokenId)), - 1 => Ok(Cis2ErrorWrapper(Cis2Error::InsufficientFunds)), - 2 => Ok(Cis2ErrorWrapper(Cis2Error::Unauthorized)), - 3 => { - let t = T::deserial(source)?; - Ok(Cis2ErrorWrapper(Cis2Error::Custom(t))) - } - _ => bail!(ParseError {}), - } - } -} -pub type InvokeContractError = CallContractError>; +pub type InvokeContractError = CallContractError>; /// Errors which can be returned by the `Cis2Client`. #[derive(Debug)] @@ -70,7 +38,7 @@ impl Serial for Cis2ClientError { fn serial(&self, out: &mut W) -> Result<(), W::Err> { match self { Cis2ClientError::InvokeContractError(e) => { - out.write_u8(3)?; + out.write_u8(2)?; match e { CallContractError::AmountTooLarge => out.write_u8(0), CallContractError::MissingAccount => out.write_u8(1), @@ -121,7 +89,7 @@ impl TryFrom> for Cis2ClientError } => Ok(Cis2ClientError::InvokeContractError(InvokeContractError::LogicReject { reason, return_value: { - let cis2_error = Cis2ErrorWrapper::::deserial(&mut return_value); + let cis2_error = Cis2Error::::deserial(&mut return_value); match cis2_error { Ok(cis2_error) => cis2_error, Err(_) => bail!(Cis2ClientError::ParseResult), @@ -294,8 +262,9 @@ impl Cis2Client { /// Calls the `transfer` entrypoint of the CIS2 contract to transfer the /// given amount of tokens from the given owner to the given receiver. - /// If the transfer is successful, it returns `Ok(())`, else it returns an - /// `Err`. + /// If the transfer is successful and the state is modified, it returns + /// `Ok(true)`, else it returns `Ok(false)`. If there is an error, it + /// returns `Err`. /// /// # Examples /// ```rust @@ -332,8 +301,10 @@ impl Cis2Client { } /// Calls the `updateOperator` of the CIS2 contract. - /// If the update is successful, it returns `Ok(())`, else it returns an - /// `Err`. # Examples + /// If the update is successful and the state is modified, it returns `Ok(true)`, else it returns `Ok(false)`. + /// If there is an error, it returns `Err`. + /// + /// # Examples /// ```rust /// use concordium_cis2::{cis2_client::*, *}; /// use concordium_std::{test_infrastructure::*, *}; diff --git a/concordium-cis2/src/lib.rs b/concordium-cis2/src/lib.rs index a3127b8f..530a1f39 100644 --- a/concordium-cis2/src/lib.rs +++ b/concordium-cis2/src/lib.rs @@ -865,7 +865,7 @@ impl schema::SchemaType for Cis2Event { } /// The different errors the contract can produce. -#[derive(Debug, PartialEq, Eq, SchemaType, Serial)] +#[derive(Debug, PartialEq, Eq, SchemaType, Serial, Deserial)] pub enum Cis2Error { /// Invalid token id (Error code: -42000001). InvalidTokenId,