Skip to content

Commit c55e7ba

Browse files
committed
fix linting
1 parent 50f0001 commit c55e7ba

File tree

9 files changed

+45
-50
lines changed

9 files changed

+45
-50
lines changed

src/btbe.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl StoredEntry {
5959

6060
let mut result = [0u8; BTBE_BUCKET_ENTRY_BYTES];
6161
result[..BTBE_BUCKET_ADDRESS_BYTES].copy_from_slice(address);
62-
Ok(Self { 0: result })
62+
Ok(Self(result))
6363
}
6464

6565
fn from(
@@ -159,15 +159,13 @@ impl StoredEntry {
159159

160160
pub fn routes_to_right_node(&self, bit_pos: usize, secret: &[u8]) -> StdResult<bool> {
161161
// target byte value
162-
let byte;
163-
164162
// bit pos is cached
165-
if bit_pos < (BTBE_BUCKET_CACHE_BYTES << 3) {
163+
let byte = if bit_pos < (BTBE_BUCKET_CACHE_BYTES << 3) {
166164
// select the byte from cache corresponding to this bit position
167-
byte = self.0[BTBE_BUCKET_ADDRESS_BYTES
165+
self.0[BTBE_BUCKET_ADDRESS_BYTES
168166
+ BTBE_BUCKET_BALANCE_BYTES
169167
+ BTBE_BUCKET_HISTORY_BYTES
170-
+ (bit_pos >> 3)];
168+
+ (bit_pos >> 3)]
171169
}
172170
// not cached; calculate on the fly
173171
else {
@@ -180,11 +178,11 @@ impl StoredEntry {
180178
)?;
181179

182180
// select the byte containing the target bit
183-
byte = key_bytes[bit_pos >> 3];
184-
}
181+
key_bytes[bit_pos >> 3]
182+
};
185183

186184
// extract value at bit position and turn into bool
187-
return Ok(((byte >> (7 - (bit_pos % 8))) & 1) != 0);
185+
Ok(((byte >> (7 - (bit_pos % 8))) & 1) != 0)
188186
}
189187

190188
pub fn merge_dwb_entry(
@@ -229,9 +227,7 @@ impl StoredEntry {
229227
// peek at the last tx bundle added (read the dummy one if its void)
230228
let last_tx_bundle_result = self.get_tx_bundle_at_unchecked(storage, bundle_pos);
231229
if last_tx_bundle_result.is_err() {
232-
return Err(StdError::generic_err(format!(
233-
"missing tx bundle while merging dwb entry!",
234-
)));
230+
return Err(StdError::generic_err("missing tx bundle while merging dwb entry!"));
235231
}
236232

237233
// unwrap
@@ -469,7 +465,7 @@ pub fn locate_btbe_node(
469465
// while the node has children
470466
while node.bucket == 0 {
471467
// calculate bit value at current bit position
472-
let bit_value = (hash[(bit_pos / 8) as usize] >> (7 - (bit_pos % 8))) & 1;
468+
let bit_value = (hash[bit_pos / 8] >> (7 - (bit_pos % 8))) & 1;
473469

474470
// increment bit position
475471
bit_pos += 1;
@@ -584,7 +580,7 @@ pub fn settle_dwb_entry(
584580
if let Some((idx, mut found_entry)) = bucket.constant_time_find_address(address) {
585581
// found existing entry
586582
// merge amount and history from dwb entry
587-
found_entry.merge_dwb_entry(storage, &dwb_entry, amount_spent)?;
583+
found_entry.merge_dwb_entry(storage, dwb_entry, amount_spent)?;
588584
bucket.entries[idx] = found_entry;
589585

590586
#[cfg(feature = "gas_tracking")]
@@ -600,7 +596,7 @@ pub fn settle_dwb_entry(
600596
else {
601597
// need to insert new entry
602598
// create new stored balance entry
603-
let mut btbe_entry = StoredEntry::from(storage, &dwb_entry, amount_spent)?;
599+
let mut btbe_entry = StoredEntry::from(storage, dwb_entry, amount_spent)?;
604600

605601
// cache the address
606602
btbe_entry.save_hash_cache(storage)?;

src/contract.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,7 @@ pub fn instantiate(
153153
}
154154
}
155155

156-
let supported_denoms = match msg.supported_denoms {
157-
None => vec![],
158-
Some(x) => x,
159-
};
156+
let supported_denoms = msg.supported_denoms.unwrap_or_default();
160157

161158
CONFIG.save(
162159
deps.storage,
@@ -468,7 +465,7 @@ fn permit_queries(
468465
query::query_balance(deps, account)
469466
}
470467
QueryWithPermit::TransferHistory { .. } => {
471-
return Err(StdError::generic_err(TRANSFER_HISTORY_UNSUPPORTED_MSG));
468+
Err(StdError::generic_err(TRANSFER_HISTORY_UNSUPPORTED_MSG))
472469
}
473470
QueryWithPermit::TransactionHistory { page, page_size } => {
474471
if !permit.check_permission(&TokenPermissions::History) {
@@ -1048,7 +1045,7 @@ mod tests {
10481045
.add_suffix(&alice_entry.head_node().unwrap().to_be_bytes())
10491046
.load(&deps.storage)
10501047
.unwrap()
1051-
.to_vec(&deps.storage, &deps.api)
1048+
.as_vec(&deps.storage, &deps.api)
10521049
.unwrap();
10531050

10541051
let expected_alice_nodes: Vec<Tx> = vec![

src/dwb.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl DelayedWriteBuffer {
129129

130130
settle_dwb_entry(
131131
store,
132-
&mut dwb_entry,
132+
&dwb_entry,
133133
Some(amount_spent),
134134
#[cfg(feature = "gas_tracking")]
135135
tracker,
@@ -178,7 +178,7 @@ impl DelayedWriteBuffer {
178178
matched_index
179179
}
180180

181-
pub fn add_recipient<'a>(
181+
pub fn add_recipient(
182182
&mut self,
183183
store: &mut dyn Storage,
184184
rng: &mut ContractPrng,
@@ -196,7 +196,7 @@ impl DelayedWriteBuffer {
196196
group1.log("recipient_match");
197197

198198
// the new entry will either derive from a prior entry for the recipient or the dummy entry
199-
let mut new_entry = self.entries[recipient_index].clone();
199+
let mut new_entry = self.entries[recipient_index];
200200

201201
new_entry.set_recipient(recipient)?;
202202
#[cfg(feature = "gas_tracking")]
@@ -273,10 +273,10 @@ impl DelayedWriteBuffer {
273273
group1.logf(format!("@write_index: {}", write_index));
274274

275275
// settle the entry
276-
let mut dwb_entry = self.entries[actual_settle_index];
276+
let dwb_entry = self.entries[actual_settle_index];
277277
settle_dwb_entry(
278278
store,
279-
&mut dwb_entry,
279+
&dwb_entry,
280280
None,
281281
#[cfg(feature = "gas_tracking")]
282282
tracker,
@@ -355,7 +355,7 @@ impl DelayedWriteBufferEntry {
355355
}
356356
let mut result = [0u8; DWB_ENTRY_BYTES];
357357
result[..DWB_RECIPIENT_BYTES].copy_from_slice(recipient);
358-
Ok(Self { 0: result })
358+
Ok(Self(result))
359359
}
360360

361361
pub fn recipient_slice(&self) -> &[u8] {
@@ -466,7 +466,7 @@ pub fn amount_u64(amount_spent: Option<u128>) -> StdResult<u64> {
466466
let amount_spent = amount_spent.unwrap_or_default();
467467
let amount_spent_u64 = amount_spent
468468
.try_into()
469-
.or_else(|_| return Err(StdError::generic_err("se: spent overflow")))?;
469+
.map_err(|_| StdError::generic_err("se: spent overflow"))?;
470470
Ok(amount_spent_u64)
471471
}
472472

@@ -481,7 +481,7 @@ pub struct TxNode {
481481

482482
impl TxNode {
483483
// converts this and following elements in list to a vec of Tx
484-
pub fn to_vec(&self, store: &dyn Storage, api: &dyn Api) -> StdResult<Vec<Tx>> {
484+
pub fn as_vec(&self, store: &dyn Storage, api: &dyn Api) -> StdResult<Vec<Tx>> {
485485
let mut result = vec![];
486486
let mut cur_node = Some(self.to_owned());
487487
while cur_node.is_some() {

src/execute_admin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn change_admin(deps: DepsMut, constants: &mut Config, address: String) -> S
1010
let address = deps.api.addr_validate(address.as_str())?;
1111

1212
constants.admin = address;
13-
CONFIG.save(deps.storage, &constants)?;
13+
CONFIG.save(deps.storage, constants)?;
1414

1515
Ok(Response::new().set_data(to_binary(&ExecuteAnswer::ChangeAdmin { status: Success })?))
1616
}
@@ -32,7 +32,7 @@ pub fn add_supported_denoms(
3232
}
3333
}
3434

35-
CONFIG.save(deps.storage, &config)?;
35+
CONFIG.save(deps.storage, config)?;
3636

3737
Ok(
3838
Response::new().set_data(to_binary(&ExecuteAnswer::AddSupportedDenoms {
@@ -56,7 +56,7 @@ pub fn remove_supported_denoms(
5656
config.supported_denoms.retain(|x| x != denom);
5757
}
5858

59-
CONFIG.save(deps.storage, &config)?;
59+
CONFIG.save(deps.storage, config)?;
6060

6161
Ok(
6262
Response::new().set_data(to_binary(&ExecuteAnswer::RemoveSupportedDenoms {

src/execute_mint_burn.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ fn try_mint_impl(
212212
Ok(())
213213
}
214214

215+
#[allow(clippy::too_many_arguments)]
215216
pub fn perform_mint(
216217
store: &mut dyn Storage,
217218
rng: &mut ContractPrng,
@@ -453,7 +454,7 @@ pub fn try_burn_from(
453454
memo_len,
454455
},
455456
)
456-
.to_txhash_notification(deps.api, &env, secret, None)?;
457+
.to_txhash_notification(deps.api, env, secret, None)?;
457458

458459
resp = resp.add_attribute_plaintext(
459460
spent_notification.id_plaintext(),

src/execute_transfer_send.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,10 @@ pub fn try_transfer_from(
230230

231231
if NOTIFICATIONS_ENABLED.load(deps.storage)? {
232232
let received_notification =
233-
received_notification.to_txhash_notification(deps.api, &env, secret, None)?;
233+
received_notification.to_txhash_notification(deps.api, env, secret, None)?;
234234

235235
let spent_notification =
236-
spent_notification.to_txhash_notification(deps.api, &env, secret, None)?;
236+
spent_notification.to_txhash_notification(deps.api, env, secret, None)?;
237237

238238
resp = resp
239239
.add_attribute_plaintext(
@@ -846,6 +846,7 @@ fn try_send_from_impl(
846846
Ok((received_notification, spent_notification))
847847
}
848848

849+
#[allow(clippy::too_many_arguments)]
849850
fn perform_transfer(
850851
store: &mut dyn Storage,
851852
rng: &mut ContractPrng,

src/gas_tracker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<'a, 'b> GasGroup<'a, 'b> {
7676
format!(
7777
"{}:{}:{}",
7878
self.index,
79-
gas.unwrap_or(0u64).to_string(),
79+
gas.unwrap_or(0u64),
8080
comment
8181
),
8282
);

src/notifications.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl GroupChannel<RecvdNotification> for MultiRecvdNotification {
196196
let owner_bytes: &[u8];
197197
if let Some(owner) = &data.sender {
198198
owner_addr = api.addr_canonicalize(owner.as_str())?;
199-
owner_bytes = &owner_addr.as_slice()
199+
owner_bytes = owner_addr.as_slice()
200200
} else {
201201
owner_bytes = &ZERO_ADDR;
202202
}
@@ -298,10 +298,10 @@ impl BloomFilter {
298298
fn add<D: DirectChannel, G: GroupChannel<D>>(
299299
&mut self,
300300
recipient: &CanonicalAddr,
301-
packet_plaintext: &Vec<u8>,
301+
packet_plaintext: &[u8],
302302
) -> StdResult<Vec<u8>> {
303303
// contribute to received bloom filter
304-
let seed = get_seed(&recipient, &self.secret)?;
304+
let seed = get_seed(recipient, &self.secret)?;
305305
let id = notification_id(&seed, G::CHANNEL_ID, &self.tx_hash)?;
306306
let hash_bytes = U256::from_big_endian(&sha_256(id.0.as_slice()));
307307
let bloom_mask: U256 = U256::from(G::BLOOM_M - 1);

src/query.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub fn query_transactions(
118118
let head_node = TX_NODES
119119
.add_suffix(&head_node_index.to_be_bytes())
120120
.load(deps.storage)?;
121-
txs_in_dwb = head_node.to_vec(deps.storage, deps.api)?;
121+
txs_in_dwb = head_node.as_vec(deps.storage, deps.api)?;
122122
}
123123
}
124124

@@ -148,7 +148,7 @@ pub fn query_transactions(
148148
if tx_bundles_idx_len > 0 {
149149
let mut bundle_idx = tx_bundles_idx_len - 1;
150150
loop {
151-
let tx_bundle = entry.get_tx_bundle_at(deps.storage, bundle_idx.clone())?;
151+
let tx_bundle = entry.get_tx_bundle_at(deps.storage, bundle_idx)?;
152152

153153
// only look if head node is not null
154154
if tx_bundle.head_node > 0 {
@@ -159,11 +159,11 @@ pub fn query_transactions(
159159
let list_len = tx_bundle.list_len as u32;
160160
if txs_left <= list_len {
161161
txs.extend_from_slice(
162-
&head_node.to_vec(deps.storage, deps.api)?[0..txs_left as usize],
162+
&head_node.as_vec(deps.storage, deps.api)?[0..txs_left as usize],
163163
);
164164
break;
165165
}
166-
txs.extend(head_node.to_vec(deps.storage, deps.api)?);
166+
txs.extend(head_node.as_vec(deps.storage, deps.api)?);
167167
txs_left = txs_left.saturating_sub(list_len);
168168
}
169169
if bundle_idx > 0 {
@@ -197,7 +197,7 @@ pub fn query_transactions(
197197
.add_suffix(&tx_bundle.head_node.to_be_bytes())
198198
.load(deps.storage)?;
199199
// this first bundle has all the txs we need
200-
txs = head_node.to_vec(deps.storage, deps.api)?
200+
txs = head_node.as_vec(deps.storage, deps.api)?
201201
[start_at as usize..(start_at + txs_left) as usize]
202202
.to_vec();
203203
}
@@ -208,7 +208,7 @@ pub fn query_transactions(
208208
.add_suffix(&tx_bundle.head_node.to_be_bytes())
209209
.load(deps.storage)?;
210210
// get the rest of the txs in this bundle and then go back through history
211-
txs = head_node.to_vec(deps.storage, deps.api)?[start_at as usize..].to_vec();
211+
txs = head_node.as_vec(deps.storage, deps.api)?[start_at as usize..].to_vec();
212212
txs_left = txs_left.saturating_sub(list_len - start_at);
213213
}
214214

@@ -218,7 +218,7 @@ pub fn query_transactions(
218218
if let Some(entry) = account_stored_entry {
219219
loop {
220220
let tx_bundle =
221-
entry.get_tx_bundle_at(deps.storage, bundle_idx.clone())?;
221+
entry.get_tx_bundle_at(deps.storage, bundle_idx)?;
222222
// only look if head node is not null
223223
if tx_bundle.head_node > 0 {
224224
let head_node = TX_NODES
@@ -227,12 +227,12 @@ pub fn query_transactions(
227227
let list_len = tx_bundle.list_len as u32;
228228
if txs_left <= list_len {
229229
txs.extend_from_slice(
230-
&head_node.to_vec(deps.storage, deps.api)?
230+
&head_node.as_vec(deps.storage, deps.api)?
231231
[0..txs_left as usize],
232232
);
233233
break;
234234
}
235-
txs.extend(head_node.to_vec(deps.storage, deps.api)?);
235+
txs.extend(head_node.as_vec(deps.storage, deps.api)?);
236236
txs_left = txs_left.saturating_sub(list_len);
237237
}
238238
if bundle_idx > 0 {
@@ -335,7 +335,7 @@ pub fn query_allowances_given(
335335
let owner = Addr::unchecked(owner);
336336

337337
let all_allowances =
338-
AllowancesStore::all_allowances(deps.storage, &owner, page, page_size).unwrap_or(vec![]);
338+
AllowancesStore::all_allowances(deps.storage, &owner, page, page_size).unwrap_or_default();
339339

340340
let allowances_result = all_allowances
341341
.into_iter()
@@ -367,7 +367,7 @@ pub fn query_allowances_received(
367367
let spender = Addr::unchecked(spender);
368368

369369
let all_allowed =
370-
AllowancesStore::all_allowed(deps.storage, &spender, page, page_size).unwrap_or(vec![]);
370+
AllowancesStore::all_allowed(deps.storage, &spender, page, page_size).unwrap_or_default();
371371

372372
let allowances = all_allowed
373373
.into_iter()

0 commit comments

Comments
 (0)