Skip to content

Commit

Permalink
chore: Add replier contract to CI and apply review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kulikthebird committed Dec 17, 2024
1 parent c99e48c commit 24c6561
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
29 changes: 29 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ workflows:
- contract_crypto_verify
- contract_cyberpunk
- contract_empty
- contract_replier
# - contract_floaty # This contract needs nightly Rust to compile
- contract_hackatom
- contract_ibc_callbacks
Expand Down Expand Up @@ -597,6 +598,34 @@ jobs:
- target/wasm32-unknown-unknown/release/deps
key: cargocache-v2-contract_burner-rust:1.74-{{ checksum "Cargo.lock" }}

contract_replier:
docker:
- image: rust:1.74
environment:
RUST_BACKTRACE: 1
working_directory: ~/cosmwasm/contracts/replier
steps:
- checkout:
path: ~/cosmwasm
- run:
name: Version information
command: rustc --version; cargo --version; rustup --version
- restore_cache:
keys:
- cargocache-v2-contract_replier-rust:1.74-{{ checksum "Cargo.lock" }}
- check_contract:
min_version: "1.4"
- save_cache:
paths:
- /usr/local/cargo/registry
- target/debug/.fingerprint
- target/debug/build
- target/debug/deps
- target/wasm32-unknown-unknown/release/.fingerprint
- target/wasm32-unknown-unknown/release/build
- target/wasm32-unknown-unknown/release/deps
key: cargocache-v2-contract_replier-rust:1.74-{{ checksum "Cargo.lock" }}

contract_crypto_verify:
docker:
- image: rust:1.74
Expand Down
4 changes: 2 additions & 2 deletions contracts/replier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ overflow-checks = true
[dependencies]
cosmwasm-schema = { path = "../../packages/schema" }
cosmwasm-std = { path = "../../packages/std", default-features = false, features = [
"abort",
"cosmwasm_2_2",
"cosmwasm_1_4",
"iterator",
"std",
] }
schemars = "0.8.12"
Expand Down
21 changes: 12 additions & 9 deletions contracts/replier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ use cosmwasm_std::{
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

const SET_DATA_IN_EXEC_AND_REPLY_FLAG: u64 = 0x100;
const RETURN_OERDER_IN_REPLY_FLAG: u64 = 0x200;
const REPLY_ERROR_FLAG: u64 = 0x400;

#[cw_serde]
pub struct InstantiateMsg {}

Expand Down Expand Up @@ -78,13 +82,13 @@ pub fn execute(
};
let mut msg_id: u64 = msg.msg_id.into();
if msg.set_data_in_exec_and_reply {
msg_id = msg_id | 0x100;
msg_id |= SET_DATA_IN_EXEC_AND_REPLY_FLAG;
}
if msg.return_order_in_reply {
msg_id = msg_id | 0x200;
msg_id |= RETURN_OERDER_IN_REPLY_FLAG;
}
if msg.reply_error {
msg_id = msg_id | 0x400;
msg_id |= REPLY_ERROR_FLAG;
}

let submsg = SubMsg {
Expand All @@ -111,9 +115,9 @@ pub fn query(_deps: Deps, _env: Env, _msg: QueryMsg) -> StdResult<QueryResponse>
#[entry_point]
pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> StdResult<Response> {
let msg_id = msg.id & 0xFF;
let should_set_data = msg.id & 0x100 != 0;
let should_set_order = msg.id & 0x200 != 0;
let should_return_error = msg.id & 0x400 != 0;
let should_set_data = msg.id & SET_DATA_IN_EXEC_AND_REPLY_FLAG != 0;
let should_set_order = msg.id & RETURN_OERDER_IN_REPLY_FLAG != 0;
let should_return_error = msg.id & REPLY_ERROR_FLAG != 0;

let data = deps.storage.get(CONFIG_KEY).unwrap();
let mut config: State = from_json(data)?;
Expand All @@ -140,9 +144,8 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> StdResult<Response> {
result
.msg_responses
.into_iter()
.map(|resp| resp.value.as_slice().to_vec())
.flatten()
.chain([0xBB, msg_id as u8].into_iter())
.flat_map(|resp| resp.value.as_slice().to_vec())
.chain([0xBB, msg_id as u8])
.collect(),
)))
} else {
Expand Down
1 change: 1 addition & 0 deletions contracts/replier/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit 24c6561

Please sign in to comment.