Skip to content

Commit

Permalink
feat(law): create temporary context on instantiate
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux authored and amimart committed Mar 23, 2023
1 parent 3c9d30a commit e9de097
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions contracts/cw-law-stone/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions contracts/cw-law-stone/src/state.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit e9de097

Please sign in to comment.