-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from radixdlt/rectify_review_suggestions
- Loading branch information
Showing
24 changed files
with
332 additions
and
350 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
mod batch_signing_response; | ||
mod batch_tx_batch_key_signing_request; | ||
mod parallel_batch_signing_request; | ||
mod serial_batch_signing_request; | ||
mod sign_with_factor_parallel_interactor; | ||
mod sign_with_factor_serial_interactor; | ||
mod mono_factor_sign_interactor; | ||
mod mono_factor_sign_request; | ||
mod mono_factor_sign_request_input; | ||
mod poly_factor_sign_interactor; | ||
mod poly_factor_sign_request; | ||
mod signature_collecting_interactors; | ||
mod signing_interactor; | ||
mod transaction_sign_request_input; | ||
|
||
pub use batch_signing_response::*; | ||
pub use batch_tx_batch_key_signing_request::*; | ||
pub use parallel_batch_signing_request::*; | ||
pub use serial_batch_signing_request::*; | ||
pub use sign_with_factor_parallel_interactor::*; | ||
pub use sign_with_factor_serial_interactor::*; | ||
pub use mono_factor_sign_interactor::*; | ||
pub use mono_factor_sign_request::*; | ||
pub use mono_factor_sign_request_input::*; | ||
pub use poly_factor_sign_interactor::*; | ||
pub use poly_factor_sign_request::*; | ||
pub use signature_collecting_interactors::*; | ||
pub use signing_interactor::*; | ||
pub use transaction_sign_request_input::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
...teractors/serial_batch_signing_request.rs → ...g/interactors/mono_factor_sign_request.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
use crate::prelude::*; | ||
|
||
/// A batch of transactions each batching over multiple keys (derivation paths) | ||
/// to sign each transaction with. | ||
#[derive(Clone, Debug, PartialEq, Eq, std::hash::Hash)] | ||
pub struct MonoFactorSignRequestInput { | ||
/// The ID of the factor source used to sign each per_transaction | ||
pub factor_source_id: FactorSourceIDFromHash, | ||
|
||
// The `factor_source_id` of each item must match `self.factor_source_id`. | ||
pub per_transaction: Vec<TransactionSignRequestInput>, | ||
} | ||
|
||
impl MonoFactorSignRequestInput { | ||
/// # Panics | ||
/// Panics if `per_transaction` is empty | ||
/// | ||
/// Also panics if `per_transaction` if the factor source id | ||
/// of each request does not match `factor_source_id`. | ||
pub fn new( | ||
factor_source_id: FactorSourceIDFromHash, | ||
per_transaction: IndexSet<TransactionSignRequestInput>, | ||
) -> Self { | ||
assert!( | ||
!per_transaction.is_empty(), | ||
"Invalid input. No transaction to sign, this is a programmer error." | ||
); | ||
|
||
assert!(per_transaction | ||
.iter() | ||
.all(|f| f.factor_source_id == factor_source_id), "Discprepancy! Input for one of the transactions has a mismatching FactorSourceID, this is a programmer error."); | ||
|
||
Self { | ||
factor_source_id, | ||
per_transaction: per_transaction.into_iter().collect(), | ||
} | ||
} | ||
|
||
pub fn factor_source_kind(&self) -> FactorSourceKind { | ||
self.factor_source_id.kind | ||
} | ||
} | ||
|
||
impl HasSampleValues for MonoFactorSignRequestInput { | ||
fn sample() -> Self { | ||
Self::new( | ||
FactorSourceIDFromHash::sample(), | ||
IndexSet::from_iter([TransactionSignRequestInput::sample()]), | ||
) | ||
} | ||
|
||
fn sample_other() -> Self { | ||
Self::new( | ||
FactorSourceIDFromHash::sample_other(), | ||
IndexSet::from_iter([TransactionSignRequestInput::sample_other()]), | ||
) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
type Sut = MonoFactorSignRequestInput; | ||
|
||
#[test] | ||
fn equality() { | ||
assert_eq!(Sut::sample(), Sut::sample()); | ||
assert_eq!(Sut::sample_other(), Sut::sample_other()); | ||
} | ||
|
||
#[test] | ||
fn inequality() { | ||
assert_ne!(Sut::sample(), Sut::sample_other()); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "Invalid input. No transaction to sign, this is a programmer error.")] | ||
fn panics_if_per_transaction_is_empty() { | ||
Sut::new(FactorSourceIDFromHash::sample(), IndexSet::new()); | ||
} | ||
|
||
#[test] | ||
#[should_panic( | ||
expected = "Discprepancy! Input for one of the transactions has a mismatching FactorSourceID, this is a programmer error." | ||
)] | ||
fn panics_if_factor_source_mismatch() { | ||
Sut::new( | ||
FactorSourceIDFromHash::sample(), | ||
IndexSet::from_iter([TransactionSignRequestInput::sample_other()]), | ||
); | ||
} | ||
} |
Oops, something went wrong.