Dear, everyone.
I am developing contract on Concordium now.
But I faced issues when update state.
this is code.
pub type ContractTokenId = TokenIdU32;
#[derive(SchemaType, Clone, Serialize, PartialEq, Eq, Debug)]
struct TokenInfo {
pub id: ContractTokenId,
pub address: ContractAddress,
}
impl TokenInfo {
fn new(id: ContractTokenId, address: ContractAddress) -> Self {
TokenInfo { id, address }
}
}
#[derive(SchemaType, Clone, Serialize, Copy, PartialEq, Eq, Debug)]
enum TokenListState {
UnListed,
Listed(Amount),
}
#[derive(SchemaType, Clone, Serialize, Copy, PartialEq, Eq, Debug)]
enum TokenSaleTypeState {
Fixed,
Auction,
}
#[derive(SchemaType, Clone, Serialize, Copy, PartialEq, Eq, Debug)]
struct TokenState {
sale_type: TokenSaleTypeState,
curr_state: TokenListState,
owner: AccountAddress,
expiry: u64,
highest_bidder: AccountAddress,
}
#[derive(Serial, DeserialWithState, StateClone)]
#[concordium(state_parameter = “S”)]
struct State
{
tokens: StateMap<TokenInfo, TokenState, S>,
}
#[receive(
contract = "Market-NFT",
name = "add",
parameter = "AddParams",
mutable
)]
fn add<S: HasStateApi>(
ctx: &impl HasReceiveContext,
host: &mut impl HasHost<State<S>, StateApiType = S>,
) → ContractResult<()> {
let params: AddParams = ctx
.parameter_cursor()
.get()
.map_err(|_e| MarketplaceError::ParseParams)?;
let info = TokenInfo::new(params.token_id, params.nft_contract_address);
if host.state_mut().tokens.get(&info).is_some() {
let token_state = host.state().tokens.get(&info).unwrap();
token_state.highest_bidder = AccountAddress([0u8; 32]);
}
ContractResult::Ok(())
}
When call add function, i want to update token_state(type: TokenState).
But I can’t update.
what is the reason?
Hope your help.
Sincerely.
Kind regards.