Skip to content

Commit

Permalink
target_address
Browse files Browse the repository at this point in the history
  • Loading branch information
codehans committed Mar 11, 2024
1 parent 60d233b commit cacc037
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
17 changes: 11 additions & 6 deletions src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ pub fn reply(deps: DepsMut, env: Env, _msg: Reply) -> Result<Response, ContractE
let config = Config::load(deps.storage)?;
let balance = deps
.querier
.query_balance(env.contract.address, config.revenue_denom.to_string())?;
let send = config.revenue_denom.send(&fee_address(), &balance.amount);
.query_balance(env.contract.address, config.target_denom.to_string())?;
let send = config
.target_denom
.send(&config.target_address, &balance.amount);
Ok(Response::default()
.add_message(send)
.add_event(Event::new("revenue/reply").add_attribute("send", balance.to_string())))
Expand Down Expand Up @@ -132,13 +134,14 @@ mod tests {
let info = mock_info("owner", &vec![]);
let msg = InstantiateMsg {
owner: Addr::unchecked("owner"),
revenue_denom: Denom::from("ukuji"),
target_denom: Denom::from("ukuji"),
target_address: fee_address(),
};
instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();
let config: ConfigResponse =
from_json(query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap()).unwrap();
assert_eq!(config.owner, Addr::unchecked("owner"));
assert_eq!(config.revenue_denom, Denom::from("ukuji"));
assert_eq!(config.target_denom, Denom::from("ukuji"));
let status: StatusResponse =
from_json(query(deps.as_ref(), mock_env(), QueryMsg::Status {}).unwrap()).unwrap();
assert_eq!(status.last, None);
Expand All @@ -152,7 +155,8 @@ mod tests {
let info = mock_info("owner", &vec![]);
let msg = InstantiateMsg {
owner: Addr::unchecked("owner"),
revenue_denom: Denom::from("ukuji"),
target_denom: Denom::from("ukuji"),
target_address: fee_address(),
};
instantiate(deps.as_mut(), mock_env(), info.clone(), msg).unwrap();

Expand Down Expand Up @@ -242,7 +246,8 @@ mod tests {
let info = mock_info("contract-0", &vec![]);
let msg = InstantiateMsg {
owner: Addr::unchecked("owner"),
revenue_denom: Denom::from("ukuji"),
target_denom: Denom::from("ukuji"),
target_address: fee_address(),
};
instantiate(deps.as_mut(), mock_env(), info.clone(), msg).unwrap();

Expand Down
6 changes: 4 additions & 2 deletions src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use crate::state::Action;
#[cw_serde]
pub struct InstantiateMsg {
pub owner: Addr,
pub revenue_denom: Denom,
pub target_denom: Denom,
pub target_address: Addr,
}

#[cw_serde]
Expand All @@ -31,7 +32,8 @@ pub enum QueryMsg {
#[cw_serde]
pub struct ConfigResponse {
pub owner: Addr,
pub revenue_denom: Denom,
pub target_denom: Denom,
pub target_address: Addr,
}

#[cw_serde]
Expand Down
11 changes: 8 additions & 3 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ pub struct Config {
/// The address permitted to set Actions
pub owner: Addr,
/// The denom that is transferred to the fee_collector at the end of every execution
pub revenue_denom: Denom,
pub target_denom: Denom,

/// The final destination that `target_denom` is sent to
pub target_address: Addr,
}

impl Config {
Expand All @@ -34,7 +37,8 @@ impl From<InstantiateMsg> for Config {
fn from(value: InstantiateMsg) -> Self {
Self {
owner: value.owner,
revenue_denom: value.revenue_denom,
target_denom: value.target_denom,
target_address: value.target_address,
}
}
}
Expand All @@ -43,7 +47,8 @@ impl From<Config> for ConfigResponse {
fn from(value: Config) -> Self {
Self {
owner: value.owner,
revenue_denom: value.revenue_denom,
target_denom: value.target_denom,
target_address: value.target_address,
}
}
}
Expand Down

0 comments on commit cacc037

Please sign in to comment.