Skip to content

Commit

Permalink
Derive serde for taproot stuctures
Browse files Browse the repository at this point in the history
  • Loading branch information
sanket1729 committed Dec 28, 2021
1 parent b945a5e commit c7478d8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/util/schnorr.rs
Expand Up @@ -110,6 +110,7 @@ impl TweakedPublicKey {

/// A BIP340-341 serialized schnorr signature with the corresponding hash type.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct SchnorrSig {
/// The underlying schnorr signature
pub sig: secp256k1::schnorrsig::Signature,
Expand Down
1 change: 1 addition & 0 deletions src/util/sighash.rs
Expand Up @@ -104,6 +104,7 @@ pub struct ScriptPath<'s> {
/// Hashtype of an input's signature, encoded in the last byte of the signature
/// Fixed values so they can be casted as integer types for encoding
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum SchnorrSigHashType {
/// 0x0: Used when not explicitly specified, defaulting to [`SchnorrSigHashType::All`]
Default = 0x00,
Expand Down
10 changes: 8 additions & 2 deletions src/util/taproot.rs
Expand Up @@ -345,6 +345,7 @@ impl TaprootSpendInfo {
/// branches in a DFS(Depth first search) walk to construct this tree.
// Similar to Taproot Builder in bitcoin core
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct TaprootBuilder {
// The following doc-comment is from bitcoin core, but modified for rust
// The comment below describes the current state of the builder for a given tree.
Expand Down Expand Up @@ -484,7 +485,8 @@ impl TaprootBuilder {

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

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

impl TaprootMerkleBranch {
Expand Down Expand Up @@ -638,6 +642,7 @@ impl TaprootMerkleBranch {

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

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

impl Default for LeafVersion {
Expand Down

0 comments on commit c7478d8

Please sign in to comment.