diff --git a/contracts/cw-law-stone/src/contract.rs b/contracts/cw-law-stone/src/contract.rs index 041a00f8..f67225f7 100644 --- a/contracts/cw-law-stone/src/contract.rs +++ b/contracts/cw-law-stone/src/contract.rs @@ -12,6 +12,7 @@ use logic_bindings::LogicCustomQuery; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; +use crate::state::INSTANTIATE_CONTEXT; // version info for migration info const CONTRACT_NAME: &str = "crates.io:law-stone"; @@ -29,16 +30,18 @@ pub fn instantiate( set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; let store_msg = StorageMsg::StoreObject { - data: msg.program, + data: msg.program.clone(), pin: true, }; let store_program_msg = WasmMsg::Execute { - contract_addr: msg.storage_address, + contract_addr: msg.storage_address.clone(), msg: to_binary(&store_msg)?, funds: vec![], }; + INSTANTIATE_CONTEXT.save(deps.storage, &(msg.storage_address, msg.program))?; + Ok(Response::new().add_submessage(SubMsg::reply_on_success( store_program_msg, STORE_PROGRAM_REPLY_ID, @@ -171,6 +174,10 @@ mod tests { }, _ => assert!(false, "cosmos sub message should be a Wasm message execute"), } + assert_eq!("okp41ffzp0xmjhwkltuxcvccl0z9tyfuu7txp5ke0tpkcjpzuq9fcj3pqrteqt3".to_string(), + INSTANTIATE_CONTEXT.load(&deps.storage).unwrap().0); + assert_eq!(program, + INSTANTIATE_CONTEXT.load(&deps.storage).unwrap().1) } struct StoreTestCase { diff --git a/contracts/cw-law-stone/src/state.rs b/contracts/cw-law-stone/src/state.rs index 119952b3..fe010465 100644 --- a/contracts/cw-law-stone/src/state.rs +++ b/contracts/cw-law-stone/src/state.rs @@ -1,8 +1,12 @@ +use cosmwasm_std::Binary; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use cw_storage_plus::{Item, Map}; +/// State to store context during contract instantiation +pub const INSTANTIATE_CONTEXT: Item<'_, (String, Binary)> = Item::new("instantiate"); + /// Represent a link to an Object stored in the `cw-storage` contract. #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] pub struct Object {