Skip to content

Commit c7478d8

Browse files
committed
Derive serde for taproot stuctures
1 parent b945a5e commit c7478d8

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/util/schnorr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ impl TweakedPublicKey {
110110

111111
/// A BIP340-341 serialized schnorr signature with the corresponding hash type.
112112
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
113+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
113114
pub struct SchnorrSig {
114115
/// The underlying schnorr signature
115116
pub sig: secp256k1::schnorrsig::Signature,

src/util/sighash.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ pub struct ScriptPath<'s> {
104104
/// Hashtype of an input's signature, encoded in the last byte of the signature
105105
/// Fixed values so they can be casted as integer types for encoding
106106
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
107+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
107108
pub enum SchnorrSigHashType {
108109
/// 0x0: Used when not explicitly specified, defaulting to [`SchnorrSigHashType::All`]
109110
Default = 0x00,

src/util/taproot.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ impl TaprootSpendInfo {
345345
/// branches in a DFS(Depth first search) walk to construct this tree.
346346
// Similar to Taproot Builder in bitcoin core
347347
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
348+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
348349
pub struct TaprootBuilder {
349350
// The following doc-comment is from bitcoin core, but modified for rust
350351
// The comment below describes the current state of the builder for a given tree.
@@ -484,7 +485,8 @@ impl TaprootBuilder {
484485

485486
// Internally used structure to represent the node information in taproot tree
486487
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
487-
struct NodeInfo {
488+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
489+
pub(crate) struct NodeInfo {
488490
/// Merkle Hash for this node
489491
hash: sha256::Hash,
490492
/// information about leaves inside this node
@@ -537,7 +539,8 @@ impl NodeInfo {
537539

538540
// Internally used structure to store information about taproot leaf node
539541
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
540-
struct LeafInfo {
542+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
543+
pub(crate) struct LeafInfo {
541544
// The underlying script
542545
script: Script,
543546
// The leaf version
@@ -567,6 +570,7 @@ impl LeafInfo {
567570
// The type of hash is sha256::Hash because the vector might contain
568571
// both TapBranchHash and TapLeafHash
569572
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
573+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
570574
pub struct TaprootMerkleBranch(Vec<sha256::Hash>);
571575

572576
impl TaprootMerkleBranch {
@@ -638,6 +642,7 @@ impl TaprootMerkleBranch {
638642

639643
/// Control Block data structure used in Tapscript satisfaction
640644
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
645+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
641646
pub struct ControlBlock {
642647
/// The tapleaf version,
643648
pub leaf_version: LeafVersion,
@@ -744,6 +749,7 @@ impl ControlBlock {
744749

745750
/// The leaf version for tapleafs
746751
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
752+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
747753
pub struct LeafVersion(u8);
748754

749755
impl Default for LeafVersion {

0 commit comments

Comments
 (0)