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

Sponsored Transaction enabled auction #364

Merged
merged 16 commits into from
Dec 4, 2023
3 changes: 3 additions & 0 deletions concordium-cis2/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

## Unreleased changes
- Add specific parameter type `OnReceivingCis2DataParams<T, A, D>` for a contract function which receives CIS2 tokens with a specific type D for the AdditionalData.
- Add `Deserial` trait for `OnReceivingCis2DataParams<T, A, D>`.
- Add `Serial` trait for `OnReceivingCis2DataParams<T, A, D>`.

## concordium-cis2 5.1.0 (2023-10-18)

Expand Down
44 changes: 43 additions & 1 deletion concordium-cis2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ impl AsRef<[MetadataUrl]> for TokenMetadataQueryResponse {
fn as_ref(&self) -> &[MetadataUrl] { &self.0 }
}

/// The parameter type for a contract function which receives CIS2 tokens.
/// Generic parameter type for a contract function which receives CIS2 tokens.
// Note: For the serialization to be derived according to the CIS2
// specification, the order of the fields cannot be changed.
#[derive(Debug, Serialize, SchemaType)]
Expand All @@ -1250,6 +1250,48 @@ pub struct OnReceivingCis2Params<T, A> {
pub data: AdditionalData,
}

/// Specific parameter type for a contract function which receives CIS2 tokens
/// 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)]
pub struct OnReceivingCis2DataParams<T, A, D> {
/// The ID of the token received.
pub token_id: T,
/// The amount of tokens received.
pub amount: A,
/// The previous owner of the tokens.
pub from: Address,
/// Some extra information which where sent as part of the transfer.
DOBEN marked this conversation as resolved.
Show resolved Hide resolved
pub data: D,
}

/// Deserial trait for OnReceivingCis2DataParams<T, A, D>.
impl<T: Deserial, A: Deserial, D: Deserial> Deserial for OnReceivingCis2DataParams<T, A, D> {
fn deserial<R: Read>(source: &mut R) -> ParseResult<Self> {
let params: OnReceivingCis2Params<T, A> = source.get()?;
let additional_data_type: D = from_bytes(params.data.as_ref())?;
Ok(OnReceivingCis2DataParams {
token_id: params.token_id,
amount: params.amount,
from: params.from,
data: additional_data_type,
})
}
}

/// Serial trait for OnReceivingCis2DataParams<T, A, D>.
impl<T: Serial, A: Serial, D: Serial> Serial for OnReceivingCis2DataParams<T, A, D> {
fn serial<W: Write>(&self, out: &mut W) -> Result<(), W::Err> {
self.token_id.serial(out)?;
self.amount.serial(out)?;
self.from.serial(out)?;
(to_bytes(&self.data).len() as u16).serial(out)?;
out.write_all(&to_bytes(&self.data))?;
DOBEN marked this conversation as resolved.
Show resolved Hide resolved
Ok(())
}
}

/// Identifier for a smart contract standard.
/// Consists of a string of ASCII characters up to a length of 255.
///
Expand Down
26 changes: 13 additions & 13 deletions examples/cis2-multi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,34 +305,34 @@ pub struct PermitParamPartial {
pub enum CustomContractError {
/// Failed parsing the parameter.
#[from(ParseError)]
ParseParams,
ParseParams, // -1
/// Failed logging: Log is full.
LogFull,
LogFull, // -2
/// Failed logging: Log is malformed.
LogMalformed,
LogMalformed, // -3
/// Invalid contract name.
InvalidContractName,
InvalidContractName, // -4
/// Only a smart contract can call this function.
ContractOnly,
ContractOnly, // -5
/// Failed to invoke a contract.
InvokeContractError,
InvokeContractError, // -6
/// Failed to verify signature because signer account does not exist on
/// chain.
MissingAccount,
MissingAccount, // -7
/// Failed to verify signature because data was malformed.
MalformedData,
MalformedData, // -8
/// Failed signature verification: Invalid signature.
WrongSignature,
WrongSignature, // -9
/// Failed signature verification: A different nonce is expected.
NonceMismatch,
NonceMismatch, // -10
/// Failed signature verification: Signature was intended for a different
/// contract.
WrongContract,
WrongContract, // -11
/// Failed signature verification: Signature was intended for a different
/// entry_point.
WrongEntryPoint,
WrongEntryPoint, // -12
/// Failed signature verification: Signature is expired.
Expired,
Expired, // -13
}

pub type ContractError = Cis2Error<CustomContractError>;
Expand Down
3 changes: 1 addition & 2 deletions examples/cis2-multi/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,7 @@ fn initialize_chain_and_contract() -> (Chain, AccountKeys, ContractAddress) {
amount: Amount::zero(),
mod_ref: deployment.module_reference,
init_name: OwnedContractName::new_unchecked("init_cis2_multi".to_string()),
param: OwnedParameter::from_serial(&TokenAmountU64(100))
.expect("UpdateOperator params"),
param: OwnedParameter::from_serial(&TokenAmountU64(100)).expect("Init params"),
})
.expect("Initialize contract");

Expand Down
23 changes: 23 additions & 0 deletions examples/sponsored-tx-enabled-auction/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "sponsored-tx-enabled-auction"
version = "0.1.0"
authors = ["Concordium <developers@concordium.com>"]
edition = "2021"
license = "MPL-2.0"

[features]
default = ["std", "wee_alloc"]
std = ["concordium-std/std", "concordium-cis2/std"]
wee_alloc = ["concordium-std/wee_alloc"]

[dependencies]
concordium-std = {path = "../../concordium-std", default-features = false}
concordium-cis2 = {path = "../../concordium-cis2", default-features = false}

[dev-dependencies]
concordium-smart-contract-testing = { path = "../../contract-testing" }
cis2-multi = { path = "../cis2-multi/" }
rand = "0.7"

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