Skip to content

Commit

Permalink
Proper error-handling and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kobby-pentangeli committed Mar 18, 2024
1 parent 122f4d7 commit 1bc88a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/inscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ use crate::{OrdError, OrdResult};
/// These are methods for encoding, decoding, and managing
/// the inscriptions, tailored to specific types (e.g. `Brc20`, `Nft`).
pub trait Inscription: DeserializeOwned {
/// Generates the redeem script from a script pubkey and the inscription.
///
/// # Errors
///
/// May return an `OrdError` if (de)serialization of any of the inscription fields
/// fails while appending the script to the builder.
fn generate_redeem_script(
&self,
builder: ScriptBuilder,
Expand Down
14 changes: 7 additions & 7 deletions src/inscription/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,44 +146,44 @@ impl Nft {
if let Some(content_type) = self.content_type.clone() {
builder = builder
.push_slice(constants::CONTENT_TYPE_TAG)
.push_slice(PushBytesBuf::try_from(content_type).unwrap());
.push_slice(PushBytesBuf::try_from(content_type)?);
}

if let Some(content_encoding) = self.content_encoding.clone() {
builder = builder
.push_slice(constants::CONTENT_ENCODING_TAG)
.push_slice(PushBytesBuf::try_from(content_encoding).unwrap());
.push_slice(PushBytesBuf::try_from(content_encoding)?);
}

if let Some(protocol) = self.metaprotocol.clone() {
builder = builder
.push_slice(constants::METAPROTOCOL_TAG)
.push_slice(PushBytesBuf::try_from(protocol).unwrap());
.push_slice(PushBytesBuf::try_from(protocol)?);
}

if let Some(parent) = self.parent.clone() {
builder = builder
.push_slice(constants::PARENT_TAG)
.push_slice(PushBytesBuf::try_from(parent).unwrap());
.push_slice(PushBytesBuf::try_from(parent)?);
}

if let Some(pointer) = self.pointer.clone() {
builder = builder
.push_slice(constants::POINTER_TAG)
.push_slice(PushBytesBuf::try_from(pointer).unwrap());
.push_slice(PushBytesBuf::try_from(pointer)?);
}

if let Some(metadata) = &self.metadata {
for chunk in metadata.chunks(520) {
builder = builder.push_slice(constants::METADATA_TAG);
builder = builder.push_slice(PushBytesBuf::try_from(chunk.to_vec()).unwrap());
builder = builder.push_slice(PushBytesBuf::try_from(chunk.to_vec())?);
}
}

if let Some(body) = &self.body {
builder = builder.push_slice(constants::BODY_TAG);
for chunk in body.chunks(520) {
builder = builder.push_slice(PushBytesBuf::try_from(chunk.to_vec()).unwrap());
builder = builder.push_slice(PushBytesBuf::try_from(chunk.to_vec())?);
}
}

Expand Down

0 comments on commit 1bc88a6

Please sign in to comment.