Derive serde for taproot stuctures

This commit is contained in:
sanket1729 2021-10-28 00:43:02 -07:00
parent b945a5e5c6
commit c7478d8fd0
3 changed files with 10 additions and 2 deletions

View File

@ -110,6 +110,7 @@ impl TweakedPublicKey {
/// A BIP340-341 serialized schnorr signature with the corresponding hash type. /// A BIP340-341 serialized schnorr signature with the corresponding hash type.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct SchnorrSig { pub struct SchnorrSig {
/// The underlying schnorr signature /// The underlying schnorr signature
pub sig: secp256k1::schnorrsig::Signature, pub sig: secp256k1::schnorrsig::Signature,

View File

@ -104,6 +104,7 @@ pub struct ScriptPath<'s> {
/// Hashtype of an input's signature, encoded in the last byte of the signature /// 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 /// Fixed values so they can be casted as integer types for encoding
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum SchnorrSigHashType { pub enum SchnorrSigHashType {
/// 0x0: Used when not explicitly specified, defaulting to [`SchnorrSigHashType::All`] /// 0x0: Used when not explicitly specified, defaulting to [`SchnorrSigHashType::All`]
Default = 0x00, Default = 0x00,

View File

@ -345,6 +345,7 @@ impl TaprootSpendInfo {
/// branches in a DFS(Depth first search) walk to construct this tree. /// branches in a DFS(Depth first search) walk to construct this tree.
// Similar to Taproot Builder in bitcoin core // Similar to Taproot Builder in bitcoin core
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct TaprootBuilder { pub struct TaprootBuilder {
// The following doc-comment is from bitcoin core, but modified for rust // 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. // The comment below describes the current state of the builder for a given tree.
@ -484,7 +485,8 @@ impl TaprootBuilder {
// Internally used structure to represent the node information in taproot tree // Internally used structure to represent the node information in taproot tree
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[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 /// Merkle Hash for this node
hash: sha256::Hash, hash: sha256::Hash,
/// information about leaves inside this node /// information about leaves inside this node
@ -537,7 +539,8 @@ impl NodeInfo {
// Internally used structure to store information about taproot leaf node // Internally used structure to store information about taproot leaf node
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
struct LeafInfo { #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub(crate) struct LeafInfo {
// The underlying script // The underlying script
script: Script, script: Script,
// The leaf version // The leaf version
@ -567,6 +570,7 @@ impl LeafInfo {
// The type of hash is sha256::Hash because the vector might contain // The type of hash is sha256::Hash because the vector might contain
// both TapBranchHash and TapLeafHash // both TapBranchHash and TapLeafHash
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct TaprootMerkleBranch(Vec<sha256::Hash>); pub struct TaprootMerkleBranch(Vec<sha256::Hash>);
impl TaprootMerkleBranch { impl TaprootMerkleBranch {
@ -638,6 +642,7 @@ impl TaprootMerkleBranch {
/// Control Block data structure used in Tapscript satisfaction /// Control Block data structure used in Tapscript satisfaction
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ControlBlock { pub struct ControlBlock {
/// The tapleaf version, /// The tapleaf version,
pub leaf_version: LeafVersion, pub leaf_version: LeafVersion,
@ -744,6 +749,7 @@ impl ControlBlock {
/// The leaf version for tapleafs /// The leaf version for tapleafs
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct LeafVersion(u8); pub struct LeafVersion(u8);
impl Default for LeafVersion { impl Default for LeafVersion {