-
Notifications
You must be signed in to change notification settings - Fork 622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a utility method to psbt to compute find sighash type of a given input #838
Comments
Hi @sanket1729, I am new to contributing to this repository and a participant in Summer of Bitcoin. I would like to solve this issue. Also, am I going in the correct direction? just wanted to confirm impl Input {
/// Returns the ['EcdsaSigHashType'] if the sighash_type is None else
/// NonStandardSigHashType Error
pub fn ecdsa_hash_ty(&self) -> Result<EcdsaSigHashType, psbt::Error> {
if let Some(sighash_type_value) = self.sighash_type {
Err(Error::NonStandardSigHashType(sighash_type_value.inner))
} else {
Ok(EcdsaSigHashType::All)
}
}
/// Returns the ['SchnorrSigHashType'] if the sighash_type is None else
/// NonStandardSigHashType Error
pub fn schnorr_hash_ty(&self) -> Result<SchnorrSigHashType, psbt::Error> {
if let Some(sighash_type_value) = self.sighash_type {
Err(Error::NonStandardSigHashType(sighash_type_value.inner))
} else {
Ok(SchnorrSigHashType::All)
}
}
.... |
This doesn't look correct. I think it should be something like |
Hi @rish-singhal , thanks for taking the time to look at this. The algorithm should be
SImilarly for Schnorr. Also, note that the |
Hi thanks for your reply, does the following work? impl Input {
/// Returns sighash_type.ecdsa_hash_ty() is sighash_type exists else
/// ['EcdsaSigHashType::All']
pub fn ecdsa_hash_ty(&self) -> Result<EcdsaSigHashType, NonStandardSigHashType> {
if let Some(sighash_type) = self.sighash_type {
sighash_type.ecdsa_hash_ty()
} else {
Ok(EcdsaSigHashType::All)
}
}
/// Returns sighash_type.schnorr_hash_ty() is sighash_type exists else
/// ['SchnorrSigHashType::Defaul']
pub fn schnorr_hash_ty(&self) -> Result<SchnorrSigHashType, sighash::Error> {
if let Some(sighash_type) = self.sighash_type {
sighash_type.schnorr_hash_ty()
} else {
Ok(SchnorrSigHashType::Default)
}
}
... |
That looks good. I like match a bit more when |
Thanks! yes you are right, it makes it more explicit that it is a |
I don't think there are hard rules. I personally prefer functional style but there are cases when match looks better. I suspect this is one of them. For iterators, functional has better performance. Also my suggestion above is a bit complex, this is probably better: self.sighash_type
.map(|sighash_type| sighash_type.ecdsa_hash_ty())
.unwrap_or(Ok(EcdsaSigHashType::All)) |
@rish-singhal, I too prefer functional styles. Feel free to open a PR to start an implementation discussion there. |
Fixes rust-bitcoin#838: Add a utility method to psbt to compute find sighash type of a given input.
Fixes rust-bitcoin#838: Add a utility method to psbt to compute find sighash type of a given input.
Fixes rust-bitcoin#838: Add a utility method to psbt to compute find sighash type of a given input.
Fixes rust-bitcoin#838: Add a utility method to psbt to compute find sighash type of a given input.
fb04cab Add a method to psbt to compute find sighash type (Rishabh Singhal) Pull request description: Fixes #838: Add a utility method to psbt to compute find sighash type of a given input. For now, I have changed my previous implementation as discussed in #838 to functional style code as suggested by @Kixunil. ACKs for top commit: apoelstra: ACK fb04cab Kixunil: ACK fb04cab Tree-SHA512: 86184649e7a309348cb217347b82bf39c9997ae259fe7881322038a88bd04deab927bede1dd71d17496bac420353a3fd07e7d191ff4671a07754c02a38dd1319
For each psbt input, we have a field called sighash_ty.
rust-bitcoin/src/util/psbt/map/input.rs
Line 95 in 0c5b695
We should add a two new APIs to input
The text was updated successfully, but these errors were encountered: