I had my cis2 transfer hook implemented like this
/// onReceivingCIS2 hook supplied when making transfers to the contract
#[receive(contract = "game_room", name = "onReceivingCIS2", error = "Error")]
fn process_cis2_deposit<S: HasStateApi>(
_ctx: &impl HasReceiveContext,
_host: &impl HasHost<State, StateApiType = S>,
) -> ReceiveResult<()> {
Ok(())
}
I want to adjust my smart contract logic to add users to the game room participants (a set in state), when they make a cis2 transfer to my smart contract. However there might be other reasons for which my smart contract might receive a transfer, so I only want to enroll the transfer sender to game room if they indicate interest by passing a “should_enroll” : true in the data field being sent with the transfer.
I have now updated my “onReceivingCIS2” to look like this
/// The `additionData` that has to be passed to the `onReceivingCIS2` entry point.
#[derive(Serialize, SchemaType)]
pub struct AdditionalDataParams {
pub should_enroll: bool,
}
/// Hook called when smart contract receives a cis2 token transfer
/// Attempts to add person who made the transfer to the game room
/// If the person has indicated interest by
#[receive(
contract = "first_game_room",
name = "onReceivingCIS2",
mutable,
parameter = "OnReceivingCis2DataParams<ContractTokenId, ContractTokenAmount, AdditionalDataParams>",
error = "Error",
enable_logger
)]
fn process_cis2_deposit(
ctx: &impl HasReceiveContext,
host: &mut Host<State>,
logger: &mut impl HasLogger,
) -> Result<(), Error> {
// Ensure the sender is the cis2 token contract.
ensure!(
ctx.sender().matches_contract(&host.state().cis2_contract),
Error::NotTokenContract
);
// Getting input parameters.
let params: OnReceivingCis2DataParams<
ContractTokenId,
ContractTokenAmount,
AdditionalDataParams,
>= ctx.parameter_cursor().get()?;
if params.data.should_enroll {
// ... Logic for adding to game room
}
Ok(())
}
My json parameter file look like this
[{
"amount": "200",
"data": [
123, 34, 115, 104, 111, 117,
108, 100, 95, 101, 110, 114,
111, 108, 108, 34, 58, 116,
114, 117, 101, 125
],
"from": {
"Account": ["4ezLXX1oNXdZ5M8msooxoKhyPheKRuyiZ7ZfuYPpedi2MSicsq"]
},
"to": {
"Contract": [
{
"index": 8663,
"subindex": 0
},
"onReceivingCIS2"
]
},
"token_id": ""
}]
for the data I took an object { “should_enroll”: true} and converted it to hex, then to bytes.
when I invoke the euroeE contract using the following command
concordium-client contract invoke 7260 --entrypoint transfer --parameter-json parameters/fund.json --invoker-account jerry-ccd-wallet-testnet.json --energy 60000 --grpc-port 20001
I get back an InvokeContractError
(-6). I have tried debugging the issue with my update and haven’t been able to spot the problem. Once I remove the AdditionalDataParams i.e revert back to my initial “onReceivingCIS2” everything works well. please any idea on what I’m doing wrong?