Skip to content

Commit

Permalink
descriptor: add set of standard descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Jul 30, 2023
1 parent 6b0b1a4 commit 8519e91
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
7 changes: 7 additions & 0 deletions std/src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use bc::secp256k1::PublicKey;
use bc::{InternalPk, ScriptPubkey};

use crate::{Address, AddressNetwork, ComprPubkey, Idx, NormalIndex};
Expand Down Expand Up @@ -88,3 +89,9 @@ pub trait DeriveSpk: Derive<Derived = ScriptPubkey> {
}
}
impl<T: Derive<Derived = ScriptPubkey>> DeriveSpk for T {}

pub trait DeriveSet {
type Base: Derive<Derived = PublicKey>;
type Compr: DeriveCompr<Derived = ComprPubkey>;
type XOnly: DeriveXOnly<Derived = InternalPk>;
}
30 changes: 24 additions & 6 deletions std/src/descriptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@

use bc::ScriptPubkey;

use crate::{Derive, DeriveXOnly, NormalIndex};
use crate::{Derive, DeriveSet, DeriveSpk, DeriveXOnly, NormalIndex};

pub struct TrKey<K: DeriveXOnly>(K);

/*
pub struct TrScript<K: DeriveXOnly> {
internal_key: K,
tap_tree: TapTree<Policy<K>>,
}
*/

impl<K: DeriveXOnly> Derive for TrKey<K> {
type Derived = ScriptPubkey;

Expand All @@ -39,9 +46,20 @@ impl<K: DeriveXOnly> Derive for TrKey<K> {
}
}

/*
pub struct TrScript<K: DeriveXOnly> {
internal_key: K,
tap_tree: TapTree<Policy<K>>,
pub enum DescriptorStd<S: DeriveSet> {
TrKey(TrKey<S::XOnly>),
}

impl<S: DeriveSet> Derive for DescriptorStd<S> {
type Derived = ScriptPubkey;

fn derive(
&self,
change: impl Into<NormalIndex>,
index: impl Into<NormalIndex>,
) -> Self::Derived {
match self {
DescriptorStd::TrKey(d) => d.derive(change, index),
}
}
}
*/
4 changes: 2 additions & 2 deletions std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ pub use address::{
};
pub use bc::{secp256k1, *};
pub use chain::{AddrInfo, BlockInfo, MiningInfo, TxInInfo, TxInfo, TxOutInfo, TxStatus, UtxoInfo};
pub use derive::{Derive, DeriveCompr, DeriveSpk, DeriveXOnly};
pub use descriptors::TrKey;
pub use derive::{Derive, DeriveCompr, DeriveSet, DeriveSpk, DeriveXOnly};
pub use descriptors::{DescriptorStd, TrKey};
pub use index::{
DerivationIndex, HardenedIndex, Idx, IndexError, IndexParseError, NormalIndex,
HARDENED_INDEX_BOUNDARY,
Expand Down
6 changes: 4 additions & 2 deletions std/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::num::NonZeroU32;
use std::ops::Deref;

use bc::{Outpoint, ScriptPubkey, Txid};
use bc::{Chain, Outpoint, ScriptPubkey, Txid};

use crate::chain::BlockHeight;
use crate::derive::DeriveSpk;
Expand All @@ -37,6 +37,8 @@ where D: DeriveSpk
{
script_pubkey: D,
keychains: BTreeSet<NormalIndex>,
#[getter(as_copy)]
chain: Chain,
}

impl<D: DeriveSpk> Deref for WalletDescr<D> {
Expand All @@ -63,7 +65,7 @@ pub struct WalletCache {
max_known: HashMap<NormalIndex, NormalIndex>,
}

pub struct Wallet<D: DeriveSpk, L2 = ()> {
pub struct Wallet<D: DeriveSpk, L2: Default = ()> {
descr: WalletDescr<D>,
data: WalletData,
cache: WalletCache,
Expand Down

0 comments on commit 8519e91

Please sign in to comment.