Skip to content

Commit ba256d7

Browse files
committed
Compatibility with Bitcoin Core v0.21
1 parent ce0c34b commit ba256d7

File tree

4 files changed

+100
-9
lines changed

4 files changed

+100
-9
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
env: BITCOINVERSION=0.20.0
2020
- rust: stable
2121
env: BITCOINVERSION=0.20.1
22+
- rust: stable
23+
env: BITCOINVERSION=0.21.0
2224

2325
script:
2426
- ./contrib/test.sh

integration_test/run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ PID1=$!
1919
sleep 3
2020

2121
BLOCKFILTERARG=""
22-
if bitcoind -version | grep -q "0\.19\|0\.20"; then
22+
if bitcoind -version | grep -q "v0\.\(19\|2\)"; then
2323
BLOCKFILTERARG="-blockfilterindex=1"
2424
fi
2525

2626
FALLBACKFEEARG=""
27-
if bitcoind -version | grep -q "0\.20"; then
27+
if bitcoind -version | grep -q "v0\.2"; then
2828
FALLBACKFEEARG="-fallbackfee=0.00001000"
2929
fi
3030

integration_test/src/main.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ macro_rules! assert_not_found {
7979
};
8080
}
8181

82+
/// Assert that the call returns the specified error message.
83+
macro_rules! assert_error_message {
84+
($call:expr, $code:expr, $msg:expr) => {
85+
match $call.unwrap_err() {
86+
Error::JsonRpc(JsonRpcError::Rpc(ref e))
87+
if e.code == $code && e.message.contains($msg) => {}
88+
e => panic!("expected '{}' error for {}, got: {}", $msg, stringify!($call), e),
89+
}
90+
};
91+
}
92+
8293
static mut VERSION: usize = 0;
8394
/// Get the version of the node that is running.
8495
fn version() -> usize {
@@ -111,7 +122,7 @@ fn get_auth() -> bitcoincore_rpc::Auth {
111122
fn main() {
112123
log::set_logger(&LOGGER).map(|()| log::set_max_level(log::LevelFilter::max())).unwrap();
113124

114-
let rpc_url = get_rpc_url();
125+
let rpc_url = format!("{}/wallet/testwallet", get_rpc_url());
115126
let auth = get_auth();
116127

117128
let cl = Client::new(rpc_url, auth).unwrap();
@@ -120,6 +131,8 @@ fn main() {
120131
unsafe { VERSION = cl.version().unwrap() };
121132
println!("Version: {}", version());
122133

134+
cl.create_wallet("testwallet", None, None, None, None).unwrap();
135+
123136
test_get_mining_info(&cl);
124137
test_get_blockchain_info(&cl);
125138
test_get_new_address(&cl);
@@ -226,8 +239,12 @@ fn test_generate(cl: &Client) {
226239
assert_eq!(blocks.len(), 6);
227240
} else if version() < 190000 {
228241
assert_deprecated!(cl.generate(5, None));
229-
} else {
242+
} else if version() < 210000 {
230243
assert_not_found!(cl.generate(5, None));
244+
} else {
245+
// Bitcoin Core v0.21 appears to return this with a generic -1 error code,
246+
// rather than the expected -32601 code (RPC_METHOD_NOT_FOUND).
247+
assert_error_message!(cl.generate(5, None), -1, "replaced by the -generate cli option");
231248
}
232249
}
233250

@@ -586,6 +603,7 @@ fn test_fund_raw_transaction(cl: &Client) {
586603
output.insert(RANDOM_ADDRESS.to_string(), btc(1));
587604

588605
let options = json::FundRawTransactionOptions {
606+
add_inputs: None,
589607
change_address: Some(addr),
590608
change_position: Some(0),
591609
change_type: None,
@@ -602,6 +620,7 @@ fn test_fund_raw_transaction(cl: &Client) {
602620
let _ = funded.transaction().unwrap();
603621

604622
let options = json::FundRawTransactionOptions {
623+
add_inputs: None,
605624
change_address: None,
606625
change_position: Some(0),
607626
change_type: Some(json::AddressType::Legacy),
@@ -663,6 +682,7 @@ fn test_wallet_create_funded_psbt(cl: &Client) {
663682
output.insert(RANDOM_ADDRESS.to_string(), btc(1));
664683

665684
let options = json::WalletCreateFundedPsbtOptions {
685+
add_inputs: None,
666686
change_address: None,
667687
change_position: Some(1),
668688
change_type: Some(json::AddressType::Legacy),
@@ -685,6 +705,7 @@ fn test_wallet_create_funded_psbt(cl: &Client) {
685705
.unwrap();
686706

687707
let options = json::WalletCreateFundedPsbtOptions {
708+
add_inputs: None,
688709
change_address: Some(addr),
689710
change_position: Some(1),
690711
change_type: None,
@@ -939,8 +960,9 @@ fn test_create_wallet(cl: &Client) {
939960

940961
wallet_list.sort();
941962

942-
// Default wallet
943-
assert_eq!(wallet_list.remove(0), "");
963+
// Main wallet created for tests
964+
assert!(wallet_list.iter().any(|w| w == "testwallet"));
965+
wallet_list.retain(|w| w != "testwallet" && w != "");
944966

945967
// Created wallets
946968
assert!(wallet_list.iter().zip(wallet_names).all(|(a, b)| a == b));

json/src/lib.rs

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ pub struct GetNetworkInfoResult {
9999
#[serde(rename = "timeoffset")]
100100
pub time_offset: isize,
101101
pub connections: usize,
102+
/// The number of inbound connections
103+
/// Added in Bitcoin Core v0.21
104+
pub connections_in: Option<usize>,
105+
/// The number of outbound connections
106+
/// Added in Bitcoin Core v0.21
107+
pub connections_out: Option<usize>,
102108
#[serde(rename = "networkactive")]
103109
pub network_active: bool,
104110
pub networks: Vec<GetNetworkInfoResultNetwork>,
@@ -544,6 +550,20 @@ pub struct TestMempoolAcceptResult {
544550
pub allowed: bool,
545551
#[serde(rename = "reject-reason")]
546552
pub reject_reason: Option<String>,
553+
/// Virtual transaction size as defined in BIP 141 (only present when 'allowed' is true)
554+
/// Added in Bitcoin Core v0.21
555+
pub vsize: Option<u64>,
556+
/// Transaction fees (only present if 'allowed' is true)
557+
/// Added in Bitcoin Core v0.21
558+
pub fees: Option<TestMempoolAcceptResultFees>,
559+
}
560+
561+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
562+
pub struct TestMempoolAcceptResultFees {
563+
/// Transaction fee in BTC
564+
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
565+
pub base: Amount,
566+
// unlike GetMempoolEntryResultFees, this only has the `base` fee
547567
}
548568

549569
#[derive(Copy, Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
@@ -781,6 +801,9 @@ pub struct GetMempoolEntryResult {
781801
/// Whether this transaction could be replaced due to BIP125 (replace-by-fee)
782802
#[serde(rename = "bip125-replaceable")]
783803
pub bip125_replaceable: bool,
804+
/// Whether this transaction is currently unbroadcast (initial broadcast not yet acknowledged by any peers)
805+
/// Added in Bitcoin Core v0.21
806+
pub unbroadcast: Option<bool>,
784807
}
785808

786809
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
@@ -920,6 +943,9 @@ pub struct GetPeerInfoResult {
920943
/// Local address as reported by the peer
921944
// TODO: use a type for addrlocal
922945
pub addrlocal: Option<String>,
946+
/// Network (ipv4, ipv6, or onion) the peer connected throug
947+
/// Added in Bitcoin Core v0.21
948+
pub network: Option<GetPeerInfoResultNetwork>,
923949
/// The services offered
924950
// TODO: use a type for services
925951
pub services: String,
@@ -929,6 +955,12 @@ pub struct GetPeerInfoResult {
929955
pub lastsend: u64,
930956
/// The time in seconds since epoch (Jan 1 1970 GMT) of the last receive
931957
pub lastrecv: u64,
958+
/// The time in seconds since epoch (Jan 1 1970 GMT) of the last valid transaction received from this peer
959+
/// Added in Bitcoin Core v0.21
960+
pub last_transaction: Option<u64>,
961+
/// The time in seconds since epoch (Jan 1 1970 GMT) of the last block received from this peer
962+
/// Added in Bitcoin Core v0.21
963+
pub last_block: Option<u64>,
932964
/// The total bytes sent
933965
pub bytessent: u64,
934966
/// The total bytes received
@@ -951,25 +983,52 @@ pub struct GetPeerInfoResult {
951983
pub inbound: bool,
952984
/// Whether connection was due to `addnode`/`-connect` or if it was an
953985
/// automatic/inbound connection
954-
pub addnode: bool,
986+
/// Deprecated in Bitcoin Core v0.21
987+
pub addnode: Option<bool>,
955988
/// The starting height (block) of the peer
956989
pub startingheight: i64,
957990
/// The ban score
958-
pub banscore: i64,
991+
/// Deprecated in Bitcoin Core v0.21
992+
pub banscore: Option<i64>,
959993
/// The last header we have in common with this peer
960994
pub synced_headers: i64,
961995
/// The last block we have in common with this peer
962996
pub synced_blocks: i64,
963997
/// The heights of blocks we're currently asking from this peer
964998
pub inflight: Vec<u64>,
965999
/// Whether the peer is whitelisted
966-
pub whitelisted: bool,
1000+
/// Deprecated in Bitcoin Core v0.21
1001+
pub whitelisted: Option<bool>,
9671002
#[serde(rename = "minfeefilter", default, with = "bitcoin::util::amount::serde::as_btc::opt")]
9681003
pub min_fee_filter: Option<Amount>,
9691004
/// The total bytes sent aggregated by message type
9701005
pub bytessent_per_msg: HashMap<String, u64>,
9711006
/// The total bytes received aggregated by message type
9721007
pub bytesrecv_per_msg: HashMap<String, u64>,
1008+
/// The type of the connection
1009+
/// Added in Bitcoin Core v0.21
1010+
pub connection_type: Option<GetPeerInfoResultConnectionType>,
1011+
}
1012+
1013+
#[derive(Copy, Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
1014+
#[serde(rename_all = "lowercase")]
1015+
pub enum GetPeerInfoResultNetwork {
1016+
Ipv4,
1017+
Ipv6,
1018+
Onion,
1019+
// this is undocumented upstream
1020+
Unroutable,
1021+
}
1022+
1023+
#[derive(Copy, Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
1024+
#[serde(rename_all = "kebab-case")]
1025+
pub enum GetPeerInfoResultConnectionType {
1026+
OutboundFullRelay,
1027+
BlockRelayOnly,
1028+
Inbound,
1029+
Manual,
1030+
AddrFetch,
1031+
Feeler,
9731032
}
9741033

9751034
/// Models the result of "estimatesmartfee"
@@ -1022,6 +1081,10 @@ pub struct WalletCreateFundedPsbtResult {
10221081
/// Models the request for "walletcreatefundedpsbt"
10231082
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize, Default)]
10241083
pub struct WalletCreateFundedPsbtOptions {
1084+
/// For a transaction with existing inputs, automatically include more if they are not enough (default true).
1085+
/// Added in Bitcoin Core v0.21
1086+
#[serde(skip_serializing_if = "Option::is_none")]
1087+
pub add_inputs: Option<bool>,
10251088
#[serde(rename = "changeAddress", skip_serializing_if = "Option::is_none")]
10261089
pub change_address: Option<Address>,
10271090
#[serde(rename = "changePosition", skip_serializing_if = "Option::is_none")]
@@ -1112,6 +1175,10 @@ pub struct CreateRawTransactionInput {
11121175
#[derive(Serialize, Clone, PartialEq, Eq, Debug, Default)]
11131176
#[serde(rename_all = "camelCase")]
11141177
pub struct FundRawTransactionOptions {
1178+
/// For a transaction with existing inputs, automatically include more if they are not enough (default true).
1179+
/// Added in Bitcoin Core v0.21
1180+
#[serde(rename = "add_inputs", skip_serializing_if = "Option::is_none")]
1181+
pub add_inputs: Option<bool>,
11151182
#[serde(skip_serializing_if = "Option::is_none")]
11161183
pub change_address: Option<Address>,
11171184
#[serde(skip_serializing_if = "Option::is_none")]

0 commit comments

Comments
 (0)