Skip to content

Commit

Permalink
rearrange entry points placement in code
Browse files Browse the repository at this point in the history
  • Loading branch information
sotnikov-s committed Nov 11, 2024
1 parent ee6e04e commit 9977666
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,6 @@ pub fn query_account(deps: Deps, addr: String) -> NeutronResult<Binary> {
Ok(to_json_binary(&REMOTE_ACCOUNTS.load(deps.storage, addr)?)?)
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Response> {
Ok(Response::default())
}

#[entry_point]
pub fn sudo(deps: DepsMut, _env: Env, msg: SudoMsg) -> NeutronResult<Response> {
match msg {
SudoMsg::KVQueryResult { query_id } => sudo_kv_query_result(deps, query_id),
_ => Ok(Response::default()),
}
}

#[entry_point]
pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> NeutronResult<Response> {
match msg.id {
Expand Down Expand Up @@ -152,6 +139,14 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> NeutronResult<Response> {
}
}

#[entry_point]
pub fn sudo(deps: DepsMut, _env: Env, msg: SudoMsg) -> NeutronResult<Response> {
match msg {
SudoMsg::KVQueryResult { query_id } => sudo_kv_query_result(deps, query_id),
_ => Ok(Response::default()),
}
}

/// The contract's callback for KV query results. Note that only the query id is provided, so you
/// need to read the query result from the state.
pub fn sudo_kv_query_result(deps: DepsMut, query_id: u64) -> NeutronResult<Response> {
Expand All @@ -167,3 +162,8 @@ pub fn sudo_kv_query_result(deps: DepsMut, query_id: u64) -> NeutronResult<Respo

Ok(Response::default())
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Response> {
Ok(Response::default())
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,6 @@ pub fn query_balances(deps: Deps, addr: String) -> NeutronResult<Binary> {
Ok(to_json_binary(&REMOTE_BALANCES.load(deps.storage, addr)?)?)
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Response> {
Ok(Response::default())
}

#[entry_point]
pub fn sudo(deps: DepsMut, env: Env, msg: SudoMsg) -> NeutronResult<Response> {
match msg {
SudoMsg::KVQueryResult { query_id } => sudo_kv_query_result(deps, env, query_id),
_ => Ok(Response::default()),
}
}

#[entry_point]
pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> NeutronResult<Response> {
match msg.id {
Expand Down Expand Up @@ -137,6 +124,14 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> NeutronResult<Response> {
}
}

#[entry_point]
pub fn sudo(deps: DepsMut, env: Env, msg: SudoMsg) -> NeutronResult<Response> {
match msg {
SudoMsg::KVQueryResult { query_id } => sudo_kv_query_result(deps, env, query_id),
_ => Ok(Response::default()),
}
}

/// The contract's callback for KV query results. Note that only the query id is provided, so you
/// need to read the query result from the state.
pub fn sudo_kv_query_result(deps: DepsMut, env: Env, query_id: u64) -> NeutronResult<Response> {
Expand All @@ -151,3 +146,8 @@ pub fn sudo_kv_query_result(deps: DepsMut, env: Env, query_id: u64) -> NeutronRe

Ok(Response::default())
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Response> {
Ok(Response::default())
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ pub fn query_undelegated_amount(deps: Deps, addr: String) -> NeutronResult<Binar
)?)
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Response> {
#[entry_point]
pub fn reply(_deps: DepsMut, _env: Env, _msg: Reply) -> NeutronResult<Response> {
Ok(Response::default())
}

Expand All @@ -124,11 +124,6 @@ pub fn sudo(deps: DepsMut, env: Env, msg: SudoMsg) -> NeutronResult<Response> {
}
}

#[entry_point]
pub fn reply(_deps: DepsMut, _env: Env, _msg: Reply) -> NeutronResult<Response> {
Ok(Response::default())
}

/// The contract's callback for TX query results.
pub fn sudo_tx_query_result(
deps: DepsMut,
Expand All @@ -154,6 +149,7 @@ pub fn sudo_tx_query_result(
}
};

// the contract's side verification of submitted TX Interchain Query results part
let mut new_undelegations: Vec<Coin> = vec![];
for msg in body.messages.iter() {
// Narrow down the messages to only MsgUndelegate ones
Expand All @@ -174,6 +170,8 @@ pub fn sudo_tx_query_result(
});
}

// Put your business logic here
// For this example we just preserve the new undelegations in the state
if !new_undelegations.is_empty() {
let mut undelegations = UNDELEGATED_AMOUNTS
.may_load(deps.storage, delegator.clone())?
Expand All @@ -184,3 +182,8 @@ pub fn sudo_tx_query_result(

Ok(Response::default())
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Response> {
Ok(Response::default())
}

0 comments on commit 9977666

Please sign in to comment.