@@ -320,14 +320,16 @@ pub type ContractTokenAmount = TokenAmountU64;
320
320
321
321
/// The parameter for the contract function `mint` which mints/airdrops a number
322
322
/// of tokens to the owner's address.
323
- #[ derive( Serialize , SchemaType ) ]
323
+ #[ derive( Serialize , SchemaType , Clone ) ]
324
324
pub struct MintParams {
325
325
/// Owner of the newly minted tokens.
326
- pub owner : Address ,
326
+ pub to : Receiver ,
327
327
/// The metadata_url of the token.
328
328
pub metadata_url : MetadataUrl ,
329
329
/// The token_id to mint/create additional tokens.
330
330
pub token_id : ContractTokenId ,
331
+ /// Additional data that can be sent to the receiving contract.
332
+ pub data : AdditionalData ,
331
333
}
332
334
333
335
/// The parameter for the contract function `burn` which burns a number
@@ -952,11 +954,13 @@ fn contract_view(_ctx: &ReceiveContext, host: &Host<State>) -> ReceiveResult<Vie
952
954
/// function of the state. Logs a `Mint` event.
953
955
/// The function assumes that the mint is authorized.
954
956
fn mint (
955
- params : MintParams ,
957
+ params : & MintParams ,
956
958
host : & mut Host < State > ,
957
959
logger : & mut impl HasLogger ,
958
960
) -> ContractResult < ( ) > {
959
- let is_blacklisted = host. state ( ) . blacklist . contains ( & get_canonical_address ( params. owner ) ?) ;
961
+ let to_address = params. to . address ( ) ;
962
+
963
+ let is_blacklisted = host. state ( ) . blacklist . contains ( & get_canonical_address ( to_address) ?) ;
960
964
961
965
// Check token owner is not blacklisted.
962
966
ensure ! ( !is_blacklisted, CustomContractError :: Blacklisted . into( ) ) ;
@@ -970,7 +974,7 @@ fn mint(
970
974
let token_metadata = state. mint (
971
975
& params. token_id ,
972
976
& params. metadata_url ,
973
- & params . owner ,
977
+ & to_address ,
974
978
state. mint_airdrop ,
975
979
builder,
976
980
) ;
@@ -979,7 +983,7 @@ fn mint(
979
983
logger. log ( & Cis2Event :: Mint ( MintEvent {
980
984
token_id : params. token_id ,
981
985
amount : state. mint_airdrop ,
982
- owner : params . owner ,
986
+ owner : to_address ,
983
987
} ) ) ?;
984
988
985
989
// Metadata URL for the token.
@@ -1030,7 +1034,18 @@ fn contract_mint(
1030
1034
// ensure!(host.state().has_role(&sender, Roles::MINTER),
1031
1035
// ContractError::Unauthorized);
1032
1036
1033
- mint ( params, host, logger) ?;
1037
+ mint ( & params, host, logger) ?;
1038
+
1039
+ // If the receiver is a contract: invoke the receive hook function.
1040
+ if let Receiver :: Contract ( address, function) = params. to {
1041
+ let parameter = OnReceivingCis2Params {
1042
+ token_id : params. token_id ,
1043
+ amount : host. state . mint_airdrop ,
1044
+ from : Address :: from ( address) ,
1045
+ data : params. data ,
1046
+ } ;
1047
+ host. invoke_contract ( & address, & parameter, function. as_entrypoint_name ( ) , Amount :: zero ( ) ) ?;
1048
+ }
1034
1049
1035
1050
Ok ( ( ) )
1036
1051
}
@@ -1383,7 +1398,7 @@ fn contract_permit(
1383
1398
// ContractError::Unauthorized
1384
1399
// );
1385
1400
1386
- mint ( params, host, logger) ?;
1401
+ mint ( & params, host, logger) ?;
1387
1402
}
1388
1403
BURN_ENTRYPOINT => {
1389
1404
// Burn tokens.
0 commit comments