Skip to content

Commit

Permalink
chore: upgrade bitcoin rpc dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
sander2 committed Jul 19, 2023
1 parent 434dc1d commit dcc7462
Show file tree
Hide file tree
Showing 18 changed files with 176 additions and 128 deletions.
67 changes: 51 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bitcoin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ light-client = []

[dependencies]
thiserror = "1.0"
bitcoincore-rpc = { git = "https://github.com/rust-bitcoin/rust-bitcoincore-rpc", rev = "bde02d7fbf031df7d3a49946ec0e7f1abde34e58" }
bitcoincore-rpc = { git = "https://github.com/rust-bitcoin/rust-bitcoincore-rpc", rev = "7bd815f1e1ae721404719ee8e6867064b7c68494" }
hex = "0.4.2"
async-trait = "0.1.40"
tokio = { version = "1.0", features = ["full"] }
Expand Down
4 changes: 2 additions & 2 deletions bitcoin/src/electrs/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bitcoincore_rpc::bitcoin::{
consensus::encode::Error as BitcoinEncodeError, hashes::hex::Error as HexError,
util::address::Error as BitcoinAddressError,
address::Error as BitcoinAddressError, consensus::encode::Error as BitcoinEncodeError,
hashes::hex::Error as HexError,
};
use reqwest::{Error as ReqwestError, StatusCode};
use serde_json::Error as SerdeJsonError;
Expand Down
11 changes: 6 additions & 5 deletions bitcoin/src/electrs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
mod error;
mod types;

use bitcoincore_rpc::bitcoin::ScriptBuf;
pub use error::Error;
pub use types::*;

use crate::{
deserialize, opcodes, serialize, Address, Block, BlockHash, BlockHeader, Builder as ScriptBuilder, FromHex,
Network, OutPoint, Script, SignedAmount, ToHex, Transaction, Txid, H256,
Network, OutPoint, SignedAmount, Transaction, Txid, H256,
};
use futures::future::{join_all, try_join};
use reqwest::{Client, Url};
Expand Down Expand Up @@ -185,7 +186,7 @@ impl ElectrsClient {
.collect::<Result<Vec<_>, Error>>()
}

pub(crate) async fn get_script_pubkey(&self, outpoint: OutPoint) -> Result<Script, Error> {
pub(crate) async fn get_script_pubkey(&self, outpoint: OutPoint) -> Result<ScriptBuf, Error> {
let tx: TransactionValue = self
.get_and_decode(&format!("/tx/{txid}", txid = outpoint.txid))
.await?;
Expand Down Expand Up @@ -215,7 +216,7 @@ impl ElectrsClient {
let txid = self
.cli
.post(url)
.body(serialize(&tx).to_hex())
.body(hex::encode(serialize(&tx)))
.send()
.await?
.error_for_status()?
Expand All @@ -232,7 +233,7 @@ impl ElectrsClient {
let mut transactions: Vec<TransactionValue> = self
.get_and_decode(&format!(
"/scripthash/{scripthash}/txs/chain/{last_seen_txid}",
scripthash = script_hash.to_hex()
scripthash = hex::encode(&script_hash)
))
.await?;
let page_size = transactions.len();
Expand All @@ -257,7 +258,7 @@ impl ElectrsClient {
) -> Result<Option<Txid>, Error> {
let script = ScriptBuilder::new()
.push_opcode(opcodes::OP_RETURN)
.push_slice(data.as_bytes())
.push_slice(&data.as_fixed_bytes())
.into_script();

let script_hash = {
Expand Down
7 changes: 4 additions & 3 deletions bitcoin/src/electrs/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{BlockHash, Script, Txid};
use crate::{BlockHash, Txid};
use bitcoincore_rpc::bitcoin::ScriptBuf;
use serde::Deserialize;

// https://github.com/Blockstream/electrs/blob/adedee15f1fe460398a7045b292604df2161adc0/src/util/transaction.rs#L17-L26
Expand All @@ -19,7 +20,7 @@ pub struct TxInValue {
pub txid: Txid,
pub vout: u32,
pub prevout: Option<TxOutValue>,
pub scriptsig: Script,
pub scriptsig: ScriptBuf,
pub scriptsig_asm: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub witness: Option<Vec<String>>,
Expand All @@ -34,7 +35,7 @@ pub struct TxInValue {
// https://github.com/Blockstream/electrs/blob/adedee15f1fe460398a7045b292604df2161adc0/src/rest.rs#L239-L270
#[derive(Deserialize)]
pub struct TxOutValue {
pub scriptpubkey: Script,
pub scriptpubkey: ScriptBuf,
pub scriptpubkey_asm: String,
pub scriptpubkey_type: String,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
5 changes: 4 additions & 1 deletion bitcoin/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::{BitcoinError, BitcoinLightError, ElectrsError};
use bitcoincore_rpc::{
bitcoin::{
address::Error as AddressError,
consensus::encode::Error as BitcoinEncodeError,
hashes::{hex::Error as HashHexError, Error as HashesError},
key::Error as KeyError,
secp256k1::Error as Secp256k1Error,
util::{address::Error as AddressError, key::Error as KeyError},
},
jsonrpc::{error::RpcError, Error as JsonRpcError},
};
Expand Down Expand Up @@ -74,6 +75,8 @@ pub enum Error {
MissingBitcoinFeeInfo,
#[error("FailedToConstructWalletName")]
FailedToConstructWalletName,
#[error("AddressError: {0}")]
AddressError(#[from] AddressError),
}

impl Error {
Expand Down
4 changes: 2 additions & 2 deletions bitcoin/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ async fn get_best_block_info(rpc: &DynBitcoinCoreApi) -> Result<(u32, BlockHash)
mod tests {
use super::*;
use crate::*;
use bitcoincore_rpc::bitcoin::PackedLockTime;
use bitcoincore_rpc::bitcoin::locktime::absolute::LockTime;
pub use bitcoincore_rpc::bitcoin::{Address, Amount, Network, PublicKey, TxMerkleNode};
use sp_core::H256;

Expand Down Expand Up @@ -281,7 +281,7 @@ mod tests {
fn dummy_tx(value: i32) -> Transaction {
Transaction {
version: value,
lock_time: PackedLockTime(1),
lock_time: LockTime(1),
input: vec![],
output: vec![],
}
Expand Down
Loading

0 comments on commit dcc7462

Please sign in to comment.