From ef8255da755362602317fe15ec28a1fafd0a6193 Mon Sep 17 00:00:00 2001 From: ccamel Date: Sat, 7 Oct 2023 10:26:26 +0200 Subject: [PATCH] feat(law-stone): implement program_code query --- contracts/okp4-law-stone/src/contract.rs | 13 +++++++++++++ contracts/okp4-law-stone/src/msg.rs | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/contracts/okp4-law-stone/src/contract.rs b/contracts/okp4-law-stone/src/contract.rs index a6af8464..ee6f363b 100644 --- a/contracts/okp4-law-stone/src/contract.rs +++ b/contracts/okp4-law-stone/src/contract.rs @@ -123,6 +123,7 @@ pub fn query(deps: Deps<'_, LogicCustomQuery>, _env: Env, msg: QueryMsg) -> StdR match msg { QueryMsg::Ask { query } => to_binary(&query::ask(deps, query)?), QueryMsg::Program => to_binary(&query::program(deps)?), + QueryMsg::ProgramCode => to_binary(&query::program_code(deps)?), } } @@ -139,6 +140,18 @@ pub mod query { Ok(program) } + pub fn program_code(deps: Deps<'_, LogicCustomQuery>) -> StdResult { + let ObjectRef { + storage_address, + object_id, + } = PROGRAM.load(deps.storage)?.law; + + deps.querier.query_wasm_smart::( + storage_address, + &StorageQuery::ObjectData { id: object_id }, + ) + } + pub fn ask(deps: Deps<'_, LogicCustomQuery>, query: String) -> StdResult { let stone = PROGRAM.load(deps.storage)?; if stone.broken { diff --git a/contracts/okp4-law-stone/src/msg.rs b/contracts/okp4-law-stone/src/msg.rs index e4c436c4..ddba3a6f 100644 --- a/contracts/okp4-law-stone/src/msg.rs +++ b/contracts/okp4-law-stone/src/msg.rs @@ -38,6 +38,11 @@ pub enum QueryMsg { /// If not broken, returns the law program location information. #[returns(ProgramResponse)] Program, + + /// # ProgramCode + /// ProgramCode returns the law program code. + #[returns(Binary)] + ProgramCode, } /// # ProgramResponse