Skip to content

Commit de93062

Browse files
authored
chore: derive more constructors (#6438)
1 parent d689d9b commit de93062

File tree

16 files changed

+22
-164
lines changed

16 files changed

+22
-164
lines changed

src/blocks/ticket.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use get_size2::GetSize;
88
/// A Ticket is a marker of a tick of the blockchain's clock. It is the source
99
/// of randomness for proofs of storage and leader election. It is generated
1010
/// by the miner of a block using a `VRF` and a `VDF`.
11+
#[cfg_attr(test, derive(derive_more::Constructor))]
1112
#[derive(
1213
Clone,
1314
Debug,
@@ -27,14 +28,6 @@ pub struct Ticket {
2728
pub vrfproof: VRFProof,
2829
}
2930

30-
impl Ticket {
31-
#[cfg(test)]
32-
/// Ticket constructor
33-
pub fn new(vrfproof: VRFProof) -> Self {
34-
Self { vrfproof }
35-
}
36-
}
37-
3831
#[cfg(test)]
3932
impl quickcheck::Arbitrary for Ticket {
4033
fn arbitrary(g: &mut quickcheck::Gen) -> Self {

src/blocks/vrf_proof.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,14 @@ use get_size2::GetSize;
66
use serde::{Deserialize, Serialize};
77

88
/// The output from running a VRF proof.
9-
#[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))]
9+
#[cfg_attr(
10+
test,
11+
derive(derive_quickcheck_arbitrary::Arbitrary, derive_more::Constructor)
12+
)]
1013
#[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Default, Serialize, Deserialize, Hash)]
1114
pub struct VRFProof(#[serde(with = "serde_byte_array")] pub Vec<u8>);
1215

1316
impl VRFProof {
14-
/// Creates a `VRFProof` from a raw vector.
15-
#[cfg(test)]
16-
pub fn new(output: Vec<u8>) -> Self {
17-
Self(output)
18-
}
19-
2017
/// Returns reference to underlying proof bytes.
2118
pub fn as_bytes(&self) -> &[u8] {
2219
&self.0

src/chain/snapshot_format.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<'de> Deserialize<'de> for FilecoinSnapshotVersion {
4343
}
4444

4545
/// Defined in <https://github.com/filecoin-project/FIPs/blob/98e33b9fa306959aa0131519eb4cc155522b2081/FRCs/frc-0108.md#snapshotmetadata>
46-
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
46+
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, derive_more::Constructor)]
4747
#[serde(rename_all = "PascalCase")]
4848
pub struct FilecoinSnapshotMetadata {
4949
/// Snapshot version
@@ -55,18 +55,6 @@ pub struct FilecoinSnapshotMetadata {
5555
}
5656

5757
impl FilecoinSnapshotMetadata {
58-
pub fn new(
59-
version: FilecoinSnapshotVersion,
60-
head_tipset_key: NonEmpty<Cid>,
61-
f3_data: Option<Cid>,
62-
) -> Self {
63-
Self {
64-
version,
65-
head_tipset_key,
66-
f3_data,
67-
}
68-
}
69-
7058
pub fn new_v2(head_tipset_key: NonEmpty<Cid>, f3_data: Option<Cid>) -> Self {
7159
Self::new(FilecoinSnapshotVersion::V2, head_tipset_key, f3_data)
7260
}

src/chain_sync/metrics.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,9 @@ pub static INVALID_TIPSET_TOTAL: LazyLock<Counter> = LazyLock::new(|| {
4545
metric
4646
});
4747

48-
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
48+
#[derive(Clone, Debug, Hash, PartialEq, Eq, derive_more::Constructor)]
4949
pub struct Libp2pMessageKindLabel(&'static str);
5050

51-
impl Libp2pMessageKindLabel {
52-
pub const fn new(kind: &'static str) -> Self {
53-
Self(kind)
54-
}
55-
}
56-
5751
impl EncodeLabelSet for Libp2pMessageKindLabel {
5852
fn encode(&self, mut encoder: LabelSetEncoder) -> Result<(), std::fmt::Error> {
5953
let mut label_encoder = encoder.encode_label();

src/chain_sync/network_context.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const MAX_CONCURRENT_CHAIN_EXCHANGE_REQUESTS: usize = 2;
4747
/// Context used in chain sync to handle network requests.
4848
/// This contains the peer manager, P2P service interface, and [`Blockstore`]
4949
/// required to make network requests.
50+
#[derive(derive_more::Constructor)]
5051
pub struct SyncNetworkContext<DB> {
5152
/// Channel to send network messages through P2P service
5253
network_send: flume::Sender<NetworkMessage>,
@@ -118,18 +119,6 @@ impl<DB> SyncNetworkContext<DB>
118119
where
119120
DB: Blockstore,
120121
{
121-
pub fn new(
122-
network_send: flume::Sender<NetworkMessage>,
123-
peer_manager: Arc<PeerManager>,
124-
db: Arc<DB>,
125-
) -> Self {
126-
Self {
127-
network_send,
128-
peer_manager,
129-
db,
130-
}
131-
}
132-
133122
/// Returns a reference to the peer manager of the network context.
134123
pub fn peer_manager(&self) -> &PeerManager {
135124
self.peer_manager.as_ref()

src/db/blockstore_with_read_cache.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ impl BlockstoreReadCacheStats for DefaultBlockstoreReadCacheStats {
7272
}
7373
}
7474

75+
#[derive(derive_more::Constructor)]
7576
pub struct BlockstoreWithReadCache<
7677
DB: Blockstore,
7778
CACHE: BlockstoreReadCache,
@@ -85,14 +86,6 @@ pub struct BlockstoreWithReadCache<
8586
impl<DB: Blockstore, CACHE: BlockstoreReadCache, STATS: BlockstoreReadCacheStats>
8687
BlockstoreWithReadCache<DB, CACHE, STATS>
8788
{
88-
pub fn new(db: DB, cache: CACHE, stats: Option<STATS>) -> Self {
89-
Self {
90-
inner: db,
91-
cache,
92-
stats,
93-
}
94-
}
95-
9689
pub fn stats(&self) -> Option<&STATS> {
9790
self.stats.as_ref()
9891
}

src/fil_cns/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub enum FilecoinConsensusError {
5757
ForestEncoding(#[from] ForestEncodingError),
5858
}
5959

60+
#[derive(derive_more::Constructor)]
6061
pub struct FilecoinConsensus {
6162
/// `Drand` randomness beacon
6263
///
@@ -67,10 +68,6 @@ pub struct FilecoinConsensus {
6768
}
6869

6970
impl FilecoinConsensus {
70-
pub fn new(beacon: Arc<BeaconSchedule>) -> Self {
71-
Self { beacon }
72-
}
73-
7471
pub async fn validate_block<DB: Blockstore + Sync + Send + 'static>(
7572
&self,
7673
state_manager: Arc<StateManager<DB>>,

src/key_management/keystore.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type SaltByteArray = [u8; RECOMMENDED_SALT_LEN];
4141
/// `KeyInfo` structure, this contains the type of key (stored as a string) and
4242
/// the private key. Note how the private key is stored as a byte vector
4343
#[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))]
44-
#[derive(Clone, PartialEq, Debug, Eq, Serialize, Deserialize)]
44+
#[derive(Clone, PartialEq, Debug, Eq, Serialize, Deserialize, derive_more::Constructor)]
4545
pub struct KeyInfo {
4646
key_type: SignatureType,
4747
// Vec<u8> is used because The private keys for BLS and SECP256K1 are not of the same type
@@ -55,14 +55,6 @@ pub struct PersistentKeyInfo {
5555
}
5656

5757
impl KeyInfo {
58-
/// Return a new `KeyInfo` given the key type and private key
59-
pub fn new(key_type: SignatureType, private_key: Vec<u8>) -> Self {
60-
KeyInfo {
61-
key_type,
62-
private_key,
63-
}
64-
}
65-
6658
/// Return a reference to the key's signature type
6759
pub fn key_type(&self) -> &SignatureType {
6860
&self.key_type

src/message_pool/msgpool/provider.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,12 @@ pub trait Provider {
6262

6363
/// This is the default Provider implementation that will be used for the
6464
/// `mpool` RPC.
65+
#[derive(derive_more::Constructor)]
6566
pub struct MpoolRpcProvider<DB> {
6667
subscriber: Publisher<HeadChange>,
6768
sm: Arc<StateManager<DB>>,
6869
}
6970

70-
impl<DB> MpoolRpcProvider<DB>
71-
where
72-
DB: Blockstore,
73-
{
74-
pub fn new(subscriber: Publisher<HeadChange>, sm: Arc<StateManager<DB>>) -> Self {
75-
MpoolRpcProvider { subscriber, sm }
76-
}
77-
}
78-
7971
#[async_trait]
8072
impl<DB> Provider for MpoolRpcProvider<DB>
8173
where

src/metrics/mod.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,11 @@ pub struct RpcMethodLabel {
169169
pub method: String,
170170
}
171171

172-
#[derive(Clone, Debug, Hash, PartialEq, Eq, EncodeLabelSet)]
172+
#[derive(Clone, Debug, Hash, PartialEq, Eq, EncodeLabelSet, derive_more::Constructor)]
173173
pub struct KindLabel {
174174
kind: &'static str,
175175
}
176176

177-
impl KindLabel {
178-
pub const fn new(kind: &'static str) -> Self {
179-
Self { kind }
180-
}
181-
}
182-
183177
pub mod values {
184178
use super::KindLabel;
185179

0 commit comments

Comments
 (0)