From cbc2f81507657f4a87b085687d083d3502fc9f50 Mon Sep 17 00:00:00 2001 From: Marek Date: Mon, 15 Jan 2024 19:27:21 +0100 Subject: [PATCH] Fix fetching the RPC tx fetching (#8157) We recently updated the `jsonrpc` dependency from 0.16 to 0.17. The former version used to implicitly send an array of params, even if a single param was passed to the request builder. The new version doesn't do that anymore, but Zebra expects an array, so this commit explicitly passes an array consisting of a single param to the request builder. --- .../src/bin/scanning-results-reader/main.rs | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/zebra-utils/src/bin/scanning-results-reader/main.rs b/zebra-utils/src/bin/scanning-results-reader/main.rs index 5e84978d5..b12892b7b 100644 --- a/zebra-utils/src/bin/scanning-results-reader/main.rs +++ b/zebra-utils/src/bin/scanning-results-reader/main.rs @@ -11,7 +11,6 @@ use hex::ToHex; use itertools::Itertools; use jsonrpc::simple_http::SimpleHttpTransport; use jsonrpc::Client; -use serde_json::value::RawValue; use zcash_client_backend::decrypt_transaction; use zcash_client_backend::keys::UnifiedFullViewingKey; @@ -65,7 +64,7 @@ pub fn main() { for txid in txids.iter() { let tx = Transaction::read( - &hex::decode(&get_tx_via_rpc(txid.encode_hex())) + &hex::decode(&fetch_tx_via_rpc(txid.encode_hex())) .expect("RPC response should be decodable from hex string to bytes")[..], BranchId::for_height(&network, height), ) @@ -98,21 +97,17 @@ fn memo_bytes_to_string(memo: &[u8; 512]) -> String { } /// Uses the `getrawtransaction` RPC to retrieve a transaction by its TXID. -fn get_tx_via_rpc(txid: String) -> String { - // Wrap the TXID with `"` so that [`RawValue::from_string`] eats it. - let txid = format!("\"{}\"", txid); - let transport = SimpleHttpTransport::builder() - .url("127.0.0.1:8232") - .expect("URL should be valid") - .build(); - let client = Client::with_transport(transport); - let params = RawValue::from_string(txid).expect("Provided TXID should be a valid JSON"); - let request = client.build_request("getrawtransaction", Some(¶ms)); - let response = client - .send_request(request) - .expect("Sending the `getrawtransaction` request should succeed"); +fn fetch_tx_via_rpc(txid: String) -> String { + let client = Client::with_transport( + SimpleHttpTransport::builder() + .url("127.0.0.1:8232") + .expect("Zebra's URL should be valid") + .build(), + ); - response + client + .send_request(client.build_request("getrawtransaction", Some(&jsonrpc::arg([txid])))) + .expect("Sending the `getrawtransaction` request should succeed") .result() .expect("Zebra's RPC response should contain a valid result") }