Remove serde for taprootspendinfo

Implementing this for spendinfo is really complicated because it
contains some cached data without retaining the components that are used
to compute them.

Users should serde the 1) NodeInfo and 2) internal key and reconstruct
TaprootSpendInfo from it.
This commit is contained in:
sanket1729 2023-02-24 01:35:58 -08:00
parent a397ab0c19
commit 289dc1e7f5
3 changed files with 1 additions and 28 deletions

View File

@ -186,8 +186,6 @@ type ScriptMerkleProofMap = BTreeMap<(ScriptBuf, LeafVersion), BTreeSet<TaprootM
/// Note: This library currently does not support /// Note: This library currently does not support
/// [annex](https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#cite_note-5). /// [annex](https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#cite_note-5).
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct TaprootSpendInfo { pub struct TaprootSpendInfo {
/// The BIP341 internal key. /// The BIP341 internal key.
internal_key: UntweakedPublicKey, internal_key: UntweakedPublicKey,

View File

@ -33,16 +33,14 @@ use bitcoin::blockdata::witness::Witness;
use bitcoin::consensus::encode::deserialize; use bitcoin::consensus::encode::deserialize;
use bitcoin::hashes::hex::FromHex; use bitcoin::hashes::hex::FromHex;
use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d, Hash}; use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d, Hash};
use bitcoin::key::UntweakedPublicKey;
use bitcoin::psbt::raw::{self, Key, Pair, ProprietaryKey}; use bitcoin::psbt::raw::{self, Key, Pair, ProprietaryKey};
use bitcoin::psbt::{Input, Output, Psbt, PsbtSighashType}; use bitcoin::psbt::{Input, Output, Psbt, PsbtSighashType};
use bitcoin::sighash::{EcdsaSighashType, TapSighashType}; use bitcoin::sighash::{EcdsaSighashType, TapSighashType};
use bitcoin::taproot::{self, ControlBlock, LeafVersion, TaprootBuilder, TaprootSpendInfo, TapTree}; use bitcoin::taproot::{self, ControlBlock, LeafVersion, TaprootBuilder, TapTree};
use bitcoin::{ use bitcoin::{
ecdsa, Address, Block, Network, OutPoint, PrivateKey, PublicKey, ScriptBuf, Sequence, Target, ecdsa, Address, Block, Network, OutPoint, PrivateKey, PublicKey, ScriptBuf, Sequence, Target,
Transaction, TxIn, TxOut, Txid, Work, Transaction, TxIn, TxOut, Txid, Work,
}; };
use secp256k1::Secp256k1;
/// Implicitly does regression test for `BlockHeader` also. /// Implicitly does regression test for `BlockHeader` also.
#[test] #[test]
@ -365,29 +363,6 @@ fn serde_regression_taptree() {
assert_eq!(got, want) assert_eq!(got, want)
} }
#[test]
fn serde_regression_taproot_spend_info() {
let secp = Secp256k1::verification_only();
let internal_key = UntweakedPublicKey::from_str(
"93c7378d96518a75448821c4f7c8f4bae7ce60f804d03d1f0628dd5dd0f5de51",
)
.unwrap();
let script_weights = vec![
(10, ScriptBuf::from_hex("51").unwrap()), // semantics of script don't matter for this test
(20, ScriptBuf::from_hex("52").unwrap()),
(20, ScriptBuf::from_hex("53").unwrap()),
(30, ScriptBuf::from_hex("54").unwrap()),
(19, ScriptBuf::from_hex("55").unwrap()),
];
let tree_info =
TaprootSpendInfo::with_huffman_tree(&secp, internal_key, script_weights).unwrap();
let got = serialize(&tree_info).unwrap();
let want = include_bytes!("data/serde/taproot_spend_info_bincode") as &[_];
assert_eq!(got, want)
}
// Used to get a 256 bit integer as a byte array. // Used to get a 256 bit integer as a byte array.
fn le_bytes() -> [u8; 32] { fn le_bytes() -> [u8; 32] {
let x: u128 = 0xDEAD_BEEF_CAFE_BABE_DEAD_BEEF_CAFE_BABE; let x: u128 = 0xDEAD_BEEF_CAFE_BABE_DEAD_BEEF_CAFE_BABE;