Skip to content

Commit 9072211

Browse files
authored
new ci (#23)
* new ci * clippy happy, thx clippy
1 parent b521b47 commit 9072211

File tree

11 files changed

+181
-163
lines changed

11 files changed

+181
-163
lines changed

.github/workflows/ci.yml renamed to .github/workflows/build.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Rust project CI
1+
name: Rust Build
22

33
on:
44
push:
@@ -7,7 +7,7 @@ on:
77
pull_request:
88

99
jobs:
10-
build-and-test:
10+
build:
1111
runs-on: ubuntu-latest
1212

1313
steps:
@@ -24,13 +24,8 @@ jobs:
2424
with:
2525
command: build
2626

27-
- name: Run tests
28-
uses: actions-rs/cargo@v1
29-
with:
30-
command: test
31-
3227
optimize:
33-
needs: build-and-test
28+
needs: build
3429
runs-on: ubuntu-latest
3530
steps:
3631
- uses: actions/checkout@v3
@@ -42,4 +37,4 @@ jobs:
4237
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/target \
4338
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
4439
cosmwasm/workspace-optimizer:0.15.0 \
45-
/code
40+
/code

.github/workflows/lint.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Rust Lint
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Install Rust
17+
uses: actions-rs/toolchain@v1
18+
with:
19+
toolchain: stable
20+
override: true
21+
22+
- name: Run Clippy
23+
uses: actions-rs/cargo@v1
24+
with:
25+
command: clippy
26+
args: -- -D warnings
27+
28+
- name: Run Rustfmt
29+
uses: actions-rs/cargo@v1
30+
with:
31+
command: fmt
32+
args: -- --check

.github/workflows/test.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Rust Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Install Rust
17+
uses: actions-rs/toolchain@v1
18+
with:
19+
toolchain: stable
20+
override: true
21+
22+
- name: Run tests
23+
uses: actions-rs/cargo@v1
24+
with:
25+
command: test

contracts/prudent-pots/src/contract.rs

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -67,34 +67,7 @@ pub fn execute(
6767
msg: ExecuteMsg,
6868
) -> Result<Response, ContractError> {
6969
match msg {
70-
ExecuteMsg::UpdateConfig {
71-
fee,
72-
fee_reallocation,
73-
fee_address,
74-
game_denom,
75-
game_cw721_addrs,
76-
game_duration,
77-
game_extend,
78-
game_end_threshold,
79-
min_pot_initial_allocation,
80-
decay_factor,
81-
reallocations_limit,
82-
} => update_config(
83-
deps,
84-
env,
85-
info,
86-
fee,
87-
fee_reallocation,
88-
fee_address,
89-
game_denom,
90-
game_cw721_addrs,
91-
game_duration,
92-
game_extend,
93-
game_end_threshold,
94-
min_pot_initial_allocation,
95-
decay_factor,
96-
reallocations_limit,
97-
),
70+
ExecuteMsg::UpdateConfig { config } => update_config(deps, env, info, config),
9871
ExecuteMsg::AllocateTokens { pot_id } => allocate_tokens(deps, env, info, pot_id),
9972
ExecuteMsg::ReallocateTokens {
10073
from_pot_id,

contracts/prudent-pots/src/execute.rs

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cosmwasm_std::{attr, Addr, BankMsg, CosmosMsg, DepsMut, Env, MessageInfo, Response, Uint128};
1+
use cosmwasm_std::{attr, BankMsg, CosmosMsg, DepsMut, Env, MessageInfo, Response, Uint128};
22

33
use crate::{
44
helpers::{
@@ -17,6 +17,7 @@ use crate::{
1717
validate_pot_limit_not_exceeded,
1818
},
1919
},
20+
msg::UpdateGameConfig,
2021
state::{GAME_CONFIG, GAME_STATE, PLAYER_ALLOCATIONS, REALLOCATION_FEE_POOL},
2122
ContractError,
2223
};
@@ -25,72 +26,62 @@ pub fn update_config(
2526
deps: DepsMut,
2627
env: Env,
2728
info: MessageInfo,
28-
fee: Option<u64>,
29-
fee_reallocation: Option<u64>,
30-
fee_address: Option<Addr>,
31-
game_denom: Option<String>,
32-
game_cw721_addrs: Vec<Addr>, // this is the cw721 collection addy we use as optional raffle prize
33-
game_duration: Option<u64>,
34-
game_extend: Option<u64>,
35-
game_end_threshold: Option<u64>,
36-
min_pot_initial_allocation: Option<Uint128>,
37-
decay_factor: Option<Uint128>, // i.e. 95 as 95%
38-
reallocations_limit: Option<u64>,
29+
update_config: UpdateGameConfig,
3930
) -> Result<Response, ContractError> {
4031
validate_is_contract_admin(&deps.querier, &env, &info.sender)?;
4132

4233
let mut game_config = GAME_CONFIG.load(deps.storage)?;
4334

44-
if let Some(fee) = fee {
35+
if let Some(fee) = update_config.fee {
4536
if fee > 10 {
4637
return Err(ContractError::InvalidInput {});
4738
}
4839
game_config.fee = fee;
4940
}
50-
if let Some(fee_reallocation) = fee_reallocation {
41+
if let Some(fee_reallocation) = update_config.fee_reallocation {
5142
if fee_reallocation > 50 {
5243
return Err(ContractError::InvalidInput {});
5344
}
5445
game_config.fee_reallocation = fee_reallocation;
5546
}
56-
if let Some(fee_address) = fee_address {
47+
if let Some(fee_address) = update_config.fee_address {
5748
game_config.fee_address = deps.api.addr_validate(fee_address.as_str())?;
5849
}
59-
if let Some(game_denom) = game_denom {
50+
if let Some(game_denom) = update_config.game_denom {
6051
game_config.game_denom = game_denom;
6152
}
6253
if !game_config
6354
.game_cw721_addrs
6455
.iter()
65-
.eq(game_cw721_addrs.iter())
56+
.eq(update_config.game_cw721_addrs.iter())
6657
{
67-
for address in &game_cw721_addrs {
58+
for address in &update_config.game_cw721_addrs {
6859
deps.api.addr_validate(address.as_str())?;
6960
}
70-
game_config.game_cw721_addrs = game_cw721_addrs;
61+
game_config.game_cw721_addrs = update_config.game_cw721_addrs;
7162
}
72-
if let Some(game_duration) = game_duration {
63+
if let Some(game_duration) = update_config.game_duration {
7364
game_config.game_duration = game_duration;
7465
}
75-
if let Some(game_extend) = game_extend {
66+
if let Some(game_extend) = update_config.game_extend {
7667
if game_extend > game_config.game_duration {
7768
return Err(ContractError::InvalidInput {});
7869
}
7970
game_config.game_extend = game_extend;
8071
}
81-
if let Some(game_end_threshold) = game_end_threshold {
72+
if let Some(game_end_threshold) = update_config.game_end_threshold {
8273
game_config.game_end_threshold = game_end_threshold;
8374
}
84-
if let Some(min_pot_initial_allocation) = min_pot_initial_allocation {
75+
if let Some(min_pot_initial_allocation) = update_config.min_pot_initial_allocation {
8576
game_config.min_pot_initial_allocation = min_pot_initial_allocation;
8677
}
87-
if let Some(decay_factor) = decay_factor {
78+
if let Some(decay_factor) = update_config.decay_factor {
8879
if decay_factor.lt(&Uint128::new(50u128)) || decay_factor.gt(&Uint128::new(99u128)) {
8980
return Err(ContractError::InvalidInput {});
9081
}
9182
game_config.decay_factor = decay_factor;
9283
}
93-
if let Some(reallocations_limit) = reallocations_limit {
84+
if let Some(reallocations_limit) = update_config.reallocations_limit {
9485
game_config.reallocations_limit = reallocations_limit;
9586
}
9687
GAME_CONFIG.save(deps.storage, &game_config)?;
@@ -223,22 +214,15 @@ pub fn game_end(
223214
let mut msgs: Vec<CosmosMsg> = vec![];
224215

225216
// Process raffle winner and prepare distribution messages
226-
let (
227-
raffle_msgs, // bank sends
228-
raffle_submsgs, // nft transfer
229-
raffle_response_attributes,
230-
new_raffle_denom_amount,
231-
updated_new_raffle_cw721_id,
232-
updated_new_raffle_cw721_addr,
233-
) = process_raffle_winner(
217+
let process_raffle_winner_resp = process_raffle_winner(
234218
&deps.as_ref(),
235219
&env,
236220
&info.funds,
237221
&winning_pots,
238222
new_raffle_cw721_id,
239223
new_raffle_cw721_addr,
240224
)?;
241-
msgs.extend(raffle_msgs.clone());
225+
msgs.extend(process_raffle_winner_resp.msgs.clone());
242226

243227
// Add messages for redistributing tokens from losing to winning pots
244228
let (send_msgs, treasury_outgoing_tokens) =
@@ -248,7 +232,8 @@ pub fn game_end(
248232

249233
// Iterate again the msgs generated to know how much tokens effectively we send,
250234
// as total_losing_tokens contains also next game funds we want to preserve.
251-
let total_outgoing_raffle: Uint128 = raffle_msgs
235+
let total_outgoing_raffle: Uint128 = process_raffle_winner_resp
236+
.msgs
252237
.iter()
253238
.filter_map(|msg| {
254239
if let CosmosMsg::Bank(BankMsg::Send { amount, .. }) = msg {
@@ -279,14 +264,14 @@ pub fn game_end(
279264
deps,
280265
&env,
281266
total_outgoing_tokens,
282-
updated_new_raffle_cw721_id,
283-
updated_new_raffle_cw721_addr,
284-
Some(new_raffle_denom_amount),
267+
process_raffle_winner_resp.new_raffle_cw721_id,
268+
process_raffle_winner_resp.new_raffle_cw721_addr,
269+
Some(process_raffle_winner_resp.new_raffle_denom_amount),
285270
)?;
286271

287272
Ok(Response::new()
288273
.add_messages(msgs)
289-
.add_submessages(raffle_submsgs)
274+
.add_submessages(process_raffle_winner_resp.submsgs)
290275
.add_attributes(vec![
291276
attr("method", "execute"),
292277
attr("action", "game_end"),
@@ -299,6 +284,6 @@ pub fn game_end(
299284
),
300285
attr("treasury_outgoing_tokens", treasury_outgoing_tokens),
301286
])
302-
.add_attributes(raffle_response_attributes) // this contains the raffle event attributes including the treasury denom fee split, which is not included above
287+
.add_attributes(process_raffle_winner_resp.attributes) // this contains the raffle event attributes including the treasury denom fee split, which is not included above
303288
.add_attribute("total_outgoing_tokens", total_outgoing_tokens)) // this is the total of distribution + raffle + treasury
304289
}

0 commit comments

Comments
 (0)