Skip to content
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

- Implement `FromStr` for `DealId` and `SwapId` by @TheCharlatan ([#307](https://github.com/farcaster-project/farcaster-core/pull/307/files)])

## [0.6.0] - 2022-12-13

### Added
Expand Down
9 changes: 9 additions & 0 deletions src/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//! and its concrete instances of swaps.

use std::io;
use std::str::FromStr;

use strict_encoding::{StrictDecode, StrictEncode};

Expand Down Expand Up @@ -64,6 +65,14 @@ impl From<DealId> for SwapId {
}
}

impl FromStr for SwapId {
type Err = uuid::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(Uuid::from_str(s)?))
}
}

impl Encodable for SwapId {
fn consensus_encode<W: io::Write>(&self, s: &mut W) -> Result<usize, io::Error> {
self.0.consensus_encode(s)
Expand Down
8 changes: 8 additions & 0 deletions src/trade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ impl From<uuid::Uuid> for DealId {
}
}

impl FromStr for DealId {
type Err = uuid::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(Uuid::from_str(s)?))
}
}

fixed_hash::construct_fixed_hash!(
/// Identify a deal by its content, internally store the hash of the deal serialized with
/// Farcaster consensus.
Expand Down