Skip to content

Commit

Permalink
Merge pull request #266 from sapio-lang/update-deps-01-16-24
Browse files Browse the repository at this point in the history
Update Versions & Small Fixes
  • Loading branch information
JeremyRubin committed Jan 16, 2024
2 parents 89e1e1f + 6aecf71 commit d1c93a1
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 43 deletions.
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 @@ -72,7 +72,7 @@ impl Compilable for bitcoin::XOnlyPublicKey {
}
}

#[derive(PartialEq, Eq)]
#[derive(PartialEq, Eq, Debug)]
enum Nullable {
Yes,
No,
Expand All @@ -90,19 +90,20 @@ fn compute_all_effects<C, A: Default>(
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 @@ where
}
.entry(h)
.or_insert(txtmpl);

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

// 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 @@ -346,6 +349,9 @@ where
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 @@ where
address,
descriptor,
amount_range,
metadata: self
.metadata(metadata_ctx)?
.add_guard_simps(all_guard_simps)?,
metadata,
})
}
}
Expand Down Expand Up @@ -394,10 +398,13 @@ fn combine_txtmpls(
// 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 @@ use super::input::InputMetadata;
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::timelocks::*;
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 @@ -229,28 +229,36 @@ impl Builder {
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 {
}
}
}

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

0 comments on commit d1c93a1

Please sign in to comment.