Skip to content

Commit 59b771d

Browse files
committed
chore: upgrade bitcoin rpc dependency
1 parent 434dc1d commit 59b771d

File tree

25 files changed

+281
-227
lines changed

25 files changed

+281
-227
lines changed

Cargo.lock

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

bitcoin/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ light-client = []
1313

1414
[dependencies]
1515
thiserror = "1.0"
16-
bitcoincore-rpc = { git = "https://github.com/rust-bitcoin/rust-bitcoincore-rpc", rev = "bde02d7fbf031df7d3a49946ec0e7f1abde34e58" }
16+
bitcoincore-rpc = { git = "https://github.com/rust-bitcoin/rust-bitcoincore-rpc", rev = "7bd815f1e1ae721404719ee8e6867064b7c68494" }
1717
hex = "0.4.2"
1818
async-trait = "0.1.40"
1919
tokio = { version = "1.0", features = ["full"] }

bitcoin/src/electrs/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bitcoincore_rpc::bitcoin::{
2-
consensus::encode::Error as BitcoinEncodeError, hashes::hex::Error as HexError,
3-
util::address::Error as BitcoinAddressError,
2+
address::Error as BitcoinAddressError, consensus::encode::Error as BitcoinEncodeError,
3+
hashes::hex::Error as HexError,
44
};
55
use reqwest::{Error as ReqwestError, StatusCode};
66
use serde_json::Error as SerdeJsonError;

bitcoin/src/electrs/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
mod error;
22
mod types;
33

4+
use bitcoincore_rpc::bitcoin::ScriptBuf;
45
pub use error::Error;
56
pub use types::*;
67

78
use crate::{
89
deserialize, opcodes, serialize, Address, Block, BlockHash, BlockHeader, Builder as ScriptBuilder, FromHex,
9-
Network, OutPoint, Script, SignedAmount, ToHex, Transaction, Txid, H256,
10+
Network, OutPoint, SignedAmount, Transaction, Txid, H256,
1011
};
1112
use futures::future::{join_all, try_join};
1213
use reqwest::{Client, Url};
@@ -185,7 +186,7 @@ impl ElectrsClient {
185186
.collect::<Result<Vec<_>, Error>>()
186187
}
187188

188-
pub(crate) async fn get_script_pubkey(&self, outpoint: OutPoint) -> Result<Script, Error> {
189+
pub(crate) async fn get_script_pubkey(&self, outpoint: OutPoint) -> Result<ScriptBuf, Error> {
189190
let tx: TransactionValue = self
190191
.get_and_decode(&format!("/tx/{txid}", txid = outpoint.txid))
191192
.await?;
@@ -215,7 +216,7 @@ impl ElectrsClient {
215216
let txid = self
216217
.cli
217218
.post(url)
218-
.body(serialize(&tx).to_hex())
219+
.body(hex::encode(serialize(&tx)))
219220
.send()
220221
.await?
221222
.error_for_status()?
@@ -232,7 +233,7 @@ impl ElectrsClient {
232233
let mut transactions: Vec<TransactionValue> = self
233234
.get_and_decode(&format!(
234235
"/scripthash/{scripthash}/txs/chain/{last_seen_txid}",
235-
scripthash = script_hash.to_hex()
236+
scripthash = hex::encode(&script_hash)
236237
))
237238
.await?;
238239
let page_size = transactions.len();
@@ -257,7 +258,7 @@ impl ElectrsClient {
257258
) -> Result<Option<Txid>, Error> {
258259
let script = ScriptBuilder::new()
259260
.push_opcode(opcodes::OP_RETURN)
260-
.push_slice(data.as_bytes())
261+
.push_slice(&data.as_fixed_bytes())
261262
.into_script();
262263

263264
let script_hash = {
@@ -302,11 +303,11 @@ mod tests {
302303
async fn test_electrs(url: &str, script_hex: &str, expected_txid: &str) {
303304
let script_bytes = Vec::from_hex(script_hex).unwrap();
304305
let script_hash = Sha256Hash::hash(&script_bytes);
305-
let expected_txid = Txid::from_hex(expected_txid).unwrap();
306+
let expected_txid = Txid::from_str(expected_txid).unwrap();
306307

307308
let electrs_client = ElectrsClient::new(Some(url.to_owned()), Network::Bitcoin).unwrap();
308309
let txs = electrs_client
309-
.get_txs_by_scripthash(script_hash.to_vec())
310+
.get_txs_by_scripthash(script_hash.to_byte_array().to_vec())
310311
.await
311312
.unwrap();
312313
assert!(txs.iter().any(|tx| tx.txid.eq(&expected_txid)));

bitcoin/src/electrs/types.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use crate::{BlockHash, Script, Txid};
1+
use crate::{BlockHash, Txid};
2+
use bitcoincore_rpc::bitcoin::ScriptBuf;
23
use serde::Deserialize;
34

45
// https://github.com/Blockstream/electrs/blob/adedee15f1fe460398a7045b292604df2161adc0/src/util/transaction.rs#L17-L26
@@ -19,7 +20,7 @@ pub struct TxInValue {
1920
pub txid: Txid,
2021
pub vout: u32,
2122
pub prevout: Option<TxOutValue>,
22-
pub scriptsig: Script,
23+
pub scriptsig: ScriptBuf,
2324
pub scriptsig_asm: String,
2425
#[serde(skip_serializing_if = "Option::is_none")]
2526
pub witness: Option<Vec<String>>,
@@ -34,7 +35,7 @@ pub struct TxInValue {
3435
// https://github.com/Blockstream/electrs/blob/adedee15f1fe460398a7045b292604df2161adc0/src/rest.rs#L239-L270
3536
#[derive(Deserialize)]
3637
pub struct TxOutValue {
37-
pub scriptpubkey: Script,
38+
pub scriptpubkey: ScriptBuf,
3839
pub scriptpubkey_asm: String,
3940
pub scriptpubkey_type: String,
4041
#[serde(skip_serializing_if = "Option::is_none")]

bitcoin/src/error.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use crate::{BitcoinError, BitcoinLightError, ElectrsError};
22
use bitcoincore_rpc::{
33
bitcoin::{
4+
address::Error as AddressError,
45
consensus::encode::Error as BitcoinEncodeError,
56
hashes::{hex::Error as HashHexError, Error as HashesError},
7+
key::Error as KeyError,
68
secp256k1::Error as Secp256k1Error,
7-
util::{address::Error as AddressError, key::Error as KeyError},
89
},
910
jsonrpc::{error::RpcError, Error as JsonRpcError},
1011
};
@@ -74,6 +75,8 @@ pub enum Error {
7475
MissingBitcoinFeeInfo,
7576
#[error("FailedToConstructWalletName")]
7677
FailedToConstructWalletName,
78+
#[error("AddressError: {0}")]
79+
AddressError(#[from] AddressError),
7780
}
7881

7982
impl Error {

bitcoin/src/iter.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ async fn get_best_block_info(rpc: &DynBitcoinCoreApi) -> Result<(u32, BlockHash)
193193
mod tests {
194194
use super::*;
195195
use crate::*;
196-
use bitcoincore_rpc::bitcoin::PackedLockTime;
197-
pub use bitcoincore_rpc::bitcoin::{Address, Amount, Network, PublicKey, TxMerkleNode};
196+
use bitcoincore_rpc::bitcoin::{absolute::Height, block::Version, locktime::absolute::LockTime, CompactTarget};
197+
pub use bitcoincore_rpc::bitcoin::{Address, Amount, Network, PublicKey};
198198
use sp_core::H256;
199199

200200
mockall::mock! {
@@ -281,7 +281,7 @@ mod tests {
281281
fn dummy_tx(value: i32) -> Transaction {
282282
Transaction {
283283
version: value,
284-
lock_time: PackedLockTime(1),
284+
lock_time: LockTime::Blocks(Height::ZERO),
285285
input: vec![],
286286
output: vec![],
287287
}
@@ -291,8 +291,8 @@ mod tests {
291291
Block {
292292
txdata: transactions.into_iter().map(dummy_tx).collect(),
293293
header: BlockHeader {
294-
version: 4,
295-
bits: 0,
294+
version: Version::from_consensus(4),
295+
bits: CompactTarget::from_consensus(0),
296296
nonce: 0,
297297
time: 0,
298298
prev_blockhash: next_hash,

0 commit comments

Comments
 (0)