Skip to content

Commit

Permalink
Merge pull request #168 from dusk-network/mocello/166_error
Browse files Browse the repository at this point in the history
Impl `From<DuskBytesError>` for `Error`
  • Loading branch information
moCello authored May 1, 2024
2 parents 03446b7 + 07320ea commit 861a3e0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `empty` method for the `Note` [#165]
- Add `From<DuskBytesError>` trait implementation for `Error` [#166]

## [0.27.0] - 2024-04-24

### Added
Expand Down Expand Up @@ -284,6 +289,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Canonical implementation shielded by feature.

<!-- ISSUES -->
[#166]: https://github.com/dusk-network/phoenix-core/issues/166
[#165]: https://github.com/dusk-network/phoenix-core/issues/165
[#156]: https://github.com/dusk-network/phoenix-core/issues/156
[#155]: https://github.com/dusk-network/phoenix-core/issues/155
[#152]: https://github.com/dusk-network/phoenix-core/issues/152
Expand Down
14 changes: 14 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ impl From<AesError> for Error {
}
}

impl From<DuskBytesError> for Error {
fn from(err: DuskBytesError) -> Self {
match err {
DuskBytesError::InvalidData => Error::InvalidData,
DuskBytesError::BadLength { found, expected } => {
Error::BadLength(found, expected)
}
DuskBytesError::InvalidChar { ch, index } => {
Error::InvalidChar(ch, index)
}
}
}
}

impl From<Error> for DuskBytesError {
fn from(err: Error) -> Self {
match err {
Expand Down
11 changes: 11 additions & 0 deletions src/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@ impl Note {
Self::new(rng, NoteType::Obfuscated, pk, value, blinding_factor)
}

/// Creates a new empty [`Note`]
pub fn empty() -> Self {
Self {
note_type: NoteType::Transparent,
value_commitment: JubJubExtended::default(),
stealth_address: StealthAddress::default(),
pos: 0,
encryption: [0; ENCRYPTION_SIZE],
}
}

fn decrypt_data(
&self,
vk: &ViewKey,
Expand Down

0 comments on commit 861a3e0

Please sign in to comment.