Skip to content

Commit

Permalink
Merge pull request #123 from xch-dev/fix-offers
Browse files Browse the repository at this point in the history
Fix offer prefix
  • Loading branch information
Rigidity authored Nov 11, 2024
2 parents 1b834e9 + 7b8531d commit 5437435
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion crates/chia-sdk-offers/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub fn encode_offer_data(offer: &[u8]) -> Result<String, OfferError> {
.into_iter()
.map(u5::try_from_u8)
.collect::<Result<Vec<_>, bech32::Error>>()?;
Ok(bech32::encode("offer1", data, Variant::Bech32m)?)
Ok(bech32::encode("offer", data, Variant::Bech32m)?)
}

pub fn decode_offer_data(offer: &str) -> Result<Vec<u8>, OfferError> {
Expand All @@ -23,3 +23,16 @@ pub fn decode_offer_data(offer: &str) -> Result<Vec<u8>, OfferError> {

Ok(bech32::convert_bits(&data, 5, 8, false)?)
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_encode_decode_offer_data() {
let offer = b"hello world";
let encoded = encode_offer_data(offer).unwrap();
let decoded = decode_offer_data(&encoded).unwrap();
assert_eq!(offer, decoded.as_slice());
}
}

0 comments on commit 5437435

Please sign in to comment.