Skip to content

Commit 9aec7a9

Browse files
committed
Cargo fmt + fix clippy and tests
1 parent ef91e07 commit 9aec7a9

File tree

12 files changed

+87
-109
lines changed

12 files changed

+87
-109
lines changed

packages/crypto/src/hkdf.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ pub fn hkdf_sha_256(
1616
let okm = zero_bytes.as_mut_slice();
1717
match hk.expand(info, okm) {
1818
Ok(_) => Ok(okm.to_vec()),
19-
Err(e) => {
20-
Err(StdError::generic_err(format!("{:?}", e)))
21-
}
19+
Err(e) => Err(StdError::generic_err(format!("{:?}", e))),
2220
}
2321
}
2422

@@ -33,8 +31,6 @@ pub fn hkdf_sha_512(
3331
let okm = zero_bytes.as_mut_slice();
3432
match hk.expand(info, okm) {
3533
Ok(_) => Ok(okm.to_vec()),
36-
Err(e) => {
37-
Err(StdError::generic_err(format!("{:?}", e)))
38-
}
34+
Err(e) => Err(StdError::generic_err(format!("{:?}", e))),
3935
}
40-
}
36+
}

packages/crypto/src/rng.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub struct ContractPrng {
99
}
1010

1111
impl ContractPrng {
12-
1312
pub fn from_env(env: &Env) -> Self {
1413
let seed = env.block.random.as_ref().unwrap();
1514

packages/notification/Readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Each notification channel will have a specified data format, which is defined by
1010

1111
The following example illustrates how you might implement this for a channel called `my_channel` and notification data containing two fields: `sender` and `amount`.
1212

13-
```rust
13+
```ignore
1414
use cosmwasm_std::{Api, StdError, StdResult};
1515
use secret_toolkit::notification::{EncoderExt, CBL_ARRAY_SHORT, CBL_BIGNUM_U64, CBL_U8, Notification, DirectChannel, GroupChannel};
1616
use serde::{Deserialize, Serialize};
@@ -48,7 +48,7 @@ To send a notification to a recipient you first create a new `Notification` stru
4848

4949
The following code snippet creates a notification for the above `my_channel` and adds it to the contract `Response` as a plaintext attribute.
5050

51-
```rust
51+
```ignore
5252
let notification = Notification::new(
5353
recipient,
5454
MyNotification {

packages/notification/src/cbor.rs

+50-59
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cosmwasm_std::{CanonicalAddr, StdResult, StdError};
1+
use cosmwasm_std::{CanonicalAddr, StdError, StdResult};
22
use minicbor::{data as cbor_data, encode as cbor_encode, Encoder};
33

44
/// Length of encoding an arry header that holds less than 24 items
@@ -35,68 +35,59 @@ pub const CBL_TIMESTAMP: usize = 1 + 1 + 8;
3535
pub const CBL_ADDRESS: usize = 1 + 20;
3636

3737
/// Wraps the CBOR error to CosmWasm StdError
38-
pub fn cbor_to_std_error<T>(e: cbor_encode::Error<T>) -> StdError {
39-
StdError::generic_err("CBOR encoding error")
38+
pub fn cbor_to_std_error<T>(_e: cbor_encode::Error<T>) -> StdError {
39+
StdError::generic_err("CBOR encoding error")
4040
}
4141

4242
/// Extends the minicbor encoder with wrapper functions that handle CBOR errors
4343
pub trait EncoderExt {
44-
fn ext_tag(&mut self, tag: cbor_data::IanaTag) -> StdResult<&mut Self>;
45-
46-
fn ext_u8(&mut self, value: u8) -> StdResult<&mut Self>;
47-
fn ext_u32(&mut self, value: u32) -> StdResult<&mut Self>;
48-
fn ext_u64_from_u128(&mut self, value: u128) -> StdResult<&mut Self>;
49-
fn ext_address(&mut self, value: CanonicalAddr) -> StdResult<&mut Self>;
50-
fn ext_bytes(&mut self, value: &[u8]) -> StdResult<&mut Self>;
51-
fn ext_timestamp(&mut self, value: u64) -> StdResult<&mut Self>;
44+
fn ext_tag(&mut self, tag: cbor_data::IanaTag) -> StdResult<&mut Self>;
45+
46+
fn ext_u8(&mut self, value: u8) -> StdResult<&mut Self>;
47+
fn ext_u32(&mut self, value: u32) -> StdResult<&mut Self>;
48+
fn ext_u64_from_u128(&mut self, value: u128) -> StdResult<&mut Self>;
49+
fn ext_address(&mut self, value: CanonicalAddr) -> StdResult<&mut Self>;
50+
fn ext_bytes(&mut self, value: &[u8]) -> StdResult<&mut Self>;
51+
fn ext_timestamp(&mut self, value: u64) -> StdResult<&mut Self>;
5252
}
5353

5454
impl<T: cbor_encode::Write> EncoderExt for Encoder<T> {
55-
#[inline]
56-
fn ext_tag(&mut self, tag: cbor_data::IanaTag) -> StdResult<&mut Self> {
57-
self
58-
.tag(cbor_data::Tag::from(tag))
59-
.map_err(cbor_to_std_error)
60-
}
61-
62-
#[inline]
63-
fn ext_u8(&mut self, value: u8) -> StdResult<&mut Self> {
64-
self
65-
.u8(value)
66-
.map_err(cbor_to_std_error)
67-
}
68-
69-
#[inline]
70-
fn ext_u32(&mut self, value: u32) -> StdResult<&mut Self> {
71-
self
72-
.u32(value)
73-
.map_err(cbor_to_std_error)
74-
}
75-
76-
#[inline]
77-
fn ext_u64_from_u128(&mut self, value: u128) -> StdResult<&mut Self> {
78-
self
79-
.ext_tag(cbor_data::IanaTag::PosBignum)?
80-
.ext_bytes(&value.to_be_bytes()[8..])
81-
}
82-
83-
#[inline]
84-
fn ext_address(&mut self, value: CanonicalAddr) -> StdResult<&mut Self> {
85-
self.ext_bytes(&value.as_slice())
86-
}
87-
88-
#[inline]
89-
fn ext_bytes(&mut self, value: &[u8]) -> StdResult<&mut Self> {
90-
self
91-
.bytes(&value)
92-
.map_err(cbor_to_std_error)
93-
}
94-
95-
#[inline]
96-
fn ext_timestamp(&mut self, value: u64) -> StdResult<&mut Self> {
97-
self
98-
.ext_tag(cbor_data::IanaTag::Timestamp)?
99-
.u64(value)
100-
.map_err(cbor_to_std_error)
101-
}
102-
}
55+
#[inline]
56+
fn ext_tag(&mut self, tag: cbor_data::IanaTag) -> StdResult<&mut Self> {
57+
self.tag(cbor_data::Tag::from(tag))
58+
.map_err(cbor_to_std_error)
59+
}
60+
61+
#[inline]
62+
fn ext_u8(&mut self, value: u8) -> StdResult<&mut Self> {
63+
self.u8(value).map_err(cbor_to_std_error)
64+
}
65+
66+
#[inline]
67+
fn ext_u32(&mut self, value: u32) -> StdResult<&mut Self> {
68+
self.u32(value).map_err(cbor_to_std_error)
69+
}
70+
71+
#[inline]
72+
fn ext_u64_from_u128(&mut self, value: u128) -> StdResult<&mut Self> {
73+
self.ext_tag(cbor_data::IanaTag::PosBignum)?
74+
.ext_bytes(&value.to_be_bytes()[8..])
75+
}
76+
77+
#[inline]
78+
fn ext_address(&mut self, value: CanonicalAddr) -> StdResult<&mut Self> {
79+
self.ext_bytes(value.as_slice())
80+
}
81+
82+
#[inline]
83+
fn ext_bytes(&mut self, value: &[u8]) -> StdResult<&mut Self> {
84+
self.bytes(value).map_err(cbor_to_std_error)
85+
}
86+
87+
#[inline]
88+
fn ext_timestamp(&mut self, value: u64) -> StdResult<&mut Self> {
89+
self.ext_tag(cbor_data::IanaTag::Timestamp)?
90+
.u64(value)
91+
.map_err(cbor_to_std_error)
92+
}
93+
}

packages/notification/src/funcs.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
use crate::cipher_data;
12
use cosmwasm_std::{Binary, CanonicalAddr, StdResult};
2-
use secret_toolkit_crypto::{sha_256, hkdf_sha_256, HmacSha256};
33
use hkdf::hmac::Mac;
4-
use crate::cipher_data;
4+
use secret_toolkit_crypto::{hkdf_sha_256, sha_256, HmacSha256};
55

66
pub const SEED_LEN: usize = 32; // 256 bits
77

@@ -10,9 +10,14 @@ pub const SEED_LEN: usize = 32; // 256 bits
1010
///
1111
/// Returns a notification id for the given address and channel id.
1212
///
13-
pub fn notification_id(seed: &Binary, channel: &str, tx_hash: &String) -> StdResult<Binary> {
13+
pub fn notification_id(seed: &Binary, channel: &str, tx_hash: &str) -> StdResult<Binary> {
1414
// compute notification ID for this event
15-
let material = [channel.as_bytes(), ":".as_bytes(), tx_hash.to_ascii_uppercase().as_bytes()].concat();
15+
let material = [
16+
channel.as_bytes(),
17+
":".as_bytes(),
18+
tx_hash.to_ascii_uppercase().as_bytes(),
19+
]
20+
.concat();
1621

1722
// create HMAC from seed
1823
let mut mac: HmacSha256 = HmacSha256::new_from_slice(seed.0.as_slice()).unwrap();
@@ -27,7 +32,7 @@ pub fn notification_id(seed: &Binary, channel: &str, tx_hash: &String) -> StdRes
2732
///
2833
/// fn encrypt_notification_data
2934
///
30-
/// Returns encrypted bytes given plaintext bytes, address, and channel id.
35+
/// Returns encrypted bytes given plaintext bytes, address, and channel id.
3136
/// Optionally, can set block size (default 36).
3237
///
3338
pub fn encrypt_notification_data(
@@ -73,12 +78,7 @@ pub fn encrypt_notification_data(
7378

7479
/// get the seed for a secret and given address
7580
pub fn get_seed(addr: &CanonicalAddr, secret: &[u8]) -> StdResult<Binary> {
76-
let seed = hkdf_sha_256(
77-
&None,
78-
secret,
79-
addr.as_slice(),
80-
SEED_LEN,
81-
)?;
81+
let seed = hkdf_sha_256(&None, secret, addr.as_slice(), SEED_LEN)?;
8282

8383
Ok(Binary::from(seed))
8484
}
@@ -96,4 +96,3 @@ fn zero_pad_right(message: &mut Vec<u8>, block_size: usize) -> &mut Vec<u8> {
9696
message.extend(std::iter::repeat(0x00).take(missing));
9797
message
9898
}
99-

packages/notification/src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#![doc = include_str!("../Readme.md")]
22

3-
pub mod structs;
4-
pub mod funcs;
5-
pub mod cipher;
63
pub mod cbor;
7-
pub use structs::*;
8-
pub use funcs::*;
9-
pub use cipher::*;
4+
pub mod cipher;
5+
pub mod funcs;
6+
pub mod structs;
107
pub use cbor::*;
8+
pub use cipher::*;
9+
pub use funcs::*;
10+
pub use structs::*;

packages/notification/src/structs.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use cosmwasm_std::{Addr, Api, Binary, Env, StdError, StdResult, Uint64};
2+
use minicbor::Encoder;
23
use schemars::JsonSchema;
34
use serde::{Deserialize, Serialize};
4-
use minicbor::{encode as cbor_encode, Encoder};
55

6-
use crate::{encrypt_notification_data, get_seed, notification_id, cbor_to_std_error};
6+
use crate::{cbor_to_std_error, encrypt_notification_data, get_seed, notification_id};
77

88
#[derive(Serialize, Debug, Deserialize, Clone)]
99
#[cfg_attr(test, derive(Eq, PartialEq))]
@@ -49,7 +49,6 @@ pub trait DirectChannel {
4949
fn encode_cbor(&self, api: &dyn Api, encoder: &mut Encoder<&mut [u8]>) -> StdResult<()>;
5050
}
5151

52-
5352
impl<T: DirectChannel> Notification<T> {
5453
pub fn new(notification_for: Addr, data: T) -> Self {
5554
Notification {
@@ -66,9 +65,12 @@ impl<T: DirectChannel> Notification<T> {
6665
block_size: Option<usize>,
6766
) -> StdResult<TxHashNotification> {
6867
// extract and normalize tx hash
69-
let tx_hash = env.transaction.clone()
68+
let tx_hash = env
69+
.transaction
70+
.clone()
7071
.ok_or(StdError::generic_err("no tx hash found"))?
71-
.hash.to_ascii_uppercase();
72+
.hash
73+
.to_ascii_uppercase();
7274

7375
// canonicalize notification recipient address
7476
let notification_for_raw = api.addr_canonicalize(self.notification_for.as_str())?;
@@ -93,14 +95,10 @@ impl<T: DirectChannel> Notification<T> {
9395
)?;
9496

9597
// enstruct
96-
Ok(TxHashNotification {
97-
id,
98-
encrypted_data,
99-
})
98+
Ok(TxHashNotification { id, encrypted_data })
10099
}
101100
}
102101

103-
104102
#[derive(Serialize, Debug, Deserialize, Clone)]
105103
#[cfg_attr(test, derive(Eq, PartialEq))]
106104
pub struct TxHashNotification {
@@ -190,4 +188,3 @@ pub trait GroupChannel<D: DirectChannel> {
190188

191189
fn notifications(&self) -> &Vec<Notification<D>>;
192190
}
193-

packages/serialization/src/base64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<S: Serde, T> Base64TVisitor<S, T> {
8787
}
8888
}
8989

90-
impl<'de, S: Serde, T: for<'des> de::Deserialize<'des>> de::Visitor<'de> for Base64TVisitor<S, T> {
90+
impl<S: Serde, T: for<'des> de::Deserialize<'des>> de::Visitor<'_> for Base64TVisitor<S, T> {
9191
type Value = Base64Of<S, T>;
9292

9393
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {

packages/snip20/src/query.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,7 @@ impl QueryMsg {
211211
code_hash,
212212
msg,
213213
}))
214-
.map_err(|err| {
215-
StdError::generic_err(format!("Error performing {self} query: {err}"))
216-
})
214+
.map_err(|err| StdError::generic_err(format!("Error performing {self} query: {err}")))
217215
}
218216
}
219217

packages/snip721/src/expiration.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ mod test {
6161
height: 1000,
6262
time: Timestamp::from_seconds(1000000),
6363
chain_id: "test".to_string(),
64-
random: None
64+
random: None,
6565
};
6666

6767
let block_h2000_t2000000 = BlockInfo {
6868
height: 2000,
6969
time: Timestamp::from_seconds(2000000),
7070
chain_id: "test".to_string(),
71-
random: None
71+
random: None,
7272
};
7373
let exp_h1000 = Expiration::AtHeight(1000);
7474
let exp_t1000000 = Expiration::AtTime(1000000);

packages/snip721/src/query.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,7 @@ impl QueryMsg {
468468
code_hash,
469469
msg,
470470
}))
471-
.map_err(|err| {
472-
StdError::generic_err(format!("Error performing {self} query: {err}"))
473-
})
471+
.map_err(|err| StdError::generic_err(format!("Error performing {self} query: {err}")))
474472
}
475473
}
476474

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
pub use secret_toolkit_crypto as crypto;
55
#[cfg(feature = "incubator")]
66
pub use secret_toolkit_incubator as incubator;
7+
#[cfg(feature = "notification")]
8+
pub use secret_toolkit_notification as notification;
79
#[cfg(feature = "permit")]
810
pub use secret_toolkit_permit as permit;
911
#[cfg(feature = "serialization")]
@@ -18,5 +20,3 @@ pub use secret_toolkit_storage as storage;
1820
pub use secret_toolkit_utils as utils;
1921
#[cfg(feature = "viewing-key")]
2022
pub use secret_toolkit_viewing_key as viewing_key;
21-
#[cfg(feature = "notification")]
22-
pub use secret_toolkit_notification as notification;

0 commit comments

Comments
 (0)