refactor: use tuple struct for psbt type
This commit is contained in:
parent
d0514f678e
commit
00a8e1ba8b
@ -186,20 +186,16 @@ impl From<&Transaction> for BdkTransaction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Psbt {
|
pub struct Psbt(pub(crate) Mutex<BdkPsbt>);
|
||||||
pub(crate) inner: Mutex<BdkPsbt>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Psbt {
|
impl Psbt {
|
||||||
pub(crate) fn new(psbt_base64: String) -> Result<Self, PsbtParseError> {
|
pub(crate) fn new(psbt_base64: String) -> Result<Self, PsbtParseError> {
|
||||||
let psbt: BdkPsbt = BdkPsbt::from_str(&psbt_base64)?;
|
let psbt: BdkPsbt = BdkPsbt::from_str(&psbt_base64)?;
|
||||||
Ok(Psbt {
|
Ok(Psbt(Mutex::new(psbt)))
|
||||||
inner: Mutex::new(psbt),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn serialize(&self) -> String {
|
pub(crate) fn serialize(&self) -> String {
|
||||||
let psbt = self.inner.lock().unwrap().clone();
|
let psbt = self.0.lock().unwrap().clone();
|
||||||
psbt.to_string()
|
psbt.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +206,7 @@ impl Psbt {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
pub(crate) fn extract_tx(&self) -> Result<Arc<Transaction>, ExtractTxError> {
|
pub(crate) fn extract_tx(&self) -> Result<Arc<Transaction>, ExtractTxError> {
|
||||||
let tx: BdkTransaction = self.inner.lock().unwrap().clone().extract_tx()?;
|
let tx: BdkTransaction = self.0.lock().unwrap().clone().extract_tx()?;
|
||||||
let transaction: Transaction = tx.into();
|
let transaction: Transaction = tx.into();
|
||||||
Ok(Arc::new(transaction))
|
Ok(Arc::new(transaction))
|
||||||
}
|
}
|
||||||
@ -254,9 +250,7 @@ impl Psbt {
|
|||||||
|
|
||||||
impl From<BdkPsbt> for Psbt {
|
impl From<BdkPsbt> for Psbt {
|
||||||
fn from(psbt: BdkPsbt) -> Self {
|
fn from(psbt: BdkPsbt) -> Self {
|
||||||
Psbt {
|
Psbt(Mutex::new(psbt))
|
||||||
inner: Mutex::new(psbt),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ impl Wallet {
|
|||||||
psbt: Arc<Psbt>,
|
psbt: Arc<Psbt>,
|
||||||
// sign_options: Option<SignOptions>,
|
// sign_options: Option<SignOptions>,
|
||||||
) -> Result<bool, SignerError> {
|
) -> Result<bool, SignerError> {
|
||||||
let mut psbt = psbt.inner.lock().unwrap();
|
let mut psbt = psbt.0.lock().unwrap();
|
||||||
self.get_wallet()
|
self.get_wallet()
|
||||||
.sign(&mut psbt, SignOptions::default())
|
.sign(&mut psbt, SignOptions::default())
|
||||||
.map_err(SignerError::from)
|
.map_err(SignerError::from)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user