From 7adf4e8a6465e40ad0e31e32e1152fe0871bc5cd Mon Sep 17 00:00:00 2001 From: raphjaph Date: Mon, 30 Sep 2024 17:06:10 +0200 Subject: [PATCH 1/4] Fix non-existant output lookup --- src/index.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.rs b/src/index.rs index 94bafd85cb..800b699811 100644 --- a/src/index.rs +++ b/src/index.rs @@ -1577,7 +1577,7 @@ impl Index { } } - self.client.get_raw_transaction(&txid, None).into_option() + Ok(self.client.get_raw_transaction(&txid, None).ok()) } pub fn find(&self, sat: Sat) -> Result> { From f77fc454d8f0a7315ad9dd2e8f233c35b815544b Mon Sep 17 00:00:00 2001 From: raphjaph Date: Mon, 30 Sep 2024 17:11:59 +0200 Subject: [PATCH 2/4] Amend --- src/subcommand/server.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 664e0f0830..52dc058986 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -7152,4 +7152,14 @@ next } ); } + + #[test] + fn unknown_output_returns_404() { + let server = TestServer::builder().chain(Chain::Regtest).build(); + server.assert_response( + "/output/0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef:123", + StatusCode::NOT_FOUND, + "output 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef:123 not found", + ); + } } From 524af4d4071784f34d3cb0358c5785a3af280706 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Wed, 2 Oct 2024 22:39:13 +0200 Subject: [PATCH 3/4] Amend --- src/index.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/index.rs b/src/index.rs index 800b699811..4cf4c0961d 100644 --- a/src/index.rs +++ b/src/index.rs @@ -170,9 +170,11 @@ impl BitcoinCoreRpcResultExt for Result { bitcoincore_rpc::jsonrpc::error::RpcError { code: -8, .. }, ))) => Ok(None), Err(bitcoincore_rpc::Error::JsonRpc(bitcoincore_rpc::jsonrpc::error::Error::Rpc( - bitcoincore_rpc::jsonrpc::error::RpcError { message, .. }, + bitcoincore_rpc::jsonrpc::error::RpcError { + code: -5, message, .. + }, ))) - if message.ends_with("not found") => + if message.starts_with("No such mempool or blockchain transaction") => { Ok(None) } @@ -1577,7 +1579,7 @@ impl Index { } } - Ok(self.client.get_raw_transaction(&txid, None).ok()) + self.client.get_raw_transaction(&txid, None).into_option() } pub fn find(&self, sat: Sat) -> Result> { From 94e23204f3b516de36d4560f927bb95cfbaf57a7 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Wed, 2 Oct 2024 22:41:40 +0200 Subject: [PATCH 4/4] Amend --- src/index.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/index.rs b/src/index.rs index 4cf4c0961d..a213c1e636 100644 --- a/src/index.rs +++ b/src/index.rs @@ -178,6 +178,13 @@ impl BitcoinCoreRpcResultExt for Result { { Ok(None) } + Err(bitcoincore_rpc::Error::JsonRpc(bitcoincore_rpc::jsonrpc::error::Error::Rpc( + bitcoincore_rpc::jsonrpc::error::RpcError { message, .. }, + ))) + if message.ends_with("not found") => + { + Ok(None) + } Err(err) => Err(err.into()), } }