Skip to content

Commit

Permalink
Merge branch 'prevtx'
Browse files Browse the repository at this point in the history
  • Loading branch information
benma committed Sep 18, 2024
2 parents 7abaa32 + 936a694 commit 77c967c
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 19 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG-npm.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

## 0.7.0
- btc: handle error when an input's previous transaction is required but missing

## 0.6.0

- btc: add support for multisig script configs
3 changes: 3 additions & 0 deletions CHANGELOG-rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

## 0.6.0
- btc: handle error when an input's previous transaction is required but missing

## 0.5.0

- btc: add `make_script_config_multisig()`
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bitbox-api"
authors = ["Marko Bencun <[email protected]>"]
version = "0.5.0"
version = "0.6.0"
homepage = "https://bitbox.swiss/"
repository = "https://github.com/BitBoxSwiss/bitbox-api-rs/"
readme = "README-rust.md"
Expand Down
2 changes: 1 addition & 1 deletion NPM_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.6.0
0.7.0
2 changes: 1 addition & 1 deletion sandbox/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 14 additions & 15 deletions src/btc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ pub struct TxInput {
pub prev_tx: Option<PrevTx>,
}

impl TxInput {
fn get_prev_tx(&self) -> Result<&PrevTx, Error> {
self.prev_tx.as_ref().ok_or(Error::BtcSign(
"input's previous transaction required but missing".into(),
))
}
}

#[derive(Debug, PartialEq)]
pub struct TxInternalOutput {
pub keypath: Keypath,
Expand Down Expand Up @@ -767,11 +775,8 @@ impl<R: Runtime> PairedBitBox<R> {
}
}
pb::btc_sign_next_response::Type::PrevtxInit => {
// TODO handle error
let prevtx: &PrevTx = transaction.inputs[next_response.index as usize]
.prev_tx
.as_ref()
.unwrap();
let prevtx: &PrevTx =
transaction.inputs[next_response.index as usize].get_prev_tx()?;
next_response = self
.get_next_response_nested(pb::btc_request::Request::PrevtxInit(
pb::BtcPrevTxInitRequest {
Expand All @@ -784,11 +789,8 @@ impl<R: Runtime> PairedBitBox<R> {
.await?;
}
pb::btc_sign_next_response::Type::PrevtxInput => {
// TODO handle error
let prevtx: &PrevTx = transaction.inputs[next_response.index as usize]
.prev_tx
.as_ref()
.unwrap();
let prevtx: &PrevTx =
transaction.inputs[next_response.index as usize].get_prev_tx()?;
let prevtx_input: &PrevTxInput =
&prevtx.inputs[next_response.prev_index as usize];
next_response = self
Expand All @@ -803,11 +805,8 @@ impl<R: Runtime> PairedBitBox<R> {
.await?;
}
pb::btc_sign_next_response::Type::PrevtxOutput => {
// TODO handle error
let prevtx: &PrevTx = transaction.inputs[next_response.index as usize]
.prev_tx
.as_ref()
.unwrap();
let prevtx: &PrevTx =
transaction.inputs[next_response.index as usize].get_prev_tx()?;
let prevtx_output: &PrevTxOutput =
&prevtx.outputs[next_response.prev_index as usize];
next_response = self
Expand Down
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ pub enum Error {
#[error("EIP-712 typed message processing error: {0}")]
#[cfg_attr(feature = "wasm", assoc(js_code = "eth-typed-message".into()))]
EthTypedMessage(String),
#[error("Bitcoin transaction signing error: {0}")]
#[cfg_attr(feature = "wasm", assoc(js_code = "btc-sign".into()))]
BtcSign(String),
}

impl From<communication::Error> for Error {
Expand Down

0 comments on commit 77c967c

Please sign in to comment.