Skip to content

Commit

Permalink
Derive serde for params of transfer/withdraw/deposit functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lassemoldrup committed May 7, 2024
1 parent 0f653ad commit 24e5618
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion concordium-rust-sdk
24 changes: 17 additions & 7 deletions examples/cis5-smart-contract-wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,30 @@ license = "MPL-2.0"
default = ["std", "bump_alloc"]
std = ["concordium-std/std", "concordium-cis2/std"]
bump_alloc = ["concordium-std/bump_alloc"]
serde = [
"concordium-contracts-common/derive-serde",
"concordium-cis2/serde",
"dep:serde",
]

[dependencies]
concordium-std = {path = "../../concordium-std", default-features = false}
concordium-cis2 = {path = "../../concordium-cis2", default-features = false, features=[
"u256_amount"]}
concordium-std = { path = "../../concordium-std", default-features = false }
concordium-cis2 = { path = "../../concordium-cis2", default-features = false, features = [
"u256_amount",
] }
serde = { version = "1.0", optional = true, default-features = false, features = [
"derive",
] }
concordium-contracts-common = "*"

[dev-dependencies]
concordium-smart-contract-testing = {path = "../../contract-testing"}
cis2-multi = {path = "../cis2-multi"}
ed25519-dalek = { version = "2.0", features = ["rand_core"] }
concordium-smart-contract-testing = { path = "../../contract-testing" }
cis2-multi = { path = "../cis2-multi" }
ed25519-dalek = { version = "2.0", features = ["rand_core"] }
rand = "0.8"

[lib]
crate-type=["cdylib", "rlib"]
crate-type = ["cdylib", "rlib"]

[profile.release]
codegen-units = 1
Expand Down
10 changes: 10 additions & 0 deletions examples/cis5-smart-contract-wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
//! (third-party) to do so.
use concordium_cis2::{self as cis2, *};
use concordium_std::*;
#[cfg(feature = "serde")]
use serde::{Deserialize as SerdeDeserialize, Serialize as SerdeSerialize};

// The testnet genesis hash is:
// 0x4221332d34e1694168c2a0c0b3fd0f273809612cb13d000d5c2e00e85f50f796
Expand Down Expand Up @@ -533,6 +535,7 @@ pub struct TokenAmount {

/// A single withdrawal of CCD or some amount of tokens.
#[derive(Serialize, Clone, SchemaType)]
#[cfg_attr(feature = "serde", derive(SerdeSerialize, SerdeDeserialize))]
pub struct Withdraw<T: SigningAmount> {
/// The address receiving the CCD or tokens being withdrawn.
pub to: Receiver,
Expand All @@ -544,6 +547,7 @@ pub struct Withdraw<T: SigningAmount> {

/// The withdraw message that is signed by the signer.
#[derive(Serialize, Clone, SchemaType)]
#[cfg_attr(feature = "serde", derive(SerdeSerialize, SerdeDeserialize))]
pub struct WithdrawMessage<T: SigningAmount> {
/// The entry_point that the signature is intended for.
pub entry_point: OwnedEntrypointName,
Expand All @@ -568,6 +572,7 @@ impl<T: SigningAmount> IsMessage for WithdrawMessage<T> {

/// A batch of withdrawals signed by a signer.
#[derive(Serialize, SchemaType)]
#[cfg_attr(feature = "serde", derive(SerdeSerialize, SerdeDeserialize))]
pub struct WithdrawBatch<T: SigningAmount> {
/// The signer public key.
pub signer: PublicKeyEd25519,
Expand All @@ -580,6 +585,7 @@ pub struct WithdrawBatch<T: SigningAmount> {
/// The parameter type for the contract functions
/// `withdrawCcd/withdrawCis2Tokens`.
#[derive(Serialize, SchemaType)]
#[cfg_attr(feature = "serde", derive(SerdeSerialize, SerdeDeserialize))]
#[concordium(transparent)]
#[repr(transparent)]
pub struct WithdrawParameter<T: SigningAmount> {
Expand Down Expand Up @@ -950,6 +956,7 @@ fn withdraw_cis2_tokens(

/// A single transfer of CCD or some amount of tokens.
#[derive(Serialize, Clone, SchemaType)]
#[cfg_attr(feature = "serde", derive(SerdeSerialize, SerdeDeserialize))]
pub struct Transfer<T: SigningAmount> {
/// The public key receiving the tokens being transferred.
pub to: PublicKeyEd25519,
Expand All @@ -959,6 +966,7 @@ pub struct Transfer<T: SigningAmount> {

/// The transfer message that is signed by the signer.
#[derive(Serialize, Clone, SchemaType)]
#[cfg_attr(feature = "serde", derive(SerdeSerialize, SerdeDeserialize))]
pub struct TransferMessage<T: SigningAmount> {
/// The entry_point that the signature is intended for.
pub entry_point: OwnedEntrypointName,
Expand All @@ -983,6 +991,7 @@ impl<T: SigningAmount> IsMessage for TransferMessage<T> {

/// A batch of transfers signed by a signer.
#[derive(Serialize, SchemaType)]
#[cfg_attr(feature = "serde", derive(SerdeSerialize, SerdeDeserialize))]
pub struct TransferBatch<T: SigningAmount> {
/// The signer public key.
pub signer: PublicKeyEd25519,
Expand All @@ -995,6 +1004,7 @@ pub struct TransferBatch<T: SigningAmount> {
/// The parameter type for the contract functions
/// `transferCcd/transferCis2Tokens`.
#[derive(Serialize, SchemaType)]
#[cfg_attr(feature = "serde", derive(SerdeSerialize, SerdeDeserialize))]
#[concordium(transparent)]
#[repr(transparent)]
pub struct TransferParameter<T: SigningAmount> {
Expand Down

0 comments on commit 24e5618

Please sign in to comment.