Skip to content

Commit

Permalink
Fix SchemaType implementation of `OnReceivingCis2DataParams<T, A, D…
Browse files Browse the repository at this point in the history
…>` so that it matches `Serial` and `Deserial` implementations. (#426)
  • Loading branch information
lassemoldrup committed Apr 30, 2024
1 parent b3a89f3 commit bdb9b1b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion concordium-cis2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased changes

- Bump MSRV to 1.72
- Fix `SchemaType` implementation of `OnReceivingCis2DataParams<T, A, D>` so that it matches `Serial` and `Deserial` implementations.

## concordium-cis2 6.1.0 (2024-02-22)

Expand Down Expand Up @@ -31,7 +32,7 @@
## concordium-cis2 4.0.0 (2023-06-16)

- Bump concordium-std to version 7.
p

## concordium-cis2 3.1.0 (2023-05-08)

- Derive `PartialEq` and `Eq` for the `MetadataUrl` from the CIS2 library.
Expand Down
17 changes: 15 additions & 2 deletions concordium-cis2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
mod cis2_client;
pub use cis2_client::{Cis2Client, Cis2ClientError};

use concordium_std::{collections::BTreeMap, *};
use concordium_std::{collections::BTreeMap, schema::SchemaType, *};
// Re-export for backward compatibility.
pub use concordium_std::MetadataUrl;
#[cfg(not(feature = "std"))]
Expand Down Expand Up @@ -1254,7 +1254,7 @@ pub struct OnReceivingCis2Params<T, A> {
/// with a specific type D for the AdditionalData.
// Note: For the serialization to be derived according to the CIS2
// specification, the order of the fields cannot be changed.
#[derive(Debug, SchemaType)]
#[derive(Debug)]
pub struct OnReceivingCis2DataParams<T, A, D> {
/// The ID of the token received.
pub token_id: T,
Expand Down Expand Up @@ -1292,6 +1292,19 @@ impl<T: Serial, A: Serial, D: Serial> Serial for OnReceivingCis2DataParams<T, A,
}
}

/// SchemaType trait for OnReceivingCis2DataParams<T, A, D>.
impl<T: SchemaType, A: SchemaType, D> SchemaType for OnReceivingCis2DataParams<T, A, D> {
fn get_type() -> schema::Type {
schema::Type::Struct(schema::Fields::Named(vec![
(String::from("token_id"), T::get_type()),
(String::from("amount"), A::get_type()),
(String::from("from"), Address::get_type()),
// The data field is serialized the same as AdditionalData.
(String::from("data"), AdditionalData::get_type()),
]))
}
}

/// Identifier for a smart contract standard.
/// Consists of a string of ASCII characters up to a length of 255.
///
Expand Down

0 comments on commit bdb9b1b

Please sign in to comment.