Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SchemaType implementation of OnReceivingCis2DataParams<T, A, D> #426

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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