Skip to content

Commit

Permalink
lint the code
Browse files Browse the repository at this point in the history
  • Loading branch information
neitdung committed Jul 28, 2024
1 parent a773d32 commit 10142f0
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 19 deletions.
3 changes: 1 addition & 2 deletions contracts/provider/external-staking/src/multitest/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ pub(crate) trait AppExt {
impl AppExt for App<MtApp> {
#[track_caller]
fn new_with_balances(balances: &[(&str, &[Coin])]) -> Self {

let app =MtApp::new(|router, _api, storage| {
let app = MtApp::new(|router, _api, storage| {
for (addr, coins) in balances {
router
.bank
Expand Down
6 changes: 5 additions & 1 deletion contracts/provider/native-staking-proxy/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ impl NativeStakingProxyContract<'_> {
/// Stakes the tokens from `info.funds` to the given validator.
/// Can only be called by the parent contract
#[sv::msg(exec)]
fn stake(&self, ctx: ExecCtx, validator: String) -> Result<Response<ProviderCustomMsg>, ContractError> {
fn stake(
&self,
ctx: ExecCtx,
validator: String,
) -> Result<Response<ProviderCustomMsg>, ContractError> {
let cfg = self.config.load(ctx.deps.storage)?;
ensure_eq!(cfg.parent, ctx.info.sender, ContractError::Unauthorized {});

Expand Down
2 changes: 1 addition & 1 deletion contracts/provider/native-staking-proxy/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pub mod contract;
pub mod error;
pub mod mock;
pub mod msg;
#[cfg(test)]
mod multitest;
pub mod mock;
pub mod native_staking_callback;
mod state;
2 changes: 1 addition & 1 deletion contracts/provider/native-staking-proxy/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,4 +499,4 @@ mod tests {
let res = contract.vote_weighted(ctx, proposal_id, vote);
assert!(matches!(res.unwrap_err(), ContractError::Unauthorized {}));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ impl NativeStakingCallback for NativeStakingContract<'_> {

Ok(Response::new().add_message(msg))
}
}
}
43 changes: 35 additions & 8 deletions contracts/provider/vault/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use cosmwasm_std::{
coin, ensure, Addr, Binary, Coin, Decimal, DepsMut, Fraction, Order, Reply, Response, StdResult, Storage, SubMsg, SubMsgResponse, Uint128, WasmMsg
coin, ensure, Addr, Binary, Coin, Decimal, DepsMut, Fraction, Order, Reply, Response,
StdResult, Storage, SubMsg, SubMsgResponse, Uint128, WasmMsg,
};
use cw2::set_contract_version;
use cw_storage_plus::{Bounder, Item, Map};
Expand Down Expand Up @@ -143,7 +144,11 @@ impl VaultContract<'_> {
}

#[sv::msg(exec)]
fn bond(&self, ctx: ExecCtx, amount: Coin) -> Result<Response<ProviderCustomMsg>, ContractError> {
fn bond(
&self,
ctx: ExecCtx,
amount: Coin,
) -> Result<Response<ProviderCustomMsg>, ContractError> {
nonpayable(&ctx.info)?;

let denom = self.config.load(ctx.deps.storage)?.denom;
Expand All @@ -156,7 +161,10 @@ impl VaultContract<'_> {
user.collateral += amount.amount;
self.users.save(ctx.deps.storage, &ctx.info.sender, &user)?;
let amt = amount.amount;
let msg = ProviderMsg::Bond { delegator: ctx.info.sender.clone().into_string(), amount};
let msg = ProviderMsg::Bond {
delegator: ctx.info.sender.clone().into_string(),
amount,
};
let resp = Response::new()
.add_message(msg)
.add_attribute("action", "unbond")
Expand All @@ -167,7 +175,11 @@ impl VaultContract<'_> {
}

#[sv::msg(exec)]
fn unbond(&self, ctx: ExecCtx, amount: Coin) -> Result<Response<ProviderCustomMsg>, ContractError> {
fn unbond(
&self,
ctx: ExecCtx,
amount: Coin,
) -> Result<Response<ProviderCustomMsg>, ContractError> {
nonpayable(&ctx.info)?;

let denom = self.config.load(ctx.deps.storage)?.denom;
Expand All @@ -187,7 +199,10 @@ impl VaultContract<'_> {
user.collateral -= amount.amount;
self.users.save(ctx.deps.storage, &ctx.info.sender, &user)?;
let amt = amount.amount;
let msg = ProviderMsg::Unbond { delegator: ctx.info.sender.clone().into_string(), amount};
let msg = ProviderMsg::Unbond {
delegator: ctx.info.sender.clone().into_string(),
amount,
};
let resp = Response::new()
.add_message(msg)
.add_attribute("action", "unbond")
Expand Down Expand Up @@ -492,7 +507,11 @@ impl VaultContract<'_> {
}

#[sv::msg(reply)]
fn reply(&self, ctx: ReplyCtx, reply: Reply) -> Result<Response<ProviderCustomMsg>, ContractError> {
fn reply(
&self,
ctx: ReplyCtx,
reply: Reply,
) -> Result<Response<ProviderCustomMsg>, ContractError> {
match reply.id {
REPLY_ID_INSTANTIATE => self.reply_init_callback(ctx.deps, reply.result.unwrap()),
_ => Err(ContractError::InvalidReplyId(reply.id)),
Expand Down Expand Up @@ -1085,7 +1104,11 @@ impl VaultApi for VaultContract<'_> {
Ok(resp)
}

fn commit_tx(&self, mut ctx: ExecCtx, tx_id: u64) -> Result<Response<Self::ExecC>, ContractError> {
fn commit_tx(
&self,
mut ctx: ExecCtx,
tx_id: u64,
) -> Result<Response<Self::ExecC>, ContractError> {
self.commit_stake(&mut ctx, tx_id)?;

let resp = Response::new()
Expand All @@ -1096,7 +1119,11 @@ impl VaultApi for VaultContract<'_> {
Ok(resp)
}

fn rollback_tx(&self, mut ctx: ExecCtx, tx_id: u64) -> Result<Response<Self::ExecC>, ContractError> {
fn rollback_tx(
&self,
mut ctx: ExecCtx,
tx_id: u64,
) -> Result<Response<Self::ExecC>, ContractError> {
self.rollback_stake(&mut ctx, tx_id)?;

let resp = Response::new()
Expand Down
2 changes: 1 addition & 1 deletion contracts/provider/vault/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pub mod contract;
pub mod error;
pub mod mock;
pub mod msg;
#[cfg(test)]
pub mod multitest;
pub mod mock;
mod state;
pub mod txs;
3 changes: 2 additions & 1 deletion contracts/provider/vault/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use cosmwasm_std::{
coin, ensure, Addr, BankMsg, Binary, Coin, Decimal, DepsMut, Empty, Fraction, Order, Reply, Response, StdResult, Storage, SubMsg, SubMsgResponse, Uint128, WasmMsg
coin, ensure, Addr, BankMsg, Binary, Coin, Decimal, DepsMut, Empty, Fraction, Order, Reply,
Response, StdResult, Storage, SubMsg, SubMsgResponse, Uint128, WasmMsg,
};
use cw2::set_contract_version;
use cw_storage_plus::{Bounder, Item, Map};
Expand Down
2 changes: 1 addition & 1 deletion packages/apis/src/vault_api.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{to_json_binary, Addr, Coin, Response, StdError, Uint128, CustomMsg, WasmMsg};
use cosmwasm_std::{to_json_binary, Addr, Coin, CustomMsg, Response, StdError, Uint128, WasmMsg};
use sylvia::types::ExecCtx;
use sylvia::{interface, schemars};

Expand Down
2 changes: 1 addition & 1 deletion packages/bindings/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod msg;
mod query;

pub use msg::{VirtualStakeCustomMsg, VirtualStakeMsg, ProviderCustomMsg, ProviderMsg};
pub use msg::{ProviderCustomMsg, ProviderMsg, VirtualStakeCustomMsg, VirtualStakeMsg};
pub use query::{
BondStatusResponse, SlashRatioResponse, TokenQuerier, VirtualStakeCustomQuery,
VirtualStakeQuery,
Expand Down
2 changes: 1 addition & 1 deletion packages/bindings/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl ProviderMsg {
amount: coin,
}
}

pub fn unstake(denom: &str, validator: &str, amount: impl Into<Uint128>) -> ProviderMsg {
let coin = Coin {
amount: amount.into(),
Expand Down

0 comments on commit 10142f0

Please sign in to comment.