Skip to content

Commit 2924567

Browse files
committed
Update to rust-elements v0.19
And fix some compatibility issues with the changes introduced in rust-bitcoin v0.28.
1 parent 93fff34 commit 2924567

File tree

8 files changed

+58
-28
lines changed

8 files changed

+58
-28
lines changed

Cargo.lock

Lines changed: 12 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ bitcoin = { version = "0.28", features = [ "use-serde" ] }
2626
clap = "2.33.3"
2727
crossbeam-channel = "0.5.0"
2828
dirs = "4.0.0"
29-
elements = { version = "0.18", features = [ "serde-feature" ], optional = true }
29+
elements = { version = "0.19", features = [ "serde-feature" ], optional = true }
3030
error-chain = "0.12.4"
3131
glob = "0.3"
3232
hex = "0.4.2"
@@ -71,8 +71,3 @@ codegen-units = 1
7171
[patch.crates-io.electrum-client]
7272
git = "https://github.com/Blockstream/rust-electrum-client"
7373
rev = "d3792352992a539afffbe11501d1aff9fd5b919d" # add-peer branch
74-
75-
# needed for https://github.com/ElementsProject/rust-elements/pull/98 until a new release is made
76-
[patch.crates-io.elements]
77-
git = "https://github.com/ElementsProject/rust-elements"
78-
rev = "d988bd7ed9cf539b8fea0da042efa5a4e1eef86f"

src/elements/mod.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,29 @@ impl From<&TxIn> for IssuanceValue {
7474
}
7575
}
7676
}
77+
78+
// Compatibility for Transaction/Block methods between rust-bitcoin and rust-elements
79+
// rust-bitcoin deprecated the 'get_' prefix in https://github.com/rust-bitcoin/rust-bitcoin/pull/861,
80+
// while rust-elements still uses it. This allows using the prefix-less methods to avoid the deprecation warnings.
81+
pub trait EBCompact {
82+
fn weight(&self) -> usize;
83+
fn size(&self) -> usize;
84+
}
85+
86+
impl EBCompact for elements::Transaction {
87+
fn weight(&self) -> usize {
88+
self.get_weight()
89+
}
90+
fn size(&self) -> usize {
91+
self.get_size()
92+
}
93+
}
94+
95+
impl EBCompact for elements::Block {
96+
fn weight(&self) -> usize {
97+
self.get_weight()
98+
}
99+
fn size(&self) -> usize {
100+
self.get_size()
101+
}
102+
}

src/new_index/fetch.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use rayon::prelude::*;
44
use bitcoin::consensus::encode::{deserialize, Decodable};
55
#[cfg(feature = "liquid")]
66
use elements::encode::{deserialize, Decodable};
7+
#[cfg(feature = "liquid")]
8+
use crate::elements::EBCompact;
79

810
use std::collections::HashMap;
911
use std::fs;

src/rest.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use hyperlocal::UnixServerExt;
2323
use std::fs;
2424
#[cfg(feature = "liquid")]
2525
use {
26-
crate::elements::{peg::PegoutValue, AssetSorting, IssuanceValue},
26+
crate::elements::{peg::PegoutValue, AssetSorting, IssuanceValue, EBCompact},
2727
elements::{
2828
confidential::{Asset, Nonce, Value},
2929
encode, AssetId,
@@ -438,9 +438,9 @@ impl From<Utxo> for UtxoValue {
438438
surjection_proof: utxo
439439
.witness
440440
.surjection_proof
441-
.map_or(vec![], |p| p.serialize()),
441+
.map_or(vec![], |p| (*p).serialize()),
442442
#[cfg(feature = "liquid")]
443-
range_proof: utxo.witness.rangeproof.map_or(vec![], |p| p.serialize()),
443+
range_proof: utxo.witness.rangeproof.map_or(vec![], |p| (*p).serialize()),
444444
}
445445
}
446446
}

src/util/block.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ use std::slice;
99
use time::format_description::well_known::Rfc3339;
1010
use time::OffsetDateTime as DateTime;
1111

12+
#[cfg(feature = "liquid")]
13+
use crate::elements::EBCompact;
14+
1215
const MTP_SPAN: usize = 11;
1316

1417
#[derive(Debug, Serialize, Deserialize, Clone)]

src/util/fees.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use crate::chain::{Network, Transaction, TxOut};
22
use std::collections::HashMap;
33

4+
#[cfg(feature = "liquid")]
5+
use crate::elements::EBCompact;
6+
47
const VSIZE_BIN_WIDTH: u32 = 50_000; // in vbytes
58

69
pub struct TxFeeInfo {

src/util/script.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,14 @@ pub fn get_innerscripts(txin: &TxIn, prevout: &TxOut) -> InnerScripts {
5656
let witness = &txin.witness;
5757
#[cfg(feature = "liquid")]
5858
let witness = &witness.script_witness;
59-
witness.iter().last().map(Vec::from).map(Script::from)
59+
60+
// rust-bitcoin returns witness items as a [u8] slice, while rust-elements returns a Vec<u8>
61+
#[cfg(not(feature = "liquid"))]
62+
let wit_to_vec = Vec::from;
63+
#[cfg(feature = "liquid")]
64+
let wit_to_vec = Clone::clone;
65+
66+
witness.iter().last().map(wit_to_vec).map(Script::from)
6067
} else {
6168
None
6269
};

0 commit comments

Comments
 (0)