Skip to content

Commit

Permalink
feat(law-stone): implement program_code query
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamel committed Oct 16, 2023
1 parent 4b6aaed commit ef8255d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions contracts/okp4-law-stone/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?),
}
}

Expand All @@ -139,6 +140,18 @@ pub mod query {
Ok(program)
}

pub fn program_code(deps: Deps<'_, LogicCustomQuery>) -> StdResult<Binary> {
let ObjectRef {
storage_address,
object_id,
} = PROGRAM.load(deps.storage)?.law;

deps.querier.query_wasm_smart::<Binary>(
storage_address,
&StorageQuery::ObjectData { id: object_id },
)
}

pub fn ask(deps: Deps<'_, LogicCustomQuery>, query: String) -> StdResult<AskResponse> {
let stone = PROGRAM.load(deps.storage)?;
if stone.broken {
Expand Down
5 changes: 5 additions & 0 deletions contracts/okp4-law-stone/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ef8255d

Please sign in to comment.