Skip to content

Commit

Permalink
format (cargo fmt)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonilol committed Apr 19, 2023
1 parent 77cf140 commit 702a074
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 41 deletions.
13 changes: 10 additions & 3 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use jsonrpc;
use serde;
use serde_json;

use crate::bitcoin::address::{NetworkUnchecked, NetworkChecked};
use crate::bitcoin::address::{NetworkChecked, NetworkUnchecked};
use crate::bitcoin::hashes::hex::FromHex;
use crate::bitcoin::secp256k1::ecdsa::Signature;
use crate::bitcoin::{
Expand Down Expand Up @@ -893,7 +893,10 @@ pub trait RpcApi: Sized {
}

/// Generate new address for receiving change
fn get_raw_change_address(&self, address_type: Option<json::AddressType>) -> Result<Address<NetworkUnchecked>> {
fn get_raw_change_address(
&self,
address_type: Option<json::AddressType>,
) -> Result<Address<NetworkUnchecked>> {
self.call("getrawchangeaddress", &[opt_into_json(address_type)?])
}

Expand Down Expand Up @@ -1184,7 +1187,11 @@ pub trait RpcApi: Sized {
self.call("finalizepsbt", handle_defaults(&mut args, &[true.into()]))
}

fn derive_addresses(&self, descriptor: &str, range: Option<[u32; 2]>) -> Result<Vec<Address<NetworkUnchecked>>> {
fn derive_addresses(
&self,
descriptor: &str,
range: Option<[u32; 2]>,
) -> Result<Vec<Address<NetworkUnchecked>>> {
let mut args = [into_json(descriptor)?, opt_into_json(range)?];
self.call("deriveaddresses", handle_defaults(&mut args, &[null()]))
}
Expand Down
91 changes: 58 additions & 33 deletions integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ use crate::json::BlockStatsFields as BsFields;
use bitcoin::consensus::encode::{deserialize, serialize_hex};
use bitcoin::hashes::hex::FromHex;
use bitcoin::hashes::Hash;
use bitcoin::{secp256k1, ScriptBuf, sighash};
use bitcoin::{secp256k1, sighash, ScriptBuf};
use bitcoin::{
Address, Amount, Network, OutPoint, PrivateKey,
Sequence, SignedAmount, Transaction, TxIn, TxOut, Txid, Witness,
Address, Amount, Network, OutPoint, PrivateKey, Sequence, SignedAmount, Transaction, TxIn,
TxOut, Txid, Witness,
};
use bitcoincore_rpc::bitcoincore_rpc_json::{
GetBlockTemplateModes, GetBlockTemplateRules, ScanTxOutRequest, GetZmqNotificationsResult,
GetBlockTemplateModes, GetBlockTemplateRules, GetZmqNotificationsResult, ScanTxOutRequest,
};

lazy_static! {
Expand Down Expand Up @@ -246,7 +246,8 @@ fn test_get_new_address(cl: &Client) {
let addr = cl.get_new_address(None, Some(json::AddressType::Bech32)).unwrap().assume_checked();
assert_eq!(addr.address_type(), Some(bitcoin::AddressType::P2wpkh));

let addr = cl.get_new_address(None, Some(json::AddressType::P2shSegwit)).unwrap().assume_checked();
let addr =
cl.get_new_address(None, Some(json::AddressType::P2shSegwit)).unwrap().assume_checked();
assert_eq!(addr.address_type(), Some(bitcoin::AddressType::P2sh));
}

Expand All @@ -257,7 +258,8 @@ fn test_get_raw_change_address(cl: &Client) {
let addr = cl.get_raw_change_address(Some(json::AddressType::Bech32)).unwrap().assume_checked();
assert_eq!(addr.address_type(), Some(bitcoin::AddressType::P2wpkh));

let addr = cl.get_raw_change_address(Some(json::AddressType::P2shSegwit)).unwrap().assume_checked();
let addr =
cl.get_raw_change_address(Some(json::AddressType::P2shSegwit)).unwrap().assume_checked();
assert_eq!(addr.address_type(), Some(bitcoin::AddressType::P2sh));
}

Expand Down Expand Up @@ -287,7 +289,9 @@ fn test_generate(cl: &Client) {
fn test_get_balance_generate_to_address(cl: &Client) {
let initial = cl.get_balance(None, None).unwrap();

let blocks = cl.generate_to_address(500, &cl.get_new_address(None, None).unwrap().assume_checked()).unwrap();
let blocks = cl
.generate_to_address(500, &cl.get_new_address(None, None).unwrap().assume_checked())
.unwrap();
assert_eq!(blocks.len(), 500);
assert_ne!(cl.get_balance(None, None).unwrap(), initial);
}
Expand All @@ -296,7 +300,9 @@ fn test_get_balances_generate_to_address(cl: &Client) {
if version() >= 190000 {
let initial = cl.get_balances().unwrap();

let blocks = cl.generate_to_address(500, &cl.get_new_address(None, None).unwrap().assume_checked()).unwrap();
let blocks = cl
.generate_to_address(500, &cl.get_new_address(None, None).unwrap().assume_checked())
.unwrap();
assert_eq!(blocks.len(), 500);
assert_ne!(cl.get_balances().unwrap(), initial);
}
Expand Down Expand Up @@ -372,7 +378,8 @@ fn test_get_address_info(cl: &Client) {
let info = cl.get_address_info(&addr).unwrap();
assert!(!info.witness_program.unwrap().is_empty());

let addr = cl.get_new_address(None, Some(json::AddressType::P2shSegwit)).unwrap().assume_checked();
let addr =
cl.get_new_address(None, Some(json::AddressType::P2shSegwit)).unwrap().assume_checked();
let info = cl.get_address_info(&addr).unwrap();
assert!(!info.hex.unwrap().is_empty());
}
Expand Down Expand Up @@ -428,27 +435,33 @@ fn test_get_received_by_address(cl: &Client) {
let _ = cl.send_to_address(&addr, btc(1), None, None, None, None, None, None).unwrap();
assert_eq!(cl.get_received_by_address(&addr, Some(0)).unwrap(), btc(1));
assert_eq!(cl.get_received_by_address(&addr, Some(1)).unwrap(), btc(0));
let _ = cl.generate_to_address(7, &cl.get_new_address(None, None).unwrap().assume_checked()).unwrap();
let _ = cl
.generate_to_address(7, &cl.get_new_address(None, None).unwrap().assume_checked())
.unwrap();
assert_eq!(cl.get_received_by_address(&addr, Some(6)).unwrap(), btc(1));
assert_eq!(cl.get_received_by_address(&addr, None).unwrap(), btc(1));
}

fn test_list_unspent(cl: &Client) {
let addr = cl.get_new_address(None, None).unwrap();
let addr_checked = addr.clone().assume_checked();
let txid = cl.send_to_address(&addr.clone().assume_checked(), btc(1), None, None, None, None, None, None).unwrap();
let unspent = cl.list_unspent(Some(0), None, Some(&[ &addr_checked]), None, None).unwrap();
let txid = cl
.send_to_address(&addr.clone().assume_checked(), btc(1), None, None, None, None, None, None)
.unwrap();
let unspent = cl.list_unspent(Some(0), None, Some(&[&addr_checked]), None, None).unwrap();
assert_eq!(unspent[0].txid, txid);
assert_eq!(unspent[0].address.as_ref(), Some(&addr));
assert_eq!(unspent[0].amount, btc(1));

let txid = cl.send_to_address(&addr_checked, btc(7), None, None, None, None, None, None).unwrap();
let txid =
cl.send_to_address(&addr_checked, btc(7), None, None, None, None, None, None).unwrap();
let options = json::ListUnspentQueryOptions {
minimum_amount: Some(btc(7)),
maximum_amount: Some(btc(7)),
..Default::default()
};
let unspent = cl.list_unspent(Some(0), None, Some(&[&addr_checked]), None, Some(options)).unwrap();
let unspent =
cl.list_unspent(Some(0), None, Some(&[&addr_checked]), None, Some(options)).unwrap();
assert_eq!(unspent.len(), 1);
assert_eq!(unspent[0].txid, txid);
assert_eq!(unspent[0].address.as_ref(), Some(&addr));
Expand All @@ -474,7 +487,9 @@ fn test_get_raw_transaction(cl: &Client) {
let info = cl.get_raw_transaction_info(&txid, None).unwrap();
assert_eq!(info.txid, txid);

let blocks = cl.generate_to_address(7, &cl.get_new_address(None, None).unwrap().assume_checked()).unwrap();
let blocks = cl
.generate_to_address(7, &cl.get_new_address(None, None).unwrap().assume_checked())
.unwrap();
let _ = cl.get_raw_transaction_info(&txid, Some(&blocks[0])).unwrap();
}

Expand Down Expand Up @@ -530,7 +545,9 @@ fn test_get_tx_out_proof(cl: &Client) {
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None).unwrap();
let txid2 =
cl.send_to_address(&RANDOM_ADDRESS, btc(1), None, None, None, None, None, None).unwrap();
let blocks = cl.generate_to_address(7, &cl.get_new_address(None, None).unwrap().assume_checked()).unwrap();
let blocks = cl
.generate_to_address(7, &cl.get_new_address(None, None).unwrap().assume_checked())
.unwrap();
let proof = cl.get_tx_out_proof(&[txid1, txid2], Some(&blocks[0])).unwrap();
assert!(!proof.is_empty());
}
Expand All @@ -557,7 +574,9 @@ fn test_lock_unspent_unlock_unspent(cl: &Client) {
}

fn test_get_block_filter(cl: &Client) {
let blocks = cl.generate_to_address(7, &cl.get_new_address(None, None).unwrap().assume_checked()).unwrap();
let blocks = cl
.generate_to_address(7, &cl.get_new_address(None, None).unwrap().assume_checked())
.unwrap();
if version() >= 190000 {
let _ = cl.get_block_filter(&blocks[0]).unwrap();
} else {
Expand Down Expand Up @@ -628,7 +647,12 @@ fn test_sign_raw_transaction_with_send_raw_transaction(cl: &Client) {
};

let res = cl
.sign_raw_transaction_with_key(&tx, &[sk], None, Some(sighash::EcdsaSighashType::All.into()))
.sign_raw_transaction_with_key(
&tx,
&[sk],
None,
Some(sighash::EcdsaSighashType::All.into()),
)
.unwrap();
assert!(res.complete);
let _ = cl.send_raw_transaction(&res.transaction().unwrap()).unwrap();
Expand Down Expand Up @@ -1273,9 +1297,7 @@ fn test_getblocktemplate(cl: &Client) {
fn test_unloadwallet(cl: &Client) {
cl.create_wallet("testunloadwallet", None, None, None, None).unwrap();

let res = new_wallet_client("testunloadwallet")
.unload_wallet(None)
.unwrap();
let res = new_wallet_client("testunloadwallet").unload_wallet(None).unwrap();

if version() >= 210000 {
assert!(res.is_some());
Expand Down Expand Up @@ -1308,18 +1330,21 @@ fn test_get_zmq_notifications(cl: &Client) {
}
});

assert!(zmq_info == vec![
GetZmqNotificationsResult {
notification_type: "pubrawblock".to_owned(),
address: "tcp://0.0.0.0:28332".to_owned(),
hwm: 1000
},
GetZmqNotificationsResult {
notification_type: "pubrawtx".to_owned(),
address: "tcp://0.0.0.0:28333".to_owned(),
hwm: 1000
},
]);
assert!(
zmq_info
== vec![
GetZmqNotificationsResult {
notification_type: "pubrawblock".to_owned(),
address: "tcp://0.0.0.0:28332".to_owned(),
hwm: 1000
},
GetZmqNotificationsResult {
notification_type: "pubrawtx".to_owned(),
address: "tcp://0.0.0.0:28333".to_owned(),
hwm: 1000
},
]
);
}

fn test_stop(cl: Client) {
Expand Down
10 changes: 5 additions & 5 deletions json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ use bitcoin::block::Version;
use bitcoin::consensus::encode;
use bitcoin::hashes::hex::FromHex;
use bitcoin::hashes::sha256;
use bitcoin::{Address, Amount, PrivateKey, PublicKey, SignedAmount, Transaction, ScriptBuf, Script, bip158, bip32};
use bitcoin::{
bip158, bip32, Address, Amount, PrivateKey, PublicKey, Script, ScriptBuf, SignedAmount,
Transaction,
};
use serde::de::Error as SerdeError;
use serde::{Deserialize, Serialize};
use std::fmt;
Expand Down Expand Up @@ -1876,10 +1879,7 @@ pub struct FundRawTransactionOptions {
pub include_watching: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub lock_unspents: Option<bool>,
#[serde(
with = "bitcoin::amount::serde::as_btc::opt",
skip_serializing_if = "Option::is_none"
)]
#[serde(with = "bitcoin::amount::serde::as_btc::opt", skip_serializing_if = "Option::is_none")]
pub fee_rate: Option<Amount>,
#[serde(skip_serializing_if = "Option::is_none")]
pub subtract_fee_from_outputs: Option<Vec<u32>>,
Expand Down

0 comments on commit 702a074

Please sign in to comment.