Skip to content

Commit d0bdabc

Browse files
feat(clarity): More clear naming (#23)
* borrow the config * clarify method names * fix api * fix typo
1 parent 8c24cbc commit d0bdabc

File tree

8 files changed

+38
-31
lines changed

8 files changed

+38
-31
lines changed

cli/src/subcmds/plog.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ pub async fn go(cmd: Command, _config: &Config) -> Result<(), Error> {
193193
.hash(vlad_cid_hash)
194194
.build(),
195195
)
196-
.entrykey(parse_key_params(&entry_key_codec, Some("/entrykey"))?)
196+
.first_entry_params(parse_key_params(&entry_key_codec, Some("/entrykey"))?)
197197
.unlock(unlock_script)
198198
.lock(lock_script.clone())
199199
.additional_ops(additional_ops) // Add all operations at once

crates/bs-peer/src/peer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ where
287287

288288
// Create BetterSign instance (no lock held)
289289
let bs = BetterSign::new(
290-
config.clone(),
290+
&config,
291291
self.key_provider.clone(),
292292
self.key_provider.clone(),
293293
)
@@ -341,7 +341,7 @@ where
341341
.build()
342342
.into(),
343343
)
344-
.entrykey(
344+
.first_entry_params(
345345
FirstEntryKeyParams::builder()
346346
.codec(Codec::Ed25519Priv)
347347
.build()

crates/bs-peer/src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ pub async fn run_in_memory_blockstore_test() {
277277
.build()
278278
.into(),
279279
)
280-
.entrykey(
280+
.first_entry_params(
281281
FirstEntryKeyParams::builder()
282282
.codec(Codec::Ed25519Priv)
283283
.build()
@@ -376,7 +376,7 @@ pub async fn run_network_blockstore_test() {
376376
.build()
377377
.into(),
378378
)
379-
.entrykey(
379+
.first_entry_params(
380380
FirstEntryKeyParams::builder()
381381
.codec(Codec::Ed25519Priv)
382382
.build()

crates/bs/src/better_sign.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ where
7373
S: MultiSigner<E>,
7474
{
7575
/// Create a new BetterSign instance with the given configuration.
76-
pub async fn new(config: open::Config, mut key_manager: KM, signer: S) -> Result<Self, E> {
77-
let plog = open::open_plog_core(&config, &mut key_manager, &signer).await?;
76+
pub async fn new(config: &open::Config, mut key_manager: KM, signer: S) -> Result<Self, E> {
77+
let plog = open::open_plog_core(config, &mut key_manager, &signer).await?;
7878
Ok(Self {
7979
plog,
8080
key_manager,
@@ -110,7 +110,7 @@ where
110110
/// # Errors
111111
///
112112
/// Returns an error if the provenance log creation fails.
113-
pub fn new_sync(config: open::Config, key_manager: KM, signer: S) -> Result<Self, E> {
113+
pub fn new_sync(config: &open::Config, key_manager: KM, signer: S) -> Result<Self, E> {
114114
futures::executor::block_on(Self::new(config, key_manager, signer))
115115
}
116116

@@ -146,7 +146,7 @@ mod tests {
146146
.build()
147147
.into(),
148148
)
149-
.entrykey(
149+
.first_entry_params(
150150
FirstEntryKeyParams::builder()
151151
.codec(Codec::Ed25519Priv)
152152
.build()
@@ -165,7 +165,7 @@ mod tests {
165165
let key_manager = InMemoryKeyManager::<Error>::default();
166166
let signer = key_manager.clone();
167167

168-
let bs = BetterSign::new(config, key_manager, signer)
168+
let bs = BetterSign::new(&config, key_manager, signer)
169169
.await
170170
.expect("Failed to create BetterSign");
171171

@@ -184,7 +184,7 @@ mod tests {
184184
.build()
185185
.into(),
186186
)
187-
.entrykey(
187+
.first_entry_params(
188188
FirstEntryKeyParams::builder()
189189
.codec(Codec::Ed25519Priv)
190190
.build()
@@ -203,7 +203,7 @@ mod tests {
203203
let key_manager = InMemoryKeyManager::<Error>::default();
204204
let signer = key_manager.clone();
205205

206-
let mut bs = BetterSign::new(open_config, key_manager, signer)
206+
let mut bs = BetterSign::new(&open_config, key_manager, signer)
207207
.await
208208
.expect("Failed to create BetterSign");
209209

@@ -239,7 +239,7 @@ mod tests {
239239
.build()
240240
.into(),
241241
)
242-
.entrykey(
242+
.first_entry_params(
243243
FirstEntryKeyParams::builder()
244244
.codec(Codec::Ed25519Priv)
245245
.build()
@@ -258,8 +258,8 @@ mod tests {
258258
let key_manager = InMemoryKeyManager::<Error>::default();
259259
let signer = key_manager.clone();
260260

261-
let bs =
262-
BetterSign::new_sync(config, key_manager, signer).expect("Failed to create BetterSign");
261+
let bs = BetterSign::new_sync(&config, key_manager, signer)
262+
.expect("Failed to create BetterSign");
263263

264264
// Verify the plog was created
265265
assert!(!bs.plog().entries.is_empty());

crates/bs/src/ops/open.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ where
129129
key_manager.preprocess_vlad(&vlad).await?;
130130

131131
// 2. Extract entry key parameters and prepare signing
132-
let entrykey_params = &config.entrykey();
132+
let entrykey_params = &config.first_entry();
133133
let (codec, threshold, limit) = extract_key_params::<E>(entrykey_params)?;
134134

135135
// Get the public key and signing function
@@ -430,7 +430,7 @@ mod tests {
430430
let config = Config::builder() // Uses default type parameter FirstEntryKeyParams
431431
.vlad(vlad_params)
432432
.pubkey(pubkey_params.into())
433-
.entrykey(entry_key_params.into())
433+
.first_entry_params(entry_key_params.into())
434434
.lock(Script::Code(Key::default(), lock))
435435
.unlock(Script::Code(Key::default(), unlock))
436436
.build();

crates/bs/src/ops/open/config.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ pub struct Config<T: ValidatedKeyParams = FirstEntryKeyParams> {
1414
/// the vlad key and cid params
1515
vlad: VladParams<T>,
1616

17-
/// the entry key params
18-
entrykey: OpParams,
17+
/// First entry [OpParams]
18+
first_entry_params: OpParams,
1919

2020
/// the pubkey params
2121
pubkey: OpParams,
@@ -46,9 +46,11 @@ impl<T: ValidatedKeyParams> Config<T> {
4646
&self.first_lock
4747
}
4848

49-
/// Get the entry key params
50-
pub fn entrykey(&self) -> &OpParams {
51-
&self.entrykey
49+
/// Get the (first) entry key params
50+
///
51+
/// Because this is the Open Config, this will always be the first entry
52+
pub fn first_entry(&self) -> &OpParams {
53+
&self.first_entry_params
5254
}
5355

5456
/// Get the pubkey params
@@ -87,7 +89,12 @@ impl<T: ValidatedKeyParams> From<Config<T>> for Vec<OpParams> {
8789
// Gather all the operations from this config so we can store their values against their Cids
8890
let (vlad_key_op, vlad_cid_op): (OpParams, OpParams) = config.vlad.into();
8991

90-
let mut ops = vec![vlad_key_op, vlad_cid_op, config.entrykey, config.pubkey];
92+
let mut ops = vec![
93+
vlad_key_op,
94+
vlad_cid_op,
95+
config.first_entry_params,
96+
config.pubkey,
97+
];
9198
ops.extend(config.additional_ops);
9299
ops
93100
}
@@ -107,7 +114,7 @@ mod tests {
107114
// Create a Config with default type parameter (FirstEntryKeyParams)
108115
let config = Config::builder()
109116
.vlad(Default::default())
110-
.entrykey(Default::default())
117+
.first_entry_params(Default::default())
111118
.pubkey(Default::default())
112119
.lock(Script::Code(Key::default(), "test lock".to_string()))
113120
.unlock(Script::Code(Key::default(), "test unlock".to_string()))
@@ -126,7 +133,7 @@ mod tests {
126133
fn test_config_with_recovery_key_params() {
127134
let config: Config<RecoveryKeyParams> = Config::<RecoveryKeyParams>::builder()
128135
.vlad(VladParams::<RecoveryKeyParams>::builder().build())
129-
.entrykey(Default::default())
136+
.first_entry_params(Default::default())
130137
.pubkey(Default::default())
131138
.lock(Script::Code(Key::default(), "test lock".to_string()))
132139
.unlock(Script::Code(Key::default(), "test unlock".to_string()))
@@ -150,7 +157,7 @@ mod tests {
150157
// Create Config and set VladParams
151158
let config = Config::<FirstEntryKeyParams>::builder()
152159
.vlad(Default::default())
153-
.entrykey(Default::default())
160+
.first_entry_params(Default::default())
154161
.pubkey(Default::default())
155162
.lock(Script::Code(Key::default(), "test lock".to_string()))
156163
.unlock(Script::Code(Key::default(), "test unlock".to_string()))
@@ -177,7 +184,7 @@ mod tests {
177184
// Create a Config
178185
let config = Config::builder()
179186
.vlad(Default::default())
180-
.entrykey(Default::default())
187+
.first_entry_params(Default::default())
181188
.pubkey(Default::default())
182189
.lock(Script::Code(Key::default(), "test lock".to_string()))
183190
.unlock(Script::Code(Key::default(), "test unlock".to_string()))
@@ -199,7 +206,7 @@ mod tests {
199206
// Create a Config
200207
let config = Config::builder()
201208
.vlad(Default::default())
202-
.entrykey(Default::default())
209+
.first_entry_params(Default::default())
203210
.pubkey(Default::default())
204211
.lock(Script::Code(Key::default(), "test lock".to_string()))
205212
.unlock(Script::Code(Key::default(), "test unlock".to_string()))
@@ -219,7 +226,7 @@ mod tests {
219226
// This would be a compile error if we tried to use the wrong type
220227
let config = Config::<FirstEntryKeyParams>::builder()
221228
.vlad(vlad_params)
222-
.entrykey(Default::default())
229+
.first_entry_params(Default::default())
223230
.pubkey(Default::default())
224231
.lock(Script::Code(Key::default(), "test lock".to_string()))
225232
.unlock(Script::Code(Key::default(), "test unlock".to_string()))

crates/bs/src/ops/update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ mod tests {
399399
let open_config = open::Config::builder()
400400
.vlad(VladParams::<FirstEntryKeyParams>::default())
401401
.pubkey(pubkey_params.clone().into())
402-
.entrykey(
402+
.first_entry_params(
403403
FirstEntryKeyParams::builder()
404404
.codec(Codec::Ed25519Priv)
405405
.build()

crates/multicid/src/vlad.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl<'a> TryDecodeFrom<'a> for Vlad {
166166
if sigil != SIGIL {
167167
return Err(VladError::MissingSigil.into());
168168
}
169-
// decode the none
169+
// decode the nonce
170170
let (nonce, ptr) = Nonce::try_decode_from(ptr)?;
171171
// decode the cid
172172
let (cid, ptr) = Cid::try_decode_from(ptr)?;

0 commit comments

Comments
 (0)