Skip to content

Commit

Permalink
return errors instead of unwrapping in plan_builder
Browse files Browse the repository at this point in the history
  • Loading branch information
lamafab committed Sep 19, 2023
1 parent 3542f08 commit 4c84a49
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions rust/tw_bitcoin/src/modules/plan_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,22 @@ impl BitcoinPlanBuilder {
proto: Proto::mod_ComposePlan::ComposeBrc20Plan<'_>,
) -> Result<Proto::mod_TransactionPlan::Brc20Plan<'static>> {
// Hard-clones
let inscription = proto.inscription.unwrap();
let inscription = proto
.inscription
.ok_or_else(|| Error::from(Proto::Error::Error_missing_inscription))?;

let brc20_info = InputBrc20Inscription {
one_prevout: inscription.one_prevout,
inscribe_to: inscription.inscribe_to.to_vec().into(),
ticker: inscription.ticker.to_string().into(),
transfer_amount: inscription.transfer_amount,
};

let tagged_output = super::utils::hard_clone_proto_output(proto.tagged_output.unwrap());
let tagged_output = super::utils::hard_clone_proto_output(
proto
.tagged_output
.ok_or_else(|| Error::from(Proto::Error::Error_missing_tagged_output))?,
);

// First, we create the reveal transaction in order to calculate its input requirement (fee + dust limit).

Expand Down
2 changes: 2 additions & 0 deletions src/proto/BitcoinV2.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ enum Error {
Error_missing_input_builder = 13;
Error_missing_output_builder = 14;
Error_missing_recipient = 15;
Error_missing_inscription = 41;
Error_missing_tagged_output = 42;
Error_legacy_p2tr_invalid_variant = 16;
Error_legacy_no_spending_script_provided = 17;
Error_legacy_expected_redeem_script = 18;
Expand Down

0 comments on commit 4c84a49

Please sign in to comment.