Skip to content

Commit 79d5c06

Browse files
authored
Merge pull request #243 from stevenroose/hash-desc
Derive std::hash::Hash for Descriptor et al
2 parents 86a63d8 + 8e52efb commit 79d5c06

File tree

9 files changed

+38
-14
lines changed

9 files changed

+38
-14
lines changed

.github/workflows/rust.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,12 @@ jobs:
6666
profile: minimal
6767
toolchain: ${{ matrix.rust }}
6868
override: true
69-
- name: Pin cc if rust 1.29
69+
- name: Pin deps if rust 1.29
7070
if: matrix.rust == '1.29.0'
71-
run: cargo generate-lockfile --verbose && cargo update -p cc --precise "1.0.41" --verbose
71+
run: |
72+
cargo generate-lockfile --verbose && \
73+
cargo update --verbose --package "cc" --precise "1.0.41" && \
74+
cargo update --verbose --package "serde" --precise "1.0.98" && \
75+
cargo update --verbose --package "serde_derive" --precise "1.0.98"
7276
- name: Running cargo
7377
run: ./contrib/test.sh

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@ coins in a given Bitcoin transaction
3434
More information can be found in [the documentation](https://docs.rs/miniscript)
3535
or in [the `examples/` directory](https://github.com/apoelstra/rust-miniscript/tree/master/examples)
3636

37+
38+
## Minimum Supported Rust Version (MSRV)
39+
This library should always compile with any combination of features on **Rust 1.29**.
40+
41+
Because some dependencies have broken the build in minor/patch releases, to
42+
compile with 1.29.0 you will need to run the following version-pinning command:
43+
```
44+
cargo update -p cc --precise "1.0.41" --verbose
45+
```
46+
47+
In order to use the `use-serde` feature or to build the unit tests with 1.29.0,
48+
the following version-pinning commands are also needed:
49+
```
50+
cargo update --package "serde" --precise "1.0.98"
51+
cargo update --package "serde_derive" --precise "1.0.98"
52+
```
53+
54+
3755
## Contributing
3856
Contributions are generally welcome. If you intend to make larger changes please
3957
discuss them in an issue before PRing them to avoid duplicate work and

contrib/test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh -ex
22

3-
FEATURES="compiler serde"
3+
FEATURES="compiler use-serde rand"
44

55
# Use toolchain if explicitly specified
66
if [ -n "$TOOLCHAIN" ]

src/descriptor/bare.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use super::{
3838

3939
/// Create a Bare Descriptor. That is descriptor that is
4040
/// not wrapped in sh or wsh. This covers the Pk descriptor
41-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]
41+
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
4242
pub struct Bare<Pk: MiniscriptKey> {
4343
/// underlying miniscript
4444
ms: Miniscript<Pk, BareCtx>,
@@ -203,7 +203,7 @@ impl<P: MiniscriptKey, Q: MiniscriptKey> TranslatePk<P, Q> for Bare<P> {
203203
}
204204

205205
/// A bare PkH descriptor at top level
206-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]
206+
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
207207
pub struct Pkh<Pk: MiniscriptKey> {
208208
/// underlying publickey
209209
pk: Pk,

src/descriptor/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub trait DescriptorTrait<Pk: MiniscriptKey> {
154154
}
155155

156156
/// Script descriptor
157-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
157+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
158158
pub enum Descriptor<Pk: MiniscriptKey> {
159159
/// A raw scriptpubkey (including pay-to-pubkey) under Legacy context
160160
Bare(Bare<Pk>),

src/descriptor/segwitv0.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use super::{
3434
DescriptorTrait, SortedMultiVec,
3535
};
3636
/// A Segwitv0 wsh descriptor
37-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]
37+
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
3838
pub struct Wsh<Pk: MiniscriptKey> {
3939
/// underlying miniscript
4040
inner: WshInner<Pk>,
@@ -79,7 +79,7 @@ impl<Pk: MiniscriptKey> Wsh<Pk> {
7979
}
8080

8181
/// Wsh Inner
82-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]
82+
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
8383
pub enum WshInner<Pk: MiniscriptKey> {
8484
/// Sorted Multi
8585
SortedMulti(SortedMultiVec<Pk, Segwitv0>),
@@ -282,7 +282,7 @@ impl<P: MiniscriptKey, Q: MiniscriptKey> TranslatePk<P, Q> for Wsh<P> {
282282
}
283283

284284
/// A bare Wpkh descriptor at top level
285-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]
285+
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
286286
pub struct Wpkh<Pk: MiniscriptKey> {
287287
/// underlying publickey
288288
pk: Pk,

src/descriptor/sh.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ use super::{
3838
};
3939

4040
/// A Legacy p2sh Descriptor
41-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]
41+
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
4242
pub struct Sh<Pk: MiniscriptKey> {
4343
/// underlying miniscript
4444
inner: ShInner<Pk>,
4545
}
4646

4747
/// Sh Inner
48-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]
48+
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
4949
pub enum ShInner<Pk: MiniscriptKey> {
5050
/// Nested Wsh
5151
Wsh(Wsh<Pk>),

src/descriptor/sortedmulti.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use script_num_size;
2727
use {errstr, Error, ForEach, ForEachKey, Miniscript, MiniscriptKey, Satisfier, ToPublicKey};
2828

2929
/// Contents of a "sortedmulti" descriptor
30-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
30+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
3131
pub struct SortedMultiVec<Pk: MiniscriptKey, Ctx: ScriptContext> {
3232
/// signatures required
3333
pub k: usize,

src/miniscript/context.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@
1212
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
1313
//
1414

15+
use std::{fmt, hash};
16+
1517
use miniscript::limits::{
1618
MAX_OPS_PER_SCRIPT, MAX_SCRIPTSIG_SIZE, MAX_SCRIPT_ELEMENT_SIZE, MAX_SCRIPT_SIZE,
1719
MAX_STANDARD_P2WSH_SCRIPT_SIZE, MAX_STANDARD_P2WSH_STACK_ITEMS,
1820
};
1921
use miniscript::types;
20-
use std::fmt;
2122
use util::witness_to_scriptsig;
2223
use Error;
2324
use {Miniscript, MiniscriptKey, Terminal};
25+
2426
/// Error for Script Context
2527
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
2628
pub enum ScriptContextError {
@@ -106,7 +108,7 @@ impl fmt::Display for ScriptContextError {
106108
/// context under which the script is used.
107109
/// For example, disallowing uncompressed keys in Segwit context
108110
pub trait ScriptContext:
109-
fmt::Debug + Clone + Ord + PartialOrd + Eq + PartialEq + private::Sealed
111+
fmt::Debug + Clone + Ord + PartialOrd + Eq + PartialEq + hash::Hash + private::Sealed
110112
{
111113
/// Depending on ScriptContext, fragments can be malleable. For Example,
112114
/// under Legacy context, PkH is malleable because it is possible to

0 commit comments

Comments
 (0)