Skip to content

Commit 7992726

Browse files
authored
Merge pull request #7 from chaintope/tapyrus_chain_crate
tapyrify the chain crate
2 parents 473ef97 + 863039d commit 7992726

25 files changed

Lines changed: 212 additions & 211 deletions

.github/workflows/code_coverage.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@ jobs:
3838
python-version: '3.9'
3939
- name: Install python dependencies
4040
run: pip install hwi==2.1.1 protobuf==3.20.1
41-
- name: Test
41+
- name: Test Chain
42+
working-directory: ./crates/chain
4243
run: cargo test --all-features
44+
- name: "[Pending]Test"
45+
# run: cargo test --all-features
46+
run: echo "Pending other crates"
4347
- name: Make coverage directory
4448
run: mkdir coverage
4549
- name: Run grcov

.github/workflows/cont_integration.yml

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
clippy: true
1515
- version: 1.63.0 # MSRV
1616
features:
17-
- --no-default-features
17+
- --no-default-features --features tapyrus/no-std,miniscript/no-std,hashbrown
1818
- --all-features
1919
steps:
2020
- name: checkout
@@ -35,10 +35,18 @@ jobs:
3535
cargo update -p home --precise "0.5.5"
3636
cargo update -p proptest --precise "1.2.0"
3737
cargo update -p url --precise "2.5.0"
38-
- name: Build
38+
- name: Build Chain
39+
working-directory: ./crates/chain
3940
run: cargo build ${{ matrix.features }}
40-
- name: Test
41+
- name: "[Pending]Build"
42+
run: echo "Pending other crates"
43+
# run: cargo build ${{ matrix.features }}
44+
- name: Test Chain
45+
working-directory: ./crates/chain
4146
run: cargo test ${{ matrix.features }}
47+
- name: "[Pending]Test"
48+
run: echo "Pending other crates"
49+
# run: cargo test ${{ matrix.features }}
4250

4351
check-no-std:
4452
name: Check no_std
@@ -58,15 +66,17 @@ jobs:
5866
- name: Check bdk_chain
5967
working-directory: ./crates/chain
6068
# TODO "--target thumbv6m-none-eabi" should work but currently does not
61-
run: cargo check --no-default-features --features bitcoin/no-std,miniscript/no-std,hashbrown
62-
- name: Check bdk wallet
69+
run: cargo check --no-default-features --features tapyrus/no-std,miniscript/no-std,hashbrown
70+
- name: "[Pending]Check bdk wallet"
6371
working-directory: ./crates/wallet
6472
# TODO "--target thumbv6m-none-eabi" should work but currently does not
65-
run: cargo check --no-default-features --features bitcoin/no-std,miniscript/no-std,bdk_chain/hashbrown
66-
- name: Check esplora
73+
run: echo "Pending"
74+
# run: cargo check --no-default-features --features tapyrus/no-std,miniscript/no-std,bdk_chain/hashbrown
75+
- name: "[Pending]Check esplora"
6776
working-directory: ./crates/esplora
6877
# TODO "--target thumbv6m-none-eabi" should work but currently does not
69-
run: cargo check --no-default-features --features bitcoin/no-std,miniscript/no-std,bdk_chain/hashbrown
78+
run: echo "Pending"
79+
# run: cargo check --no-default-features --features tapyrus/no-std,miniscript/no-std,bdk_chain/hashbrown
7080

7181
check-wasm:
7282
name: Check WASM
@@ -90,12 +100,14 @@ jobs:
90100
target: "wasm32-unknown-unknown"
91101
- name: Rust Cache
92102
uses: Swatinem/[email protected]
93-
- name: Check bdk wallet
103+
- name: "[Pending]Check bdk wallet"
94104
working-directory: ./crates/wallet
95-
run: cargo check --target wasm32-unknown-unknown --no-default-features --features bitcoin/no-std,miniscript/no-std,bdk_chain/hashbrown,dev-getrandom-wasm
96-
- name: Check esplora
105+
run: echo "Pending"
106+
# run: cargo check --target wasm32-unknown-unknown --no-default-features --features tapyrus/no-std,miniscript/no-std,bdk_chain/hashbrown,dev-getrandom-wasm
107+
- name: "[Pending]Check esplora"
97108
working-directory: ./crates/esplora
98-
run: cargo check --target wasm32-unknown-unknown --no-default-features --features bitcoin/no-std,miniscript/no-std,bdk_chain/hashbrown,async
109+
run: echo "Pending"
110+
# run: cargo check --target wasm32-unknown-unknown --no-default-features --features tapyrus/no-std,miniscript/no-std,bdk_chain/hashbrown,async
99111

100112
fmt:
101113
name: Rust fmt
@@ -127,4 +139,10 @@ jobs:
127139
- uses: actions-rs/clippy-check@v1
128140
with:
129141
token: ${{ secrets.GITHUB_TOKEN }}
130-
args: --all-features --all-targets -- -D warnings
142+
args: --manifest-path crates/chain/Cargo.toml --all-features --all-targets -- -D warnings
143+
# - uses: actions-rs/clippy-check@v1
144+
# with:
145+
# token: ${{ secrets.GITHUB_TOKEN }}
146+
# args: --all-features --all-targets -- -D warnings
147+
- name: "[Pending]Clippy"
148+
run: echo "Pending other crates"

.github/workflows/nightly_docs.yml

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,16 @@ jobs:
1818
- name: Rust Cache
1919
uses: Swatinem/[email protected]
2020
- name: Build docs
21+
working-directory: ./crates/chain
2122
run: cargo doc --no-deps
2223
env:
2324
RUSTDOCFLAGS: '--cfg docsrs -Dwarnings'
25+
# - name: Build docs
26+
# run: cargo doc --no-deps
27+
# env:
28+
# RUSTDOCFLAGS: '--cfg docsrs -Dwarnings'
2429
- name: Upload artifact
2530
uses: actions/upload-artifact@v2
2631
with:
2732
name: built-docs
2833
path: ./target/doc/*
29-
30-
publish_docs:
31-
name: 'Publish docs'
32-
if: github.ref == 'refs/heads/master'
33-
needs: [build_docs]
34-
runs-on: ubuntu-latest
35-
steps:
36-
- name: Checkout `bitcoindevkit.org`
37-
uses: actions/checkout@v2
38-
with:
39-
ssh-key: ${{ secrets.DOCS_PUSH_SSH_KEY }}
40-
repository: bitcoindevkit/bitcoindevkit.org
41-
ref: master
42-
- name: Create directories
43-
run: mkdir -p ./docs/.vuepress/public/docs-rs/bdk/nightly
44-
- name: Remove old latest
45-
run: rm -rf ./docs/.vuepress/public/docs-rs/bdk/nightly/latest
46-
- name: Download built docs
47-
uses: actions/download-artifact@v1
48-
with:
49-
name: built-docs
50-
path: ./docs/.vuepress/public/docs-rs/bdk/nightly/latest
51-
- name: Configure git
52-
run: git config user.email "[email protected]" && git config user.name "github-actions"
53-
- name: Commit
54-
continue-on-error: true # If there's nothing to commit this step fails, but it's fine
55-
run: git add ./docs/.vuepress/public/docs-rs && git commit -m "Publish autogenerated nightly docs"
56-
- name: Push
57-
run: git push origin master

crates/chain/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ readme = "README.md"
1414

1515
[dependencies]
1616
# For no-std, remember to enable the bitcoin/no-std feature
17-
bitcoin = { version = "0.31.0", default-features = false }
17+
tapyrus = { git = "https://github.com/chaintope/rust-tapyrus", branch = "update_on_bitcoin_0.31.x", default-features = false, subdirectory = "tapyrus" }
1818
serde_crate = { package = "serde", version = "1", optional = true, features = ["derive", "rc"] }
1919

2020
# Use hashbrown as a feature flag to have HashSet and HashMap from it.
2121
hashbrown = { version = "0.9.1", optional = true, features = ["serde"] }
22-
miniscript = { version = "11.0.0", optional = true, default-features = false }
22+
miniscript = { git = "https://github.com/chaintope/rust-miniscript", branch = "master", optional = true, default-features = false }
2323

2424
[dev-dependencies]
2525
rand = "0.8"
2626
proptest = "1.2.0"
2727

2828
[features]
2929
default = ["std", "miniscript"]
30-
std = ["bitcoin/std", "miniscript?/std"]
31-
serde = ["serde_crate", "bitcoin/serde", "miniscript?/serde"]
30+
std = ["tapyrus/std", "miniscript?/std"]
31+
serde = ["serde_crate", "tapyrus/serde", "miniscript?/serde"]

crates/chain/src/chain_data.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use bitcoin::{hashes::Hash, BlockHash, OutPoint, TxOut, Txid};
1+
use tapyrus::{hashes::Hash, BlockHash, OutPoint, TxOut, Txid};
22

33
use crate::{Anchor, AnchorFromBlockPosition, COINBASE_MATURITY};
44

@@ -110,7 +110,7 @@ impl Anchor for BlockId {
110110
}
111111

112112
impl AnchorFromBlockPosition for BlockId {
113-
fn from_block_position(_block: &bitcoin::Block, block_id: BlockId, _tx_pos: usize) -> Self {
113+
fn from_block_position(_block: &tapyrus::Block, block_id: BlockId, _tx_pos: usize) -> Self {
114114
block_id
115115
}
116116
}
@@ -176,7 +176,7 @@ impl Anchor for ConfirmationHeightAnchor {
176176
}
177177

178178
impl AnchorFromBlockPosition for ConfirmationHeightAnchor {
179-
fn from_block_position(_block: &bitcoin::Block, block_id: BlockId, _tx_pos: usize) -> Self {
179+
fn from_block_position(_block: &tapyrus::Block, block_id: BlockId, _tx_pos: usize) -> Self {
180180
Self {
181181
anchor_block: block_id,
182182
confirmation_height: block_id.height,
@@ -216,7 +216,7 @@ impl Anchor for ConfirmationTimeHeightAnchor {
216216
}
217217

218218
impl AnchorFromBlockPosition for ConfirmationTimeHeightAnchor {
219-
fn from_block_position(block: &bitcoin::Block, block_id: BlockId, _tx_pos: usize) -> Self {
219+
fn from_block_position(block: &tapyrus::Block, block_id: BlockId, _tx_pos: usize) -> Self {
220220
Self {
221221
anchor_block: block_id,
222222
confirmation_height: block_id.height,

crates/chain/src/descriptor_ext.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{
22
alloc::{string::ToString, vec::Vec},
33
miniscript::{Descriptor, DescriptorPublicKey},
44
};
5-
use bitcoin::hashes::{hash_newtype, sha256, Hash};
5+
use tapyrus::hashes::{hash_newtype, sha256, Hash};
66

77
hash_newtype! {
88
/// Represents the ID of a descriptor, defined as the sha256 hash of
@@ -32,7 +32,7 @@ impl DescriptorExt for Descriptor<DescriptorPublicKey> {
3232
.expect("descriptor can't have hardened derivation")
3333
.script_pubkey()
3434
.dust_value()
35-
.to_sat()
35+
.to_tap()
3636
}
3737

3838
fn descriptor_id(&self) -> DescriptorId {

crates/chain/src/example_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(unused)]
22
use alloc::vec::Vec;
3-
use bitcoin::{
3+
use tapyrus::{
44
consensus,
55
hashes::{hex::FromHex, Hash},
66
Transaction,
@@ -19,7 +19,7 @@ pub fn tx_from_hex(s: &str) -> Transaction {
1919
}
2020

2121
pub fn new_hash<H: Hash>(s: &str) -> H {
22-
<H as bitcoin::hashes::Hash>::hash(s.as_bytes())
22+
<H as tapyrus::hashes::Hash>::hash(s.as_bytes())
2323
}
2424

2525
pub fn new_block_id(height: u32, hash: &str) -> BlockId {

crates/chain/src/indexed_tx_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Contains the [`IndexedTxGraph`] and associated types. Refer to the
22
//! [`IndexedTxGraph`] documentation for more.
33
use alloc::vec::Vec;
4-
use bitcoin::{Block, OutPoint, Transaction, TxOut, Txid};
4+
use tapyrus::{Block, OutPoint, Transaction, TxOut, Txid};
55

66
use crate::{
77
tx_graph::{self, TxGraph},

crates/chain/src/keychain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
#[cfg(feature = "miniscript")]
1414
mod txout_index;
15-
use bitcoin::Amount;
15+
use tapyrus::Amount;
1616
#[cfg(feature = "miniscript")]
1717
pub use txout_index::*;
1818

crates/chain/src/keychain/txout_index.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use crate::{
55
spk_iter::BIP32_MAX_INDEX,
66
DescriptorExt, DescriptorId, SpkIterator, SpkTxOutIndex,
77
};
8-
use bitcoin::{hashes::Hash, Amount, OutPoint, Script, SignedAmount, Transaction, TxOut, Txid};
98
use core::{
109
fmt::Debug,
1110
ops::{Bound, RangeBounds},
1211
};
12+
use tapyrus::{hashes::Hash, Amount, OutPoint, Script, SignedAmount, Transaction, TxOut, Txid};
1313

1414
use crate::Append;
1515

@@ -149,10 +149,10 @@ const DEFAULT_LOOKAHEAD: u32 = 25;
149149
///
150150
/// let mut txout_index = KeychainTxOutIndex::<MyKeychain>::default();
151151
///
152-
/// # let secp = bdk_chain::bitcoin::secp256k1::Secp256k1::signing_only();
153-
/// # let (external_descriptor,_) = Descriptor::<DescriptorPublicKey>::parse_descriptor(&secp, "tr([73c5da0a/86'/0'/0']xprv9xgqHN7yz9MwCkxsBPN5qetuNdQSUttZNKw1dcYTV4mkaAFiBVGQziHs3NRSWMkCzvgjEe3n9xV8oYywvM8at9yRqyaZVz6TYYhX98VjsUk/0/*)").unwrap();
154-
/// # let (internal_descriptor,_) = Descriptor::<DescriptorPublicKey>::parse_descriptor(&secp, "tr([73c5da0a/86'/0'/0']xprv9xgqHN7yz9MwCkxsBPN5qetuNdQSUttZNKw1dcYTV4mkaAFiBVGQziHs3NRSWMkCzvgjEe3n9xV8oYywvM8at9yRqyaZVz6TYYhX98VjsUk/1/*)").unwrap();
155-
/// # let (descriptor_42, _) = Descriptor::<DescriptorPublicKey>::parse_descriptor(&secp, "tr([73c5da0a/86'/0'/0']xprv9xgqHN7yz9MwCkxsBPN5qetuNdQSUttZNKw1dcYTV4mkaAFiBVGQziHs3NRSWMkCzvgjEe3n9xV8oYywvM8at9yRqyaZVz6TYYhX98VjsUk/2/*)").unwrap();
152+
/// # let secp = bdk_chain::tapyrus::secp256k1::Secp256k1::signing_only();
153+
/// # let (external_descriptor,_) = Descriptor::<DescriptorPublicKey>::parse_descriptor(&secp, "pkh([73c5da0a/86'/0'/0']xprv9xgqHN7yz9MwCkxsBPN5qetuNdQSUttZNKw1dcYTV4mkaAFiBVGQziHs3NRSWMkCzvgjEe3n9xV8oYywvM8at9yRqyaZVz6TYYhX98VjsUk/0/*)").unwrap();
154+
/// # let (internal_descriptor,_) = Descriptor::<DescriptorPublicKey>::parse_descriptor(&secp, "pkh([73c5da0a/86'/0'/0']xprv9xgqHN7yz9MwCkxsBPN5qetuNdQSUttZNKw1dcYTV4mkaAFiBVGQziHs3NRSWMkCzvgjEe3n9xV8oYywvM8at9yRqyaZVz6TYYhX98VjsUk/1/*)").unwrap();
155+
/// # let (descriptor_42, _) = Descriptor::<DescriptorPublicKey>::parse_descriptor(&secp, "pkh([73c5da0a/86'/0'/0']xprv9xgqHN7yz9MwCkxsBPN5qetuNdQSUttZNKw1dcYTV4mkaAFiBVGQziHs3NRSWMkCzvgjEe3n9xV8oYywvM8at9yRqyaZVz6TYYhX98VjsUk/2/*)").unwrap();
156156
/// let _ = txout_index.insert_descriptor(MyKeychain::External, external_descriptor);
157157
/// let _ = txout_index.insert_descriptor(MyKeychain::Internal, internal_descriptor);
158158
/// let _ = txout_index.insert_descriptor(MyKeychain::MyAppUser { user_id: 42 }, descriptor_42);
@@ -248,7 +248,7 @@ impl<K: Clone + Ord + Debug> Indexer for KeychainTxOutIndex<K> {
248248
}
249249
}
250250

251-
fn index_tx(&mut self, tx: &bitcoin::Transaction) -> Self::ChangeSet {
251+
fn index_tx(&mut self, tx: &tapyrus::Transaction) -> Self::ChangeSet {
252252
let mut changeset = super::ChangeSet::<K>::default();
253253
for (op, txout) in tx.output.iter().enumerate() {
254254
changeset.append(self.index_txout(OutPoint::new(tx.txid(), op as u32), txout));
@@ -270,7 +270,7 @@ impl<K: Clone + Ord + Debug> Indexer for KeychainTxOutIndex<K> {
270270
self.apply_changeset(changeset)
271271
}
272272

273-
fn is_tx_relevant(&self, tx: &bitcoin::Transaction) -> bool {
273+
fn is_tx_relevant(&self, tx: &tapyrus::Transaction) -> bool {
274274
self.inner.is_relevant(tx)
275275
}
276276
}

0 commit comments

Comments
 (0)