Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Versions & Small Fixes #266

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ serde_derive = "1.0"
clap = "=3.0.0-beta.2"
base64 = "0.13.0"
lazy_static = "1.4.0"
bitcoincore-rpc-async = "4.0.1-alpha.1"
bitcoincore-rpc-async = "4.0.1-alpha.2"
tokio = { version = "1", features = ["full"] }
directories = "3.0.1"
rand = "^0.6"
Expand Down
2 changes: 1 addition & 1 deletion examples/dcf_mining_pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ serde_json = "1.0"
serde = "1.0"
serde_derive = "1.0"
tokio = { version = "1", features = ["full"] }
bitcoincore-rpc-async = "4.0.1-alpha.1"
bitcoincore-rpc-async = "4.0.1-alpha.2"


[dependencies.bitcoin]
Expand Down
4 changes: 2 additions & 2 deletions sapio-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ serde_derive = "1.0"

[dependencies.miniscript]
package = "sapio-miniscript"
version = "^7.0.0"
version = "^7.0.1"
features = ['compiler', 'use-serde', 'use-schemars', 'serde']

[dependencies.bitcoin]
package = "sapio-bitcoin"
version = "0.28.0"
version = "0.28.2"
features = ['use-serde']
4 changes: 2 additions & 2 deletions sapio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ description = "A programming framework for bitcoin smart contracts."

[dependencies.miniscript]
package = "sapio-miniscript"
version = "^7.0.0"
version = "^7.0.1"
features = ['compiler', 'use-serde', 'use-schemars', 'serde']

[features]
Expand All @@ -37,7 +37,7 @@ features = ['impl_json_schema', 'derive']

[dependencies.bitcoin]
package = "sapio-bitcoin"
version = "0.28.0"
version = "0.28.2"
features = ['use-serde']


Expand Down
35 changes: 21 additions & 14 deletions sapio/src/contract/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
/// Allow Contract to implement Compile
impl ImplSeal for super::Compiled {}
impl ImplSeal for bitcoin::XOnlyPublicKey {}
impl<'a, C> ImplSeal for C where C: super::AnyContract {}

Check warning on line 47 in sapio/src/contract/compiler/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

this lifetime isn't used in the impl

warning: this lifetime isn't used in the impl --> sapio/src/contract/compiler/mod.rs:47:10 | 47 | impl<'a, C> ImplSeal for C where C: super::AnyContract {} | ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes = note: `#[warn(clippy::extra_unused_lifetimes)]` on by default
}
/// Compilable is a trait for anything which can be compiled
pub trait Compilable: private::ImplSeal {
Expand Down Expand Up @@ -72,7 +72,7 @@
}
}

#[derive(PartialEq, Eq)]
#[derive(PartialEq, Eq, Debug)]
enum Nullable {
Yes,
No,
Expand All @@ -90,19 +90,20 @@
return Ok(def);
}
let mut applied_effects_ctx = top_effect_ctx.derive(PathFragment::Effects)?;
top_effect_ctx
let r = top_effect_ctx
.get_effects(InternalCompilerTag { _secret: () })
.get_value(top_effect_ctx.path())
// always gets the default expansion, but will also attempt
// operating with the effects passed in through the Context Object.
.fold(Ok(def), |a: TxTmplIt, (k, arg)| -> TxTmplIt {
let v = a?;
.try_fold(def, |a, (k, arg)| -> TxTmplIt {
let v = a;
let c = applied_effects_ctx
.derive(PathFragment::Named(SArc(k.clone())))
.expect(UNIQUE_DERIVE_PANIC_MSG);
let w = func.call_json(self_ref, c, arg.clone())?;
Ok(Box::new(v.chain(w)))
})
});
r
}

struct Renamer {
Expand Down Expand Up @@ -252,6 +253,7 @@
}
.entry(h)
.or_insert(txtmpl);

let extractor = func.get_extract_clause_from_txtmpl();
(extractor)(txtmpl, &ctx)
})
Expand All @@ -262,11 +264,12 @@

// N.B. the order of the matches below is significant
Ok(if func.get_returned_txtmpls_modify_guards() {
(
let r = (
None,
combine_txtmpls(nullability, txtmpl_clauses, guards)?,
guard_metadata,
)
);
r

Check warning on line 272 in sapio/src/contract/compiler/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

returning the result of a `let` binding from a block

warning: returning the result of a `let` binding from a block --> sapio/src/contract/compiler/mod.rs:272:21 | 267 | / let r = ( 268 | | None, 269 | | combine_txtmpls(nullability, txtmpl_clauses, guards)?, 270 | | guard_metadata, 271 | | ); | |______________________- unnecessary `let` binding 272 | r | ^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return = note: `#[warn(clippy::let_and_return)]` on by default help: return the expression directly | 267 ~ 268 ~ ( 269 + None, 270 + combine_txtmpls(nullability, txtmpl_clauses, guards)?, 271 + guard_metadata, 272 + ) |
} else {
let mut cp =
ContinuationPoint::at(func.get_schema().clone(), effect_path.clone());
Expand Down Expand Up @@ -318,7 +321,7 @@

all_g
.into_iter()
.chain(clause_accumulator.into_iter())

Check warning on line 324 in sapio/src/contract/compiler/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

explicit call to `.into_iter()` in function argument accepting `IntoIterator`

warning: explicit call to `.into_iter()` in function argument accepting `IntoIterator` --> sapio/src/contract/compiler/mod.rs:324:24 | 324 | .chain(clause_accumulator.into_iter()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `clause_accumulator` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` --> /rustc/714b29a17ff5fa727c794bbb60bfd335f8e75d42/library/core/src/iter/traits/iterator.rs:524:12 = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion = note: `#[warn(clippy::useless_conversion)]` on by default
.flatten()
.collect()
};
Expand All @@ -336,7 +339,7 @@

let failed_estimate = comitted_txns.values().any(|a| {
// witness space not scaled
let tx_size = a.tx.get_weight() + estimated_max_size;

Check warning on line 342 in sapio/src/contract/compiler/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

use of deprecated method `sapio_bitcoin::Transaction::get_weight`: Please use `transaction::weight` instead.

warning: use of deprecated method `sapio_bitcoin::Transaction::get_weight`: Please use `transaction::weight` instead. --> sapio/src/contract/compiler/mod.rs:342:32 | 342 | let tx_size = a.tx.get_weight() + estimated_max_size; | ^^^^^^^^^^ | = note: `#[warn(deprecated)]` on by default
let fees = amount_range.max() - a.total_amount();
a.min_feerate_sats_vbyte
.map(|m| fees.as_sat() < (m.as_sat() * tx_size as u64))
Expand All @@ -346,6 +349,9 @@
Err(CompilationError::MinFeerateError)
} else {
let metadata_ctx = ctx.derive(PathFragment::Metadata)?;
let metadata = self
.metadata(metadata_ctx)?
.add_guard_simps(all_guard_simps)?;
Ok(Compiled {
ctv_to_tx: comitted_txns,
suggested_txs: other_txns,
Expand All @@ -354,9 +360,7 @@
address,
descriptor,
amount_range,
metadata: self
.metadata(metadata_ctx)?
.add_guard_simps(all_guard_simps)?,
metadata,
})
}
}
Expand Down Expand Up @@ -394,10 +398,13 @@
// Error if 0 templates return and we don't want to be nullable
(Nullable::No, 0, _) => Err(CompilationError::MissingTemplates),
// If the guard is trivial, return the hashes standalone
(_, _, Clause::Trivial) => Ok(txtmpl_clauses
.into_iter()
.map(|policy| policy.compile().map_err(Into::<CompilationError>::into))
.collect::<Result<Vec<_>, _>>()?),
(_, _, Clause::Trivial) => {
let r = Ok(txtmpl_clauses
.into_iter()
.map(|policy| policy.compile().map_err(Into::<CompilationError>::into))
.collect::<Result<Vec<_>, _>>()?);
r

Check warning on line 406 in sapio/src/contract/compiler/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

returning the result of a `let` binding from a block

warning: returning the result of a `let` binding from a block --> sapio/src/contract/compiler/mod.rs:406:13 | 402 | / let r = Ok(txtmpl_clauses 403 | | .into_iter() 404 | | .map(|policy| policy.compile().map_err(Into::<CompilationError>::into)) 405 | | .collect::<Result<Vec<_>, _>>()?); | |__________________________________________________- unnecessary `let` binding 406 | r | ^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return help: return the expression directly | 402 ~ 403 ~ Ok(txtmpl_clauses 404 + .into_iter() 405 + .map(|policy| policy.compile().map_err(Into::<CompilationError>::into)) 406 + .collect::<Result<Vec<_>, _>>()?) |
}
// If the guard is non-trivial, zip it to each hash
// TODO: Arc in miniscript to dedup memory?
// This could be Clause::Shared(x) or something...
Expand Down
52 changes: 30 additions & 22 deletions sapio/src/template/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
pub use super::{Output, OutputMeta};
use super::{Template, TemplateMetadata};
use crate::contract::{CompilationError, Context};
use crate::util::extended_address::ExtendedAddress;
use bitcoin::util::amount::Amount;
use bitcoin::VarInt;
use bitcoin::Witness;
use bitcoin::{Script, VarInt};
use sapio_base::effects::PathFragment;
use sapio_base::simp::SIMPAttachableAt;
use sapio_base::simp::TemplateInputLT;
Expand All @@ -20,7 +21,6 @@
use sapio_base::CTVHash;
use sapio_base::Clause;
use std::convert::TryFrom;
use std::convert::TryInto;

/// Builder can be used to interactively put together a transaction template before
/// finalizing into a Template.
Expand Down Expand Up @@ -227,30 +227,38 @@
/// Creates a transaction from a Builder.
/// Generally, should not be called directly.
pub fn get_tx(&self) -> bitcoin::Transaction {
let default_seq = RelTime::try_from(0).unwrap().into();

Check warning on line 230 in sapio/src/template/builder.rs

View workflow job for this annotation

GitHub Actions / clippy

use of a fallible conversion when an infallible one could be used

warning: use of a fallible conversion when an infallible one could be used --> sapio/src/template/builder.rs:230:27 | 230 | let default_seq = RelTime::try_from(0).unwrap().into(); | ^^^^^^^^^^^^^^^^^ help: use: `From::from` | = note: converting `u16` to `LockTime<Rel, MTP>` cannot fail = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_fallible_conversions = note: `#[warn(clippy::unnecessary_fallible_conversions)]` on by default
let default_nlt = AbsHeight::try_from(0).unwrap().into();
bitcoin::Transaction {
let input = self
.sequences
.iter()
.map(|sequence| bitcoin::TxIn {
previous_output: Default::default(),
script_sig: Default::default(),
sequence: sequence.unwrap_or(default_seq).get(),
witness: Witness::new(),
})
.collect();
let output = self
.outputs
.iter()
.map(|out| {
let value = out.amount.as_sat();

let script_pubkey: Script = From::<&ExtendedAddress>::from(&out.contract.address);
bitcoin::TxOut {
value,
script_pubkey,
}
})
.collect();
let t = bitcoin::Transaction {
version: self.version,
lock_time: self.lock_time.unwrap_or(default_nlt).get(),
input: self
.sequences
.iter()
.map(|sequence| bitcoin::TxIn {
previous_output: Default::default(),
script_sig: Default::default(),
sequence: sequence.unwrap_or(default_seq).get(),
witness: Witness::new(),
})
.collect(),
output: self
.outputs
.iter()
.map(|out| bitcoin::TxOut {
value: TryInto::<Amount>::try_into(out.amount).unwrap().as_sat(),
script_pubkey: out.contract.address.clone().into(),
})
.collect(),
}
input,
output,
};
t

Check warning on line 261 in sapio/src/template/builder.rs

View workflow job for this annotation

GitHub Actions / clippy

returning the result of a `let` binding from a block

warning: returning the result of a `let` binding from a block --> sapio/src/template/builder.rs:261:9 | 255 | / let t = bitcoin::Transaction { 256 | | version: self.version, 257 | | lock_time: self.lock_time.unwrap_or(default_nlt).get(), 258 | | input, 259 | | output, 260 | | }; | |__________- unnecessary `let` binding 261 | t | ^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return help: return the expression directly | 255 ~ 256 ~ bitcoin::Transaction { 257 + version: self.version, 258 + lock_time: self.lock_time.unwrap_or(default_nlt).get(), 259 + input, 260 + output, 261 + } |
}

/// Sets the feerate if not set, and then sets the value to the min of the
Expand Down
14 changes: 14 additions & 0 deletions sapio/src/util/extended_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,17 @@
}
}
}

impl From<&ExtendedAddress> for Script {
fn from(s: &ExtendedAddress) -> Self {
match s {
ExtendedAddress::Address(a) => a.script_pubkey(),
ExtendedAddress::OpReturn(OpReturn(s)) => s.clone(),
ExtendedAddress::Unknown(s) => s.clone(),
ExtendedAddress::Descriptor(d) => {
let r = d.script_pubkey();
r

Check warning on line 100 in sapio/src/util/extended_address.rs

View workflow job for this annotation

GitHub Actions / clippy

returning the result of a `let` binding from a block

warning: returning the result of a `let` binding from a block --> sapio/src/util/extended_address.rs:100:17 | 99 | let r = d.script_pubkey(); | -------------------------- unnecessary `let` binding 100 | r | ^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return help: return the expression directly | 99 ~ 100 ~ d.script_pubkey() |
}
}
}
}
2 changes: 1 addition & 1 deletion tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ serde_json = "1.0"
serde = "1.0"
serde_derive = "1.0"
tokio = { version = "1", features = ["full"] }
bitcoincore-rpc-async = "4.0.1-alpha.1"
bitcoincore-rpc-async = "4.0.1-alpha.2"

[dependencies.miniscript]
package = "sapio-miniscript"
Expand Down
Loading