Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add strict encoding for PublicOfferId #195

Merged
merged 2 commits into from
Dec 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `strict_encoding` implementation for `PublicOfferId` type ([#195](https://github.com/farcaster-project/farcaster-core/pull/195))

## [0.4.2] - 2021-12-05

### Added
Expand Down
15 changes: 15 additions & 0 deletions src/negotiation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,21 @@ impl<'de> Deserialize<'de> for PublicOfferId {
}
}

impl Encodable for PublicOfferId {
fn consensus_encode<W: io::Write>(&self, s: &mut W) -> Result<usize, io::Error> {
self.0.consensus_encode(s)
}
}

impl Decodable for PublicOfferId {
fn consensus_decode<D: io::Read>(d: &mut D) -> Result<Self, consensus::Error> {
let bytes: [u8; 32] = Decodable::consensus_decode(d)?;
Ok(Self::from_slice(&bytes))
}
}

impl_strict_encoding!(PublicOfferId);

/// A public offer is shared across [`TradeRole::Maker`]'s prefered network to signal is willing of
/// trading some assets at some conditions. The assets and condition are defined in the [`Offer`],
/// maker peer connection information are contained in the public offer.
Expand Down