Skip to content

Commit ba4aad3

Browse files
committed
Merge #166: Update crate to bitcoin 0.30
74948ea fix issues with documentation (Andrew Poelstra) 0e20b8a ci: update to newer deps, modernize the CI job, add docs/clippy/fuzz (Andrew Poelstra) f18565e release 0.22.0 (Andrew Poelstra) 0356a14 remove remaining 0.30 conversion scaffolding (Andrew Poelstra) c929437 run clippy with --all-targets --all-features (Andrew Poelstra) 197149f run cargo clippy on the whole codebase (Andrew Poelstra) 53de6f2 update MSRV to 1.48.0 from 1.41.1 (Andrew Poelstra) 3542f91 rename bitcoin30 to bitcoin; delete bitcoin 0.29 dep (Andrew Poelstra) 5c071d0 convert everything else to bitcoin 0.30 :) (Andrew Poelstra) ed3381b bring transactions primitives up to bitcoin 0.30.0 (Andrew Poelstra) 443694b update key/signature material to bitcoin 0.30.0 (Andrew Poelstra) 6d67a6c update bitcoin_hashes to 0.12 (through bitcoin 0.30.0) (Andrew Poelstra) bfb0fe7 move locktime-related stuff to bitcoin 0.30; delete PackedLockTime (Andrew Poelstra) 35eaf43 update bech32/base58 to bitcoin 0.30.0 (Andrew Poelstra) 9f4ef0f confidential: remove `as_ref` which seems weirdly fragile (Andrew Poelstra) f8f90c1 port all types in crate to new `hex` module (Andrew Poelstra) e4a4af0 add `hex` module which is basically a copy/paste from bitcoin_hashes 0.11 (Andrew Poelstra) 97972df introduce bitcoin 0.30 as a (yet-unused) dependency (Andrew Poelstra) Pull request description: Apologies for taking so long. Every time I got started on this over the last 6 months I'd run into problems with hex encoding immediately and then stall out. I tried to break this into reasonably-digestible chunks. Each commit should compile and pass all tests independently. All the scaffolding should be gone by the end of the PR. I also updated the CI since the old version was 404ing, and while I was at it I added tests for documentation and clippy, so I needed a few more commits to fix that. ACKs for top commit: sanket1729: ACK 74948ea. Thanks for doing this in steps with smaller commits. Made this PR really easy to review. Tree-SHA512: bb2e8fcbf703c5d41c044e9ff1a88b8cd3a873dc10184e2410a370f2689eeb92d26db079c9dc4a87535abf5f87373a0f1da6022b515c692250ae064e4c6fd2eb
2 parents cd1d258 + 74948ea commit ba4aad3

41 files changed

Lines changed: 1147 additions & 794 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/rust.yml

Lines changed: 99 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,112 @@
1-
on: [push, pull_request]
1+
on:
2+
push:
3+
branches:
4+
- master
5+
pull_request: {}
26

37
name: Continuous integration
48

59
jobs:
6-
Tests:
7-
name: Tests
10+
Stable:
11+
name: Test - stable toolchain
812
runs-on: ubuntu-latest
913
strategy:
1014
fail-fast: false
11-
matrix:
12-
include:
13-
- rust: 1.58.0
14-
env:
15-
DO_FUZZ: true
16-
- rust: stable
17-
env:
18-
DO_INTEGRATION: true
19-
- rust: beta
20-
env:
21-
DUMMY: true
22-
- rust: nightly
23-
env:
24-
DUMMY: true
25-
- rust: 1.41.1
26-
env:
27-
PIN_VERSIONS: true
2815
steps:
16+
- name: Checkout Crate
17+
uses: actions/checkout@v3
18+
- name: Checkout Toolchain
19+
# https://github.com/dtolnay/rust-toolchain
20+
uses: dtolnay/rust-toolchain@stable
21+
- name: Running test script
22+
env:
23+
DO_DOCS: true
24+
DO_DOCSRS: false
25+
DO_FUZZ: false
26+
DO_INTEGRATION: false
27+
DO_LINT: true
28+
DO_FEATURE_MATRIX: true
29+
run: ./contrib/test.sh
30+
31+
Nightly:
32+
name: Test - nightly toolchain
33+
runs-on: ubuntu-latest
34+
strategy:
35+
fail-fast: false
36+
steps:
37+
- name: Checkout Crate
38+
uses: actions/checkout@v3
39+
- name: Checkout Toolchain
40+
uses: dtolnay/rust-toolchain@nightly
41+
- name: Running test script
42+
env:
43+
DO_DOCS: true
44+
DO_DOCSRS: true
45+
DO_FUZZ: false
46+
DO_INTEGRATION: false
47+
DO_LINT: false
48+
DO_FEATURE_MATRIX: true
49+
run: ./contrib/test.sh
50+
51+
MSRV:
52+
name: Test - 1.48.0 toolchain
53+
runs-on: ubuntu-latest
54+
strategy:
55+
fail-fast: false
56+
steps:
57+
- name: Checkout Crate
58+
uses: actions/checkout@v3
59+
- name: Checkout Toolchain
60+
uses: dtolnay/rust-toolchain@1.48.0
61+
- name: Running test script
62+
env:
63+
DO_DOCS: false
64+
DO_DOCSRS: false
65+
DO_FUZZ: false
66+
DO_INTEGRATION: false
67+
DO_LINT: false
68+
DO_FEATURE_MATRIX: true
69+
run: ./contrib/test.sh
70+
71+
Fuzz:
72+
name: Fuzztests - 1.58.0 toolchain
73+
runs-on: ubuntu-latest
74+
strategy:
75+
fail-fast: false
76+
steps:
77+
- name: Checkout Crate
78+
uses: actions/checkout@v3
79+
- name: Checkout Toolchain
80+
uses: dtolnay/rust-toolchain@1.58.0
2981
- name: Install test dependencies
30-
run: sudo apt-get install -y binutils-dev libunwind8-dev
82+
run: sudo apt-get update -y && sudo apt-get install -y binutils-dev libunwind8-dev libcurl4-openssl-dev libelf-dev libdw-dev cmake gcc libiberty-dev
83+
- name: Running test script
84+
env:
85+
DO_DOCS: false
86+
DO_DOCSRS: false
87+
DO_FUZZ: true
88+
DO_INTEGRATION: false
89+
DO_LINT: false
90+
DO_FEATURE_MATRIX: false
91+
run: ./contrib/test.sh
92+
93+
Integration:
94+
name: Integration tests - stable
95+
runs-on: ubuntu-latest
96+
strategy:
97+
fail-fast: false
98+
steps:
3199
- name: Checkout Crate
32-
uses: actions/checkout@v2
100+
uses: actions/checkout@v3
33101
- name: Checkout Toolchain
34-
uses: actions-rs/toolchain@v1
35-
with:
36-
profile: minimal
37-
toolchain: ${{ matrix.rust }}
38-
override: true
102+
uses: dtolnay/rust-toolchain@stable
39103
- name: Running test script
40-
env: ${{ matrix.env }}
104+
env:
105+
DO_DOCS: false
106+
DO_DOCSRS: false
107+
DO_FUZZ: false
108+
DO_INTEGRATION: true
109+
DO_LINT: false
110+
DO_FEATURE_MATRIX: false
41111
run: ./contrib/test.sh
112+

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11

2+
# 0.22.0 - 2023-06-08
3+
4+
* [https://github.com/ElementsProject/rust-elements/pull/159](Update `TapTweak`, and `schnorr` module generally, to match rust-bitcoin)
5+
* [https://github.com/ElementsProject/rust-elements/pull/160](Make `Prevouts` generic over type of `TxOut`)
6+
* [https://github.com/ElementsProject/rust-elements/pull/161](Add `Transaction::vsize` method)
7+
* [https://github.com/ElementsProject/rust-elements/pull/157](dynafed: extract `FullParams` from `Params`)
8+
* [https://github.com/ElementsProject/rust-elements/pull/166](**Update bitcoin dependency to 0.30.0 and secp256k1-zkp dependency to 0.9.1**)
9+
210
# 0.21.1 - 2022-10-21
311

412
- Add `PeginData::parse_tx`

Cargo.toml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "elements"
3-
version = "0.21.1"
3+
version = "0.22.0"
44
authors = ["Andrew Poelstra <apoelstra@blockstream.com>"]
55
description = "Library with support for de/serialization, parsing and executing on data structures and network messages related to Elements"
66
license = "CC0-1.0"
@@ -15,20 +15,16 @@ default = [ "json-contract" ]
1515
json-contract = [ "serde_json" ]
1616
"serde" = [
1717
"bitcoin/serde",
18-
"secp256k1-zkp/use-serde",
18+
"bitcoin/serde",
19+
"secp256k1-zkp/serde",
1920
"actual-serde"
2021
]
2122

2223
[dependencies]
23-
bitcoin = "0.29.1"
24-
secp256k1-zkp = { version = "0.7.0", features = [ "global-context", "bitcoin_hashes" ] }
24+
bitcoin = "0.30.0"
25+
secp256k1-zkp = { version = "0.9.1", features = [ "global-context", "bitcoin_hashes" ] }
2526
slip21 = "0.2.0"
2627

27-
# While this dependency is included in bitcoin, we need this to use the macros.
28-
# We should probably try keep this one in sync with the bitcoin version,
29-
# to avoid requiring two version of bitcoin_hashes.
30-
bitcoin_hashes = "0.11.0"
31-
3228
# Used for ContractHash::from_json_contract.
3329
serde_json = { version = "1.0", optional = true }
3430

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ structures and network messages related to Elements
1010

1111
## Minimum Supported Rust Version (MSRV)
1212

13-
This library should always compile with any combination of features on **Rust 1.41.1**.
13+
This library should always compile with any combination of features on **Rust 1.48.0**.

clippy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
msrv = "1.48.0"

contrib/test.sh

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,49 @@
22

33
FEATURES="serde"
44

5-
# Use toolchain if explicitly specified
6-
if [ -n "$TOOLCHAIN" ]
7-
then
8-
alias cargo="cargo +$TOOLCHAIN"
9-
fi
10-
115
# Pin dependencies as required if we are using MSRV toolchain.
12-
if cargo --version | grep "1\.41"; then
6+
if cargo --version | grep "1\.48"; then
137
# 1.0.157 uses syn 2.0 which requires edition 2018
148
cargo update -p serde --precise 1.0.156
15-
# 1.0.108 uses `matches!` macro so does not work with Rust 1.41.1, bad `syn` no biscuit.
16-
cargo update -p syn --precise 1.0.107
179
fi
1810

19-
# Test without any features first
20-
cargo test --verbose --no-default-features
21-
# Then test with the default features
22-
cargo test --verbose
23-
24-
# Also build and run each example to catch regressions
25-
cargo build --examples
26-
# run all examples
27-
run-parts ./target/debug/examples
28-
29-
# Test each feature
30-
for feature in ${FEATURES}
31-
do
32-
cargo test --verbose --features="$feature"
33-
done
11+
if [ "$DO_FEATURE_MATRX" = true ]
12+
then
13+
# Test without any features first
14+
cargo test --all --verbose --no-default-features
15+
# Then test with the default features
16+
cargo test --all --verbose
17+
# Then test with the default features
18+
cargo test --all --all-features --verbose
19+
20+
# Also build and run each example to catch regressions
21+
cargo build --examples
22+
# run all examples
23+
run-parts ./target/debug/examples
24+
25+
# Test each feature
26+
for feature in ${FEATURES}
27+
do
28+
cargo test --verbose --features="$feature"
29+
done
30+
fi
31+
32+
if [ "$DO_LINT" = true ]
33+
then
34+
cargo clippy --all-features --all-targets -- -D warnings
35+
fi
36+
37+
# Build the docs if told to (this only works with the nightly toolchain)
38+
if [ "$DO_DOCSRS" = true ]; then
39+
RUSTDOCFLAGS="--cfg docsrs -D warnings -D rustdoc::broken-intra-doc-links" cargo +nightly doc --all-features
40+
fi
41+
42+
# Build the docs with a stable toolchain, in unison with the DO_DOCSRS command
43+
# above this checks that we feature guarded docs imports correctly.
44+
if [ "$DO_DOCS" = true ]; then
45+
RUSTDOCFLAGS="-D warnings" cargo +stable doc --all-features
46+
fi
47+
3448

3549
# Fuzz if told to
3650
if [ "$DO_FUZZ" = true ]

elementsd-tests/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ edition = "2018"
88

99
[dependencies]
1010
base64 = "0.13.0"
11-
bitcoin30 = { package = "bitcoin", version = "0.30" }
11+
bitcoin = "0.30.0"
1212
elements = {path = "../"}
1313
elementsd = "0.8.0"
1414
rand = "0.8"

elementsd-tests/src/pset.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ extern crate rand;
66

77
use crate::{setup, Call};
88

9-
use bitcoin30::{self, Address, Amount};
10-
use elements::bitcoin::hashes::hex::ToHex;
11-
use elements::bitcoin::hashes::Hash;
9+
use bitcoin::{self, Address, Amount};
10+
use elements::hex::ToHex;
1211
use elements::encode::{deserialize, serialize};
12+
use elements::hashes::Hash;
1313
use elements::pset::PartiallySignedTransaction;
1414
use elements::{AssetId, ContractHash};
1515
use elementsd::bitcoincore_rpc::jsonrpc::serde_json::json;
@@ -52,7 +52,7 @@ fn tx_issuance() {
5252
let address_lbtc = elementsd.get_new_address();
5353
let prevout = elementsd.get_first_prevout();
5454

55-
let contract_hash = ContractHash::from_inner([0u8; 32]);
55+
let contract_hash = ContractHash::from_byte_array([0u8; 32]);
5656
let entropy = AssetId::generate_asset_entropy(prevout, contract_hash);
5757
let asset_id = AssetId::from_entropy(entropy.clone());
5858
let reissuance_id = AssetId::reissuance_token_from_entropy(entropy, true);
@@ -100,12 +100,12 @@ fn tx_pegin() {
100100
.send_to_address(&address, amount, None, None, None, None, None, None)
101101
.unwrap();
102102
let tx = bitcoind.client.get_raw_transaction(&txid, None).unwrap();
103-
let tx_bytes = bitcoin30::consensus::serialize(&tx);
103+
let tx_bytes = bitcoin::consensus::serialize(&tx);
104104
let vout = tx
105105
.output
106106
.iter()
107107
.position(|o| {
108-
let addr = Address::from_script(&o.script_pubkey, bitcoin30::Network::Regtest);
108+
let addr = Address::from_script(&o.script_pubkey, bitcoin::Network::Regtest);
109109
addr.unwrap().to_string() == pegin_address
110110
})
111111
.unwrap();

elementsd-tests/src/taproot.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ extern crate rand;
55

66
use crate::{Call, setup};
77

8-
use elements::bitcoin::{Amount, XOnlyPublicKey, KeyPair};
9-
use elements::bitcoin::hashes::hex::FromHex;
8+
use bitcoin::key::{XOnlyPublicKey, KeyPair};
9+
use bitcoin::Amount;
10+
use elements::hex::FromHex;
1011
use elements::confidential::{AssetBlindingFactor, ValueBlindingFactor};
1112
use elements::encode::{deserialize, serialize_hex};
1213
use elements::hashes::Hash;
@@ -16,7 +17,7 @@ use elements::sighash::{self, SigHashCache};
1617
use elements::taproot::{LeafVersion, TapTweakHash, TaprootBuilder, TaprootSpendInfo, TapLeafHash};
1718
use elements::OutPoint;
1819
use elements::{
19-
confidential, opcodes, AssetIssuance, BlockHash, PackedLockTime, SchnorrSig, SchnorrSigHashType, Script,
20+
confidential, opcodes, AssetIssuance, BlockHash, LockTime, SchnorrSig, SchnorrSigHashType, Script,
2021
Sequence, TxInWitness, TxOut, Txid,
2122
};
2223
use elements::{AddressParams, Transaction, TxIn, TxOutSecrets};
@@ -153,7 +154,7 @@ fn taproot_spend_test(
153154
// create a new spend that spends the above output
154155
let mut tx = Transaction {
155156
version: 2,
156-
lock_time: PackedLockTime::ZERO,
157+
lock_time: LockTime::ZERO,
157158
input: vec![],
158159
output: vec![],
159160
};
@@ -212,7 +213,7 @@ fn taproot_spend_test(
212213
test_data.internal_pk,
213214
test_data.spend_info.merkle_root(),
214215
);
215-
let tweak = secp256k1_zkp::Scalar::from_be_bytes(tweak.into_inner()).expect("hash value greater than curve order");
216+
let tweak = secp256k1_zkp::Scalar::from_be_bytes(tweak.to_byte_array()).expect("hash value greater than curve order");
216217
let sig = secp.sign_schnorr(
217218
&secp256k1_zkp::Message::from_slice(&sighash_msg[..]).unwrap(),
218219
&output_keypair.add_xonly_tweak(&secp, &tweak).unwrap(),
@@ -282,17 +283,17 @@ fn taproot_tests() {
282283
SchnorrSigHashType::AllPlusAnyoneCanPay,
283284
];
284285

285-
for conf_prevout in [true, false] {
286+
for &conf_prevout in &[true, false] {
286287
// whether the input is blinded
287-
for blind in [true, false] {
288+
for &blind in &[true, false] {
288289
// blind the current tx
289290
if !blind && conf_prevout {
290291
// trying to spend a confidential txout to all explicit transactions
291292
// This is not possible to do because we need to balance the blinding factors
292293
continue;
293294
}
294-
for script_spend in [true, false] {
295-
for sighash_ty in sighash_tys {
295+
for &script_spend in &[true, false] {
296+
for &sighash_ty in &sighash_tys {
296297
taproot_spend_test(
297298
&elementsd,
298299
&secp,

0 commit comments

Comments
 (0)