Skip to content

Commit 85b8baf

Browse files
committed
Update rust-elements to v0.24
1 parent a796e89 commit 85b8baf

File tree

11 files changed

+434
-151
lines changed

11 files changed

+434
-151
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ bitcoin = { version = "0.31", features = [ "serde" ] }
2424
clap = "2.33.3"
2525
crossbeam-channel = "0.5.0"
2626
dirs = "5.0.1"
27-
elements = { version = "0.23.0", features = [ "serde" ], optional = true }
27+
elements = { version = "0.24", features = [ "serde" ], optional = true }
2828
error-chain = "0.12.4"
2929
glob = "0.3"
3030
hex = { package = "hex-conservative", version = "0.1.1" }
@@ -59,7 +59,7 @@ electrum-client = { version = "0.8", optional = true }
5959

6060
[dev-dependencies]
6161
bitcoind = { version = "0.34", features = [ "25_0" ] }
62-
elementsd = { version = "0.8.0", features = [ "22_1_1" ] }
62+
elementsd = { version = "0.9", features = [ "22_1_1" ] }
6363
electrumd = { version = "0.1.0", features = [ "4_1_5" ] }
6464
ureq = { version = "2.9", default-features = false, features = [ "json" ] }
6565
tempfile = "3.10"

src/chain.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,6 @@ pub enum Network {
4141
LiquidRegtest,
4242
}
4343

44-
#[cfg(feature = "liquid")]
45-
pub const LIQUID_TESTNET_PARAMS: address::AddressParams = address::AddressParams {
46-
p2pkh_prefix: 36,
47-
p2sh_prefix: 19,
48-
blinded_prefix: 23,
49-
bech_hrp: "tex",
50-
blech_hrp: "tlq",
51-
};
52-
5344
impl Network {
5445
#[cfg(not(feature = "liquid"))]
5546
pub fn magic(self) -> u32 {
@@ -80,7 +71,7 @@ impl Network {
8071
match self {
8172
Network::Liquid => &address::AddressParams::LIQUID,
8273
Network::LiquidRegtest => &address::AddressParams::ELEMENTS,
83-
Network::LiquidTestnet => &LIQUID_TESTNET_PARAMS,
74+
Network::LiquidTestnet => &address::AddressParams::LIQUID_TESTNET,
8475
}
8576
}
8677

src/elements/mod.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,38 @@ impl From<&TxIn> for IssuanceValue {
6060
}
6161
}
6262
}
63+
64+
// Traits to make rust-elements' types compatible with the changes made in rust-bitcoin v0.31
65+
// Should hopefully eventually make its way into rust-elements itself.
66+
pub mod ebcompact {
67+
pub trait SizeMethod {
68+
fn total_size(&self) -> usize;
69+
}
70+
impl SizeMethod for elements::Block {
71+
fn total_size(&self) -> usize {
72+
self.size()
73+
}
74+
}
75+
impl SizeMethod for elements::Transaction {
76+
fn total_size(&self) -> usize {
77+
self.size()
78+
}
79+
}
80+
81+
pub trait ScriptMethods {
82+
fn is_p2wpkh(&self) -> bool;
83+
fn is_p2wsh(&self) -> bool;
84+
fn is_p2tr(&self) -> bool;
85+
}
86+
impl ScriptMethods for elements::Script {
87+
fn is_p2wpkh(&self) -> bool {
88+
self.is_v0_p2wpkh()
89+
}
90+
fn is_p2wsh(&self) -> bool {
91+
self.is_v0_p2wsh()
92+
}
93+
fn is_p2tr(&self) -> bool {
94+
self.is_v1_p2tr()
95+
}
96+
}
97+
}

src/elements/peg.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ impl PegoutValue {
3636
pub fn from_txout(txout: &TxOut, network: Network, parent_network: BNetwork) -> Option<Self> {
3737
let pegoutdata = get_pegout_data(txout, network, parent_network)?;
3838

39-
// pending https://github.com/ElementsProject/rust-elements/pull/69 is merged
4039
let scriptpubkey = pegoutdata.script_pubkey;
4140
let address = bitcoin::Address::from_script(&scriptpubkey, parent_network).ok();
4241

src/new_index/fetch.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use rayon::prelude::*;
22

3+
#[cfg(feature = "liquid")]
4+
use crate::elements::ebcompact::*;
35
#[cfg(not(feature = "liquid"))]
46
use bitcoin::consensus::encode::{deserialize, Decodable};
57
#[cfg(feature = "liquid")]

src/new_index/mempool.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use crate::daemon::Daemon;
1717
use crate::errors::*;
1818
use crate::metrics::{GaugeVec, HistogramOpts, HistogramVec, MetricOpts, Metrics};
1919
use crate::new_index::{
20-
compute_script_hash, schema::FullHash, ChainQuery, FundingInfo, ScriptStats, SpendingInfo,
21-
SpendingInput, TxHistoryInfo, Utxo,
20+
compute_script_hash, schema::FullHash, ChainQuery, FundingInfo, GetAmountVal, ScriptStats,
21+
SpendingInfo, SpendingInput, TxHistoryInfo, Utxo,
2222
};
2323
use crate::util::fees::{make_fee_histogram, TxFeeInfo};
2424
use crate::util::{extract_tx_prevouts, full_hash, has_prevout, is_spendable, Bytes};
@@ -380,7 +380,7 @@ impl Mempool {
380380
vin: input_index as u16,
381381
prev_txid: full_hash(&txi.previous_output.txid[..]),
382382
prev_vout: txi.previous_output.vout as u16,
383-
value: prevout.value.to_sat(),
383+
value: prevout.value.amount_value(),
384384
}),
385385
)
386386
});
@@ -399,7 +399,7 @@ impl Mempool {
399399
TxHistoryInfo::Funding(FundingInfo {
400400
txid: txid_bytes,
401401
vout: index as u16,
402-
value: txo.value.to_sat(),
402+
value: txo.value.amount_value(),
403403
}),
404404
)
405405
});

src/new_index/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ pub use self::fetch::{BlockEntry, FetchFrom};
1010
pub use self::mempool::Mempool;
1111
pub use self::query::Query;
1212
pub use self::schema::{
13-
compute_script_hash, parse_hash, ChainQuery, FundingInfo, Indexer, ScriptStats, SpendingInfo,
14-
SpendingInput, Store, TxHistoryInfo, TxHistoryKey, TxHistoryRow, Utxo,
13+
compute_script_hash, parse_hash, ChainQuery, FundingInfo, GetAmountVal, Indexer, ScriptStats,
14+
SpendingInfo, SpendingInput, Store, TxHistoryInfo, TxHistoryKey, TxHistoryRow, Utxo,
1515
};

src/new_index/schema.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rayon::prelude::*;
1212
use bitcoin::consensus::encode::{deserialize, serialize};
1313
#[cfg(feature = "liquid")]
1414
use elements::{
15+
confidential,
1516
encode::{deserialize, serialize},
1617
AssetId,
1718
};
@@ -112,9 +113,9 @@ pub struct Utxo {
112113
pub value: Value,
113114

114115
#[cfg(feature = "liquid")]
115-
pub asset: elements::confidential::Asset,
116+
pub asset: confidential::Asset,
116117
#[cfg(feature = "liquid")]
117-
pub nonce: elements::confidential::Nonce,
118+
pub nonce: confidential::Nonce,
118119
#[cfg(feature = "liquid")]
119120
pub witness: elements::TxOutWitness,
120121
}
@@ -1104,7 +1105,7 @@ fn index_transaction(
11041105
TxHistoryInfo::Funding(FundingInfo {
11051106
txid,
11061107
vout: txo_index as u16,
1107-
value: txo.value.to_sat(),
1108+
value: txo.value.amount_value(),
11081109
}),
11091110
);
11101111
rows.push(history.into_row());
@@ -1132,7 +1133,7 @@ fn index_transaction(
11321133
vin: txi_index as u16,
11331134
prev_txid: full_hash(&txi.previous_output.txid[..]),
11341135
prev_vout: txi.previous_output.vout as u16,
1135-
value: prev_txo.value.to_sat(),
1136+
value: prev_txo.value.amount_value(),
11361137
}),
11371138
);
11381139
rows.push(history.into_row());
@@ -1642,3 +1643,25 @@ fn from_utxo_cache(utxos_cache: CachedUtxoMap, chain: &ChainQuery) -> UtxoMap {
16421643
})
16431644
.collect()
16441645
}
1646+
1647+
// Get the amount value as gets stored in the DB and mempool tracker.
1648+
// For bitcoin it is the Amount's inner u64, for elements it is the confidential::Value itself.
1649+
pub trait GetAmountVal {
1650+
#[cfg(not(feature = "liquid"))]
1651+
fn amount_value(self) -> u64;
1652+
#[cfg(feature = "liquid")]
1653+
fn amount_value(self) -> confidential::Value;
1654+
}
1655+
1656+
#[cfg(not(feature = "liquid"))]
1657+
impl GetAmountVal for bitcoin::Amount {
1658+
fn amount_value(self) -> u64 {
1659+
self.to_sat()
1660+
}
1661+
}
1662+
#[cfg(feature = "liquid")]
1663+
impl GetAmountVal for confidential::Value {
1664+
fn amount_value(self) -> confidential::Value {
1665+
self
1666+
}
1667+
}

src/rest.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use std::str::FromStr;
2626

2727
#[cfg(feature = "liquid")]
2828
use {
29-
crate::elements::{peg::PegoutValue, AssetSorting, IssuanceValue},
29+
crate::elements::{ebcompact::*, peg::PegoutValue, AssetSorting, IssuanceValue},
3030
elements::{encode, secp256k1_zkp as zkp, AssetId},
3131
};
3232

@@ -159,7 +159,10 @@ impl TransactionValue {
159159

160160
TransactionValue {
161161
txid: tx.txid(),
162+
#[cfg(not(feature = "liquid"))]
162163
version: tx.version.0 as u32,
164+
#[cfg(feature = "liquid")]
165+
version: tx.version as u32,
163166
locktime: tx.lock_time.to_consensus_u32(),
164167
vin: vins,
165168
vout: vouts,
@@ -284,7 +287,7 @@ struct TxOutValue {
284287
impl TxOutValue {
285288
fn new(txout: &TxOut, config: &Config) -> Self {
286289
#[cfg(not(feature = "liquid"))]
287-
let value = txout.value;
290+
let value = txout.value.to_sat();
288291
#[cfg(feature = "liquid")]
289292
let value = txout.value.explicit();
290293

@@ -330,7 +333,7 @@ impl TxOutValue {
330333
scriptpubkey_asm: script_asm,
331334
scriptpubkey_address: script_addr,
332335
scriptpubkey_type: script_type.to_string(),
333-
value: value.to_sat(),
336+
value,
334337
#[cfg(feature = "liquid")]
335338
valuecommitment: txout.value.commitment(),
336339
#[cfg(feature = "liquid")]
@@ -1296,6 +1299,7 @@ impl From<std::string::FromUtf8Error> for HttpError {
12961299
}
12971300
}
12981301

1302+
#[cfg(not(feature = "liquid"))]
12991303
impl From<address::ParseError> for HttpError {
13001304
fn from(e: address::ParseError) -> Self {
13011305
HttpError::from(e.to_string())

src/util/script.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#[cfg(feature = "liquid")]
2+
use crate::elements::ebcompact::*;
3+
#[cfg(feature = "liquid")]
24
use elements::address as elements_address;
35

46
use crate::chain::{script, Network, Script, TxIn, TxOut};

0 commit comments

Comments
 (0)