Skip to content

Commit

Permalink
refac: Replace hashchain's register_service with from_operation
Browse files Browse the repository at this point in the history
  • Loading branch information
jns-ps committed Oct 30, 2024
1 parent 50a40d0 commit aeebc35
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 20 deletions.
15 changes: 1 addition & 14 deletions crates/common/src/hashchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ use std::{

use crate::{
keys::VerifyingKey,
operation::{
AddDataArgs, CreateAccountArgs, KeyOperationArgs, Operation, RegisterServiceArgs,
ServiceChallenge, ServiceChallengeInput,
},
operation::{AddDataArgs, KeyOperationArgs, Operation},
tree::{Digest, Hasher},
};

Expand Down Expand Up @@ -69,16 +66,6 @@ impl Hashchain {
Ok(hc)
}

pub fn register_service(id: String, challenge: ServiceChallenge) -> Result<Hashchain> {
let mut hc = Hashchain::empty(id.clone());
let operation = Operation::RegisterService(RegisterServiceArgs {
id,
creation_gate: challenge,
});
hc.perform_operation(operation)?;
Ok(hc)
}

pub fn empty(id: String) -> Self {
Self {
id,
Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ impl TestTreeState {
pub fn register_service(&mut self, service_id: String) -> Service {
let service_key = create_mock_signing_key();

let hashchain = Hashchain::register_service(
let hashchain = Hashchain::from_operation(Operation::new_register_service(
service_id.clone(),
ServiceChallenge::from(service_key.clone()),
)
))
.unwrap();

let key_hash = hashchain.get_keyhash();
Expand Down
6 changes: 2 additions & 4 deletions crates/common/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,7 @@ where
self.insert(account_key_hash, new_account_chain)?,
))
}
Operation::RegisterService(RegisterServiceArgs {
id, creation_gate, ..
}) => {
Operation::RegisterService(RegisterServiceArgs { id, .. }) => {
let hashed_id = Digest::hash(id);
let key_hash = KeyHash::with::<Hasher>(hashed_id);

Expand All @@ -483,7 +481,7 @@ where
};

debug!("creating new hashchain for service id {}", id);
let chain = Hashchain::register_service(id.clone(), creation_gate.clone())?;
let chain = Hashchain::from_operation(operation.clone())?;

Ok(Proof::Insert(
self.insert(KeyHash::with::<Hasher>(hashed_id), chain)?,
Expand Down

0 comments on commit aeebc35

Please sign in to comment.