feat: add psbt related errors
This commit is contained in:
parent
ab2e97e782
commit
0e617bc986
@ -82,6 +82,12 @@ interface TransactionError {
|
|||||||
OtherTransactionError();
|
OtherTransactionError();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[Error]
|
||||||
|
interface PsbtParseError {
|
||||||
|
PsbtEncoding(string e);
|
||||||
|
Base64Encoding(string e);
|
||||||
|
};
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// bdk crate - types module
|
// bdk crate - types module
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
@ -424,7 +430,7 @@ interface Transaction {
|
|||||||
};
|
};
|
||||||
|
|
||||||
interface PartiallySignedTransaction {
|
interface PartiallySignedTransaction {
|
||||||
[Throws=Alpha3Error]
|
[Throws=PsbtParseError]
|
||||||
constructor(string psbt_base64);
|
constructor(string psbt_base64);
|
||||||
|
|
||||||
string serialize();
|
string serialize();
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::error::{Alpha3Error, TransactionError};
|
use crate::error::{PsbtParseError, TransactionError};
|
||||||
use crate::error::AddressError;
|
use crate::error::AddressError;
|
||||||
|
|
||||||
use bdk::bitcoin::address::{NetworkChecked, NetworkUnchecked};
|
use bdk::bitcoin::address::{NetworkChecked, NetworkUnchecked};
|
||||||
@ -195,10 +195,10 @@ pub struct PartiallySignedTransaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PartiallySignedTransaction {
|
impl PartiallySignedTransaction {
|
||||||
pub(crate) fn new(psbt_base64: String) -> Result<Self, Alpha3Error> {
|
pub(crate) fn new(psbt_base64: String) -> Result<Self, PsbtParseError> {
|
||||||
let psbt: BdkPartiallySignedTransaction =
|
let psbt: BdkPartiallySignedTransaction =
|
||||||
BdkPartiallySignedTransaction::from_str(&psbt_base64)
|
BdkPartiallySignedTransaction::from_str(&psbt_base64)?;
|
||||||
.map_err(|_| Alpha3Error::Generic)?;
|
// .map_err(|_| Alpha3Error::Generic)?;
|
||||||
|
|
||||||
Ok(PartiallySignedTransaction {
|
Ok(PartiallySignedTransaction {
|
||||||
inner: Mutex::new(psbt),
|
inner: Mutex::new(psbt),
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
use crate::bitcoin::OutPoint;
|
use crate::bitcoin::OutPoint;
|
||||||
|
|
||||||
use bdk::chain::tx_graph::CalculateFeeError as BdkCalculateFeeError;
|
use bdk::chain::tx_graph::CalculateFeeError as BdkCalculateFeeError;
|
||||||
use bdk_esplora::esplora_client::Error as BdkEsploraError;
|
use bdk_esplora::esplora_client::{Error as BdkEsploraError};
|
||||||
|
|
||||||
|
use bdk::bitcoin::psbt::PsbtParseError as BdkPsbtParseError;
|
||||||
use bdk::bitcoin::Network;
|
use bdk::bitcoin::Network;
|
||||||
use bdk::descriptor::DescriptorError;
|
use bdk::descriptor::DescriptorError;
|
||||||
use bdk::wallet::error::{BuildFeeBumpError, CreateTxError};
|
use bdk::wallet::error::{BuildFeeBumpError, CreateTxError};
|
||||||
@ -194,6 +195,29 @@ pub enum TransactionError {
|
|||||||
OtherTransactionError,
|
OtherTransactionError,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
pub enum PsbtParseError {
|
||||||
|
#[error("error in internal PSBT data structure: {e}")]
|
||||||
|
PsbtEncoding { e: String },
|
||||||
|
|
||||||
|
#[error("error in PSBT base64 encoding: {e}")]
|
||||||
|
Base64Encoding { e: String },
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<BdkPsbtParseError> for PsbtParseError {
|
||||||
|
fn from(error: BdkPsbtParseError) -> Self {
|
||||||
|
match error {
|
||||||
|
BdkPsbtParseError::PsbtEncoding(e) => PsbtParseError::PsbtEncoding { e: e.to_string() },
|
||||||
|
BdkPsbtParseError::Base64Encoding(e) => {
|
||||||
|
PsbtParseError::Base64Encoding { e: e.to_string() }
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
unreachable!("this is required because of the non-exhaustive enum in rust-bitcoin")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<BdkFileError> for WalletCreationError {
|
impl From<BdkFileError> for WalletCreationError {
|
||||||
fn from(error: BdkFileError) -> Self {
|
fn from(error: BdkFileError) -> Self {
|
||||||
match error {
|
match error {
|
||||||
@ -340,12 +364,10 @@ impl From<bdk::bitcoin::address::Error> for AddressError {
|
|||||||
AddressError::MalformedWitnessVersion
|
AddressError::MalformedWitnessVersion
|
||||||
}
|
}
|
||||||
bdk::bitcoin::address::Error::InvalidWitnessProgramLength(length) => {
|
bdk::bitcoin::address::Error::InvalidWitnessProgramLength(length) => {
|
||||||
let length = length as u64;
|
AddressError::InvalidWitnessProgramLength { length: length as u64 }
|
||||||
AddressError::InvalidWitnessProgramLength { length }
|
|
||||||
}
|
}
|
||||||
bdk::bitcoin::address::Error::InvalidSegwitV0ProgramLength(length) => {
|
bdk::bitcoin::address::Error::InvalidSegwitV0ProgramLength(length) => {
|
||||||
let length = length as u64;
|
AddressError::InvalidSegwitV0ProgramLength { length: length as u64 }
|
||||||
AddressError::InvalidSegwitV0ProgramLength { length }
|
|
||||||
}
|
}
|
||||||
bdk::bitcoin::address::Error::UncompressedPubkey => AddressError::UncompressedPubkey,
|
bdk::bitcoin::address::Error::UncompressedPubkey => AddressError::UncompressedPubkey,
|
||||||
bdk::bitcoin::address::Error::ExcessiveScriptSize => AddressError::ExcessiveScriptSize,
|
bdk::bitcoin::address::Error::ExcessiveScriptSize => AddressError::ExcessiveScriptSize,
|
||||||
@ -358,12 +380,10 @@ impl From<bdk::bitcoin::address::Error> for AddressError {
|
|||||||
found,
|
found,
|
||||||
address,
|
address,
|
||||||
} => {
|
} => {
|
||||||
// let address = address.to_string();
|
|
||||||
let address = format!("{:?}", address);
|
|
||||||
AddressError::NetworkValidation {
|
AddressError::NetworkValidation {
|
||||||
required,
|
required,
|
||||||
found,
|
found,
|
||||||
address,
|
address: format!("{:?}", address),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => AddressError::OtherAddressError,
|
_ => AddressError::OtherAddressError,
|
||||||
@ -379,9 +399,10 @@ impl From<bdk::bitcoin::consensus::encode::Error> for TransactionError {
|
|||||||
TransactionError::OversizedVectorAllocation
|
TransactionError::OversizedVectorAllocation
|
||||||
}
|
}
|
||||||
bdk::bitcoin::consensus::encode::Error::InvalidChecksum { expected, actual } => {
|
bdk::bitcoin::consensus::encode::Error::InvalidChecksum { expected, actual } => {
|
||||||
let expected = DisplayHex::to_lower_hex_string(&expected);
|
TransactionError::InvalidChecksum {
|
||||||
let actual = DisplayHex::to_lower_hex_string(&actual);
|
expected: DisplayHex::to_lower_hex_string(&expected),
|
||||||
TransactionError::InvalidChecksum { expected, actual }
|
actual: DisplayHex::to_lower_hex_string(&actual),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
bdk::bitcoin::consensus::encode::Error::NonMinimalVarInt => {
|
bdk::bitcoin::consensus::encode::Error::NonMinimalVarInt => {
|
||||||
TransactionError::NonMinimalVarInt
|
TransactionError::NonMinimalVarInt
|
||||||
|
@ -19,6 +19,7 @@ use crate::error::CalculateFeeError;
|
|||||||
use crate::error::EsploraError;
|
use crate::error::EsploraError;
|
||||||
use crate::error::FeeRateError;
|
use crate::error::FeeRateError;
|
||||||
use crate::error::PersistenceError;
|
use crate::error::PersistenceError;
|
||||||
|
use crate::error::PsbtParseError;
|
||||||
use crate::error::TransactionError;
|
use crate::error::TransactionError;
|
||||||
use crate::error::WalletCreationError;
|
use crate::error::WalletCreationError;
|
||||||
use crate::esplora::EsploraClient;
|
use crate::esplora::EsploraClient;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user