Skip to content

Commit

Permalink
Update bitcoin/bitcoinrpc deleting incompatible methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lsunsi committed Oct 28, 2023
1 parent cdd9960 commit ba65951
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 71 deletions.
7 changes: 2 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ name = "btcore"
version = "0.1.0"
edition = "2021"

[lib]
name = "btcore"

[dependencies]
bitcoin = { version= "0.29.0", features=["std"], default-features = false }
bitcoincore-rpc = { branch = "master", git = "https://github.com/bipa-app/rust-bitcoincore-rpc.git"}
bitcoin = { version= "0.30.0", features = ["std"], default-features = false }
bitcoincore-rpc = { version = "0.17.0", default-features = false }
tokio = { version = "1.12.0", features = ["rt", "macros"], default-features = false }
tracing = { version = "0.1.37", default-features = false }
70 changes: 4 additions & 66 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use bitcoin::{Address, Amount, BlockHash, Txid};
use bitcoin::{address::NetworkUnchecked, Address, Amount, BlockHash, Txid};
use bitcoincore_rpc::{
bitcoincore_rpc_json::GetTransactionResult,
json::{AddressType, GetBalancesResult, ListTransactionResult},
RpcApi,
};
use std::{collections::HashMap, future::Future, sync::Arc};
use std::{future::Future, sync::Arc};
use tracing::Instrument;

pub use bitcoincore_rpc as rpc;
Expand Down Expand Up @@ -98,72 +98,10 @@ impl Btc {
.instrument(span!("gettransaction"))
}

pub fn send_to_address(
&self,
address: Address,
amount_satoshi: i64,
fee_rate: Option<i32>,
) -> impl Future<Output = bitcoincore_rpc::Result<bitcoin::Txid>> {
let client = self.client.clone();

async move {
tokio::task::spawn_blocking(move || {
client.send_to_address(
&address,
Amount::from_sat(amount_satoshi as u64),
Some(""),
Some(""),
Some(true),
Some(true),
None,
None,
None,
fee_rate,
)
})
.await
.unwrap()
}
.instrument(span!("sendtoaddress"))
}

pub fn send_many(
&self,
addresses: HashMap<Address, Amount>,
fee_rate: i32,
) -> impl Future<Output = bitcoincore_rpc::Result<bitcoin::Txid>> {
let client = self.client.clone();

async move {
tokio::task::spawn_blocking(move || {
client.send_many(
addresses,
Some(""),
None,
Some(true),
None,
None,
Some(fee_rate),
)
})
.await
.unwrap()
}
.instrument(span!("sendmany"))
}

/// DANGEROUS: this call will block the thread. it is not safe unless you know what you're doing.
pub fn generate_address_blocking(
&self,
address_type: AddressType,
) -> bitcoincore_rpc::Result<Address> {
self.client.get_new_address(None, Some(address_type))
}

pub fn generate_address_async(
pub fn generate_address(
&self,
address_type: AddressType,
) -> impl Future<Output = bitcoincore_rpc::Result<Address>> {
) -> impl Future<Output = bitcoincore_rpc::Result<Address<NetworkUnchecked>>> {
let client = self.client.clone();

async move {
Expand Down

0 comments on commit ba65951

Please sign in to comment.