Skip to content

Commit

Permalink
Merge pull request #158 from aspectron/mass-estimation-without-p2sh
Browse files Browse the repository at this point in the history
Calculate mass without p2sh
  • Loading branch information
saefstroem authored Feb 1, 2025
2 parents 4c5175d + b0702a5 commit e49f339
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions wallet/pskt/src/wasm/pskt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,30 @@ impl PSKT {
let network_id = NetworkType::from_str(&network_id).map_err(|e| Error::custom(format!("Invalid networkId: {}", e)))?;

let cloned_pskt = self.clone();
let extractor = cloned_pskt.extractor()?;
let state = extractor.state().clone().expect("Extractor state is not valid");
match state {
State::Extractor(pskt) => {
let tx =
pskt.extract_tx(&network_id.into()).map_err(|e| Error::custom(format!("Failed to extract transaction: {e}")))?;
Ok(tx.tx.mass())

let extractor = {
let finalizer = cloned_pskt.finalizer()?;

let finalizer_state = finalizer.state().clone().unwrap();

match finalizer_state {
State::Finalizer(pskt) => {
for input in pskt.inputs.iter() {
if input.redeem_script.is_some() {
return Err(Error::custom("Mass calculation is not supported for inputs with redeem scripts"));
}
}
let pskt = pskt
.finalize_sync(|inner: &Inner| -> Result<Vec<Vec<u8>>> { Ok(vec![vec![0u8, 65]; inner.inputs.len()]) })
.map_err(|e| Error::custom(format!("Failed to finalize PSKT: {e}")))?;
pskt.extractor()?
}
_ => panic!("Finalizer state is not valid"),
}
_ => panic!("Extractor state is not valid"),
}
};
let tx = extractor
.extract_tx_unchecked(&network_id.into())
.map_err(|e| Error::custom(format!("Failed to extract transaction: {e}")))?;
Ok(tx.tx.mass())
}
}

0 comments on commit e49f339

Please sign in to comment.