Stop using deprecated structs
This commit is contained in:
parent
a16c18255c
commit
00164588f2
@ -10,6 +10,7 @@
|
|||||||
// licenses.
|
// licenses.
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::io::BufReader;
|
||||||
use std::net::{TcpStream, ToSocketAddrs};
|
use std::net::{TcpStream, ToSocketAddrs};
|
||||||
use std::sync::{Arc, Condvar, Mutex, RwLock};
|
use std::sync::{Arc, Condvar, Mutex, RwLock};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
@ -19,14 +20,13 @@ use socks::{Socks5Stream, ToTargetAddr};
|
|||||||
|
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
|
|
||||||
use bitcoin::consensus::Encodable;
|
use bitcoin::consensus::{Decodable, Encodable};
|
||||||
use bitcoin::hash_types::BlockHash;
|
use bitcoin::hash_types::BlockHash;
|
||||||
use bitcoin::network::constants::ServiceFlags;
|
use bitcoin::network::constants::ServiceFlags;
|
||||||
use bitcoin::network::message::{NetworkMessage, RawNetworkMessage};
|
use bitcoin::network::message::{NetworkMessage, RawNetworkMessage};
|
||||||
use bitcoin::network::message_blockdata::*;
|
use bitcoin::network::message_blockdata::*;
|
||||||
use bitcoin::network::message_filter::*;
|
use bitcoin::network::message_filter::*;
|
||||||
use bitcoin::network::message_network::VersionMessage;
|
use bitcoin::network::message_network::VersionMessage;
|
||||||
use bitcoin::network::stream_reader::StreamReader;
|
|
||||||
use bitcoin::network::Address;
|
use bitcoin::network::Address;
|
||||||
use bitcoin::{Block, Network, Transaction, Txid, Wtxid};
|
use bitcoin::{Block, Network, Transaction, Txid, Wtxid};
|
||||||
|
|
||||||
@ -327,9 +327,10 @@ impl Peer {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut reader = StreamReader::new(connection, None);
|
let mut reader = BufReader::new(connection);
|
||||||
loop {
|
loop {
|
||||||
let raw_message: RawNetworkMessage = check_disconnect!(reader.read_next());
|
let raw_message: RawNetworkMessage =
|
||||||
|
check_disconnect!(Decodable::consensus_decode(&mut reader));
|
||||||
|
|
||||||
let in_message = if raw_message.magic != network.magic() {
|
let in_message = if raw_message.magic != network.magic() {
|
||||||
continue;
|
continue;
|
||||||
|
@ -25,7 +25,9 @@ use bitcoin::secp256k1::Secp256k1;
|
|||||||
|
|
||||||
use bitcoin::consensus::encode::serialize;
|
use bitcoin::consensus::encode::serialize;
|
||||||
use bitcoin::util::psbt;
|
use bitcoin::util::psbt;
|
||||||
use bitcoin::{Address, Network, OutPoint, Script, SigHashType, Transaction, TxOut, Txid, Witness};
|
use bitcoin::{
|
||||||
|
Address, EcdsaSighashType, Network, OutPoint, Script, Transaction, TxOut, Txid, Witness,
|
||||||
|
};
|
||||||
|
|
||||||
use miniscript::descriptor::DescriptorTrait;
|
use miniscript::descriptor::DescriptorTrait;
|
||||||
use miniscript::psbt::PsbtInputSatisfier;
|
use miniscript::psbt::PsbtInputSatisfier;
|
||||||
@ -1022,7 +1024,7 @@ where
|
|||||||
// is using `SIGHASH_ALL`
|
// is using `SIGHASH_ALL`
|
||||||
if !sign_options.allow_all_sighashes
|
if !sign_options.allow_all_sighashes
|
||||||
&& !psbt.inputs.iter().all(|i| {
|
&& !psbt.inputs.iter().all(|i| {
|
||||||
i.sighash_type.is_none() || i.sighash_type == Some(SigHashType::All.into())
|
i.sighash_type.is_none() || i.sighash_type == Some(EcdsaSighashType::All.into())
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
return Err(Error::Signer(signer::SignerError::NonStandardSighash));
|
return Err(Error::Signer(signer::SignerError::NonStandardSighash));
|
||||||
@ -2241,12 +2243,12 @@ pub(crate) mod test {
|
|||||||
let mut builder = wallet.build_tx();
|
let mut builder = wallet.build_tx();
|
||||||
builder
|
builder
|
||||||
.add_recipient(addr.script_pubkey(), 30_000)
|
.add_recipient(addr.script_pubkey(), 30_000)
|
||||||
.sighash(bitcoin::SigHashType::Single.into());
|
.sighash(bitcoin::EcdsaSighashType::Single.into());
|
||||||
let (psbt, _) = builder.finish().unwrap();
|
let (psbt, _) = builder.finish().unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
psbt.inputs[0].sighash_type,
|
psbt.inputs[0].sighash_type,
|
||||||
Some(bitcoin::SigHashType::Single.into())
|
Some(bitcoin::EcdsaSighashType::Single.into())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3785,7 +3787,7 @@ pub(crate) mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_sign_nonstandard_sighash() {
|
fn test_sign_nonstandard_sighash() {
|
||||||
let sighash = SigHashType::NonePlusAnyoneCanPay;
|
let sighash = EcdsaSighashType::NonePlusAnyoneCanPay;
|
||||||
|
|
||||||
let (wallet, _, _) = get_funded_wallet("wpkh(tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/*)");
|
let (wallet, _, _) = get_funded_wallet("wpkh(tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/*)");
|
||||||
let addr = wallet.get_address(New).unwrap();
|
let addr = wallet.get_address(New).unwrap();
|
||||||
|
@ -94,8 +94,8 @@ use bitcoin::hashes::{hash160, Hash};
|
|||||||
use bitcoin::secp256k1;
|
use bitcoin::secp256k1;
|
||||||
use bitcoin::secp256k1::{Message, Secp256k1};
|
use bitcoin::secp256k1::{Message, Secp256k1};
|
||||||
use bitcoin::util::bip32::{ChildNumber, DerivationPath, ExtendedPrivKey, Fingerprint};
|
use bitcoin::util::bip32::{ChildNumber, DerivationPath, ExtendedPrivKey, Fingerprint};
|
||||||
use bitcoin::util::{bip143, ecdsa, psbt};
|
use bitcoin::util::{ecdsa, psbt, sighash};
|
||||||
use bitcoin::{PrivateKey, PublicKey, Script, SigHashType, Sighash};
|
use bitcoin::{EcdsaSighashType, PrivateKey, PublicKey, Script, Sighash};
|
||||||
|
|
||||||
use miniscript::descriptor::{DescriptorSecretKey, DescriptorSinglePriv, DescriptorXKey, KeyMap};
|
use miniscript::descriptor::{DescriptorSecretKey, DescriptorSinglePriv, DescriptorXKey, KeyMap};
|
||||||
use miniscript::{Legacy, MiniscriptKey, Segwitv0};
|
use miniscript::{Legacy, MiniscriptKey, Segwitv0};
|
||||||
@ -156,6 +156,14 @@ pub enum SignerError {
|
|||||||
NonStandardSighash,
|
NonStandardSighash,
|
||||||
/// Invalid SIGHASH for the signing context in use
|
/// Invalid SIGHASH for the signing context in use
|
||||||
InvalidSighash,
|
InvalidSighash,
|
||||||
|
/// Error while computing the hash to sign
|
||||||
|
SighashError(sighash::Error),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<sighash::Error> for SignerError {
|
||||||
|
fn from(e: sighash::Error) -> Self {
|
||||||
|
SignerError::SighashError(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for SignerError {
|
impl fmt::Display for SignerError {
|
||||||
@ -292,7 +300,7 @@ impl Signer for PrivateKey {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let pubkey = PublicKey::from_private_key(secp, &self);
|
let pubkey = PublicKey::from_private_key(secp, self);
|
||||||
if psbt.inputs[input_index].partial_sigs.contains_key(&pubkey) {
|
if psbt.inputs[input_index].partial_sigs.contains_key(&pubkey) {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@ -518,7 +526,9 @@ impl ComputeSighash for Legacy {
|
|||||||
let psbt_input = &psbt.inputs[input_index];
|
let psbt_input = &psbt.inputs[input_index];
|
||||||
let tx_input = &psbt.unsigned_tx.input[input_index];
|
let tx_input = &psbt.unsigned_tx.input[input_index];
|
||||||
|
|
||||||
let sighash = psbt_input.sighash_type.unwrap_or(SigHashType::All.into());
|
let sighash = psbt_input
|
||||||
|
.sighash_type
|
||||||
|
.unwrap_or_else(|| EcdsaSighashType::All.into());
|
||||||
let script = match psbt_input.redeem_script {
|
let script = match psbt_input.redeem_script {
|
||||||
Some(ref redeem_script) => redeem_script.clone(),
|
Some(ref redeem_script) => redeem_script.clone(),
|
||||||
None => {
|
None => {
|
||||||
@ -536,8 +546,11 @@ impl ComputeSighash for Legacy {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
psbt.unsigned_tx
|
sighash::SighashCache::new(&psbt.unsigned_tx).legacy_signature_hash(
|
||||||
.signature_hash(input_index, &script, sighash.to_u32()),
|
input_index,
|
||||||
|
&script,
|
||||||
|
sighash.to_u32(),
|
||||||
|
)?,
|
||||||
sighash,
|
sighash,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@ -567,7 +580,7 @@ impl ComputeSighash for Segwitv0 {
|
|||||||
|
|
||||||
let sighash = psbt_input
|
let sighash = psbt_input
|
||||||
.sighash_type
|
.sighash_type
|
||||||
.unwrap_or(SigHashType::All.into())
|
.unwrap_or_else(|| EcdsaSighashType::All.into())
|
||||||
.ecdsa_hash_ty()
|
.ecdsa_hash_ty()
|
||||||
.map_err(|_| SignerError::InvalidSighash)?;
|
.map_err(|_| SignerError::InvalidSighash)?;
|
||||||
|
|
||||||
@ -612,12 +625,12 @@ impl ComputeSighash for Segwitv0 {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
bip143::SigHashCache::new(&psbt.unsigned_tx).signature_hash(
|
sighash::SighashCache::new(&psbt.unsigned_tx).segwit_signature_hash(
|
||||||
input_index,
|
input_index,
|
||||||
&script,
|
&script,
|
||||||
value,
|
value,
|
||||||
sighash,
|
sighash,
|
||||||
),
|
)?,
|
||||||
sighash.into(),
|
sighash.into(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user