Skip to content

Commit

Permalink
Fix band error on ack
Browse files Browse the repository at this point in the history
  • Loading branch information
trinitys7 committed Sep 19, 2024
1 parent da560f3 commit 815e888
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
27 changes: 23 additions & 4 deletions contracts/consumer/band-price-feed/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use mesh_apis::price_feed_api::{PriceFeedApi, PriceResponse};
use crate::error::ContractError;
use crate::state::{Config, TradingPair};

use sylvia::types::{InstantiateCtx, QueryCtx, SudoCtx};
use sylvia::types::{ExecCtx, InstantiateCtx, QueryCtx, SudoCtx};
use sylvia::{contract, schemars};

use cw_band::{Input, OracleRequestPacketData};
Expand Down Expand Up @@ -58,7 +58,7 @@ impl RemotePriceFeedContract {
#[sv::msg(instantiate)]
pub fn instantiate(
&self,
ctx: InstantiateCtx,
mut ctx: InstantiateCtx,
trading_pair: TradingPair,
client_id: String,
oracle_script_id: Uint64,
Expand All @@ -68,12 +68,12 @@ impl RemotePriceFeedContract {
prepare_gas: Uint64,
execute_gas: Uint64,
minimum_sources: u8,
price_info_ttl_in_secs: u64,
) -> Result<Response, ContractError> {
nonpayable(&ctx.info)?;

set_contract_version(ctx.deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
self.trading_pair.save(ctx.deps.storage, &trading_pair)?;

self.config.save(
ctx.deps.storage,
&Config {
Expand All @@ -87,9 +87,27 @@ impl RemotePriceFeedContract {
minimum_sources,
},
)?;

self.price_keeper
.init(&mut ctx.deps, price_info_ttl_in_secs)?;
Ok(Response::new())
}

#[sv::msg(query)]
pub fn get_price(&self, ctx: QueryCtx) -> Result<PriceResponse, ContractError> {
Ok(self
.price_keeper
.price(ctx.deps, &ctx.env)
.map(|rate| PriceResponse {
native_per_foreign: rate,
})?)
}

#[sv::msg(exec)]
pub fn request(&self, ctx: ExecCtx) -> Result<Response, ContractError> {
let ExecCtx { deps, env, info: _ } = ctx;
try_request(deps, &env)
}

}

impl PriceFeedApi for RemotePriceFeedContract {
Expand Down Expand Up @@ -197,6 +215,7 @@ mod tests {
Uint64::new(100000),
Uint64::new(200000),
1,
60,
)
.unwrap();
}
Expand Down
3 changes: 2 additions & 1 deletion contracts/consumer/band-price-feed/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ pub fn ibc_packet_ack(
_env: Env,
_msg: IbcPacketAckMsg,
) -> Result<IbcBasicResponse, ContractError> {
Err(ContractError::IbcAckNotAccepted)
// We ignore acknowledgement from BandChain becuase it doesn't neccessary to know request id when handle result.
Ok(IbcBasicResponse::new().add_attribute("action", "ibc_packet_ack"))
}

#[cfg_attr(not(feature = "library"), entry_point)]
Expand Down

0 comments on commit 815e888

Please sign in to comment.