From 5a3aa5d6e102bbd40a458ed86c54058192479b3b Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Wed, 23 Oct 2013 14:22:44 +0200 Subject: [PATCH] Remove redundant query in H2FullPrunedBlockStore. Patch from Eric W Dickerson. Resolves issue 441. --- AUTHORS | 1 + .../com/google/bitcoin/store/H2FullPrunedBlockStore.java | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/AUTHORS b/AUTHORS index 78f12428..fe587498 100644 --- a/AUTHORS +++ b/AUTHORS @@ -18,3 +18,4 @@ Mark van Cuijk Matt Corallo Alexander Lolis Matija Mazi +Eric William Dickerson diff --git a/core/src/main/java/com/google/bitcoin/store/H2FullPrunedBlockStore.java b/core/src/main/java/com/google/bitcoin/store/H2FullPrunedBlockStore.java index 21fa6f89..06581c30 100644 --- a/core/src/main/java/com/google/bitcoin/store/H2FullPrunedBlockStore.java +++ b/core/src/main/java/com/google/bitcoin/store/H2FullPrunedBlockStore.java @@ -686,9 +686,6 @@ public class H2FullPrunedBlockStore implements FullPrunedBlockStore { public void removeUnspentTransactionOutput(StoredTransactionOutput out) throws BlockStoreException { maybeConnect(); - // TODO: This should only need one query (maybe a stored procedure) - if (getTransactionOutput(out.getHash(), out.getIndex()) == null) - throw new BlockStoreException("Tried to remove a StoredTransactionOutput from H2FullPrunedBlockStore that it didn't have!"); try { PreparedStatement s = conn.get() .prepareStatement("DELETE FROM openOutputs WHERE hash = ? AND index = ?"); @@ -696,7 +693,10 @@ public class H2FullPrunedBlockStore implements FullPrunedBlockStore { // index is actually an unsigned int s.setInt(2, (int)out.getIndex()); s.executeUpdate(); + int updateCount = s.getUpdateCount(); s.close(); + if (updateCount == 0) + throw new BlockStoreException("Tried to remove a StoredTransactionOutput from H2FullPrunedBlockStore that it didn't have!"); } catch (SQLException e) { throw new BlockStoreException(e); }