Skip to content

Commit

Permalink
add strict encoding for PublicOfferId (#195)
Browse files Browse the repository at this point in the history
* add strict encoding for PublicOfferId

* update changelog
  • Loading branch information
Lederstrumpf authored Dec 5, 2021
1 parent 5bf5c7a commit bd072a2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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

0 comments on commit bd072a2

Please sign in to comment.