Skip to content

Commit

Permalink
add optional post_init_data to set in result in InstantiateMsg
Browse files Browse the repository at this point in the history
a hack to workaround scrtlabs/SecretNetwork#1323

Useful when you want to instantiate this contract and return data back to the calling contract that is available in the Reply
  • Loading branch information
luca992 committed Oct 26, 2023
1 parent 9d131b4 commit f6938b4
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ pub fn instantiate(
} else {
Vec::new()
};
Ok(Response::new().add_messages(messages))
let res = Response::new().add_messages(messages);
if let Some(some_post_init_data) = msg.post_init_data {
Ok(res.set_data(some_post_init_data))
} else {
Ok(res)
}
}

///////////////////////////////////// Handle //////////////////////////////////////
Expand Down
3 changes: 3 additions & 0 deletions src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ pub struct InstantiateMsg {
/// contract that instantiated it, but it could be used to execute any
/// contract
pub post_init_callback: Option<PostInstantiateCallback>,
/// optional data to set in result
/// a hack to workaround https://github.com/scrtlabs/SecretNetwork/issues/1323
pub post_init_data: Option<Binary>,
}

/// This type represents optional configuration values.
Expand Down
3 changes: 3 additions & 0 deletions src/unittest_handles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ mod tests {
royalty_info: None,
config: None,
post_init_callback: None,
post_init_data: None,
};

(instantiate(deps.as_mut(), env, info, init_msg), deps)
Expand Down Expand Up @@ -96,6 +97,7 @@ mod tests {
royalty_info: None,
config: Some(init_config),
post_init_callback: None,
post_init_data: None,
};

(instantiate(deps.as_mut(), env, info, init_msg), deps)
Expand Down Expand Up @@ -183,6 +185,7 @@ mod tests {
royalty_info: None,
config: None,
post_init_callback,
post_init_data: None,
};

let init_response = instantiate(deps.as_mut(), env, info, init_msg).unwrap();
Expand Down
1 change: 1 addition & 0 deletions src/unittest_mint_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mod tests {
royalty_info: None,
config: None,
post_init_callback: None,
post_init_data: None,
};

(instantiate(deps.as_mut(), env, info, init_msg), deps)
Expand Down
4 changes: 4 additions & 0 deletions src/unittest_non_transferable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ mod tests {
royalty_info: None,
config: None,
post_init_callback: None,
post_init_data: None,
};

(instantiate(deps.as_mut(), env, info, init_msg), deps)
Expand Down Expand Up @@ -89,6 +90,7 @@ mod tests {
royalty_info: None,
config: Some(init_config),
post_init_callback: None,
post_init_data: None,
};

(instantiate(deps.as_mut(), env, info, init_msg), deps)
Expand Down Expand Up @@ -140,6 +142,7 @@ mod tests {
royalty_info,
config: Some(init_config),
post_init_callback: None,
post_init_data: None,
};

(instantiate(deps.as_mut(), env, info, init_msg), deps)
Expand Down Expand Up @@ -220,6 +223,7 @@ mod tests {
royalty_info: None,
config: None,
post_init_callback,
post_init_data: None,
};

let init_response = instantiate(deps.as_mut(), env, info, init_msg).unwrap();
Expand Down
2 changes: 2 additions & 0 deletions src/unittest_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ mod tests {
royalty_info: None,
config: None,
post_init_callback: None,
post_init_data: None,
};

(instantiate(deps.as_mut(), env, info, init_msg), deps)
Expand Down Expand Up @@ -83,6 +84,7 @@ mod tests {
royalty_info: None,
config: Some(init_config),
post_init_callback: None,
post_init_data: None,
};

(instantiate(deps.as_mut(), env, info, init_msg), deps)
Expand Down
3 changes: 3 additions & 0 deletions src/unittest_royalties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ mod tests {
royalty_info,
config: None,
post_init_callback: None,
post_init_data: None,
};

(instantiate(deps.as_mut(), env, info, init_msg), deps)
Expand Down Expand Up @@ -86,6 +87,7 @@ mod tests {
royalty_info,
config: Some(init_config),
post_init_callback: None,
post_init_data: None,
};

(instantiate(deps.as_mut(), env, info, init_msg), deps)
Expand Down Expand Up @@ -286,6 +288,7 @@ mod tests {
royalty_info: None,
config: None,
post_init_callback,
post_init_data: None,
};

let init_response = instantiate(deps.as_mut(), env, info, init_msg).unwrap();
Expand Down

0 comments on commit f6938b4

Please sign in to comment.