I’ve added schema-embed but still can’t pass parameter on init func, following is my code
/// The parameter type for the contract function `init` and `setMetadataUrl`.
#[derive(Serialize, SchemaType, Clone)]
struct SetMetadataUrlParams {
/// The URL following the specification RFC1738.
url: String,
/// The hash of the document stored at the above URL.
hash: Option<Sha256>,
}
/// Initialize contract instance with no initial tokens.
/// Logs a `Mint` event for the single token id with no amounts.
#[init(
contract = "cis2-bridgeable",
parameter = "SetMetadataUrlParams",
event = "BridgeableEvent",
enable_logger,
crypto_primitives
)]
fn contract_init<S: HasStateApi>(
ctx: &impl HasInitContext,
state_builder: &mut StateBuilder<S>,
logger: &mut impl HasLogger,
_crypto: &impl HasCryptoPrimitives,
) -> InitResult<State<S>> {
// Get the instantiater of this contract instance.
let invoker = Address::Account(ctx.init_origin());
let params: SetMetadataUrlParams = ctx.parameter_cursor().get()?;
// Create the metadata_url
let metadata_url = MetadataUrl {
url: params.url.clone(),
hash: params.hash,
};
// Construct the initial contract state.
let mut state = State::new(state_builder, metadata_url.clone());
state.grant_role(&invoker, Roles::Admin, state_builder);
// Log event for the newly minted token.
logger.log(&BridgeableEvent::Cis2Event(Cis2Event::Mint(MintEvent {
token_id: TOKEN_ID,
amount: TOKEN_AMOUNT_ZERO,
owner: invoker,
})))?;
// Log event for where to find metadata for the token
logger.log(&BridgeableEvent::Cis2Event(Cis2Event::TokenMetadata::<
_,
ContractTokenAmount,
>(TokenMetadataEvent {
token_id: TOKEN_ID,
metadata_url,
})))?;
// Log event for the new admin.
logger.log(&BridgeableEvent::GrantRole(GrantRoleEvent {
address: invoker,
role: Roles::Admin,
}))?;
Ok(state)
}