Skip to content

Commit 97f16a9

Browse files
committed
Introduce arithematic expressions
1 parent 5c91ae1 commit 97f16a9

File tree

8 files changed

+1194
-14
lines changed

8 files changed

+1194
-14
lines changed

src/descriptor/csfs_cov/satisfy.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,13 @@ impl<'tx, 'ptx> CovSatisfier<'tx, 'ptx> {
5959
/// 1) if number of spent_utxos is not equal to
6060
/// number of transaction inputs.
6161
/// 2) if idx is out of bounds
62-
pub fn new_taproot(
63-
tx: &'tx Transaction,
64-
spent_utxos: &'ptx [TxOut],
65-
idx: u32,
66-
hash_type: EcdsaSigHashType,
67-
) -> Self {
62+
pub fn new_taproot(tx: &'tx Transaction, spent_utxos: &'ptx [TxOut], idx: u32) -> Self {
6863
assert!(spent_utxos.len() == tx.input.len());
6964
assert!((idx as usize) < spent_utxos.len());
7065
Self {
7166
tx,
7267
idx,
73-
hash_type,
68+
hash_type: EcdsaSigHashType::All, // This is not used in taproot. Update PsbtSigHashType later
7469
script_code: None,
7570
value: None,
7671
spent_utxos: Some(spent_utxos),
@@ -112,6 +107,14 @@ impl<'tx, 'ptx> CovSatisfier<'tx, 'ptx> {
112107
}
113108

114109
impl<'tx, 'ptx, Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for CovSatisfier<'tx, 'ptx> {
110+
fn lookup_spent_utxos(&self) -> Option<&[elements::TxOut]> {
111+
self.spent_utxos
112+
}
113+
114+
fn lookup_tx(&self) -> Option<&elements::Transaction> {
115+
Some(self.tx)
116+
}
117+
115118
fn lookup_nversion(&self) -> Option<u32> {
116119
Some(self.tx.version)
117120
}

src/expression.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,13 @@ impl<'a> Tree<'a> {
233233
pub fn parse_num<T: FromStr>(s: &str) -> Result<T, Error> {
234234
if s.len() > 1 {
235235
let ch = s.chars().next().unwrap();
236+
let ch = if ch == '-' {
237+
s.chars().nth(1).ok_or(Error::Unexpected(
238+
"Negative number must follow dash sign".to_string(),
239+
))?
240+
} else {
241+
ch
242+
};
236243
if !('1'..='9').contains(&ch) {
237244
return Err(Error::Unexpected(
238245
"Number must start with a digit 1-9".to_string(),

0 commit comments

Comments
 (0)