diff --git a/core/src/main/java/com/google/bitcoin/core/Wallet.java b/core/src/main/java/com/google/bitcoin/core/Wallet.java index 2e35d6be..ff96f6fd 100644 --- a/core/src/main/java/com/google/bitcoin/core/Wallet.java +++ b/core/src/main/java/com/google/bitcoin/core/Wallet.java @@ -1360,21 +1360,16 @@ public class Wallet implements Serializable, BlockChainListener { } /** - *

Updates the wallet with the given transaction: puts it into the pending pool, sets the spent flags and runs - * the onCoinsSent/onCoinsReceived event listener. Used in two situations:

+ * Calls {@link Wallet#commitTx} if tx is not already in the pending pool * - *
    - *
  1. When we have just successfully transmitted the tx we created to the network.
  2. - *
  3. When we receive a pending transaction that didn't appear in the chain yet, and we did not create it.
  4. - *
- * - *

Triggers an auto save.

+ * @return true if the tx was added to the wallet, or false if it was already in the pending pool */ - public void commitTx(Transaction tx) throws VerificationException { + public boolean maybeCommitTx(Transaction tx) throws VerificationException { tx.verify(); lock.lock(); try { - checkArgument(!pending.containsKey(tx.getHash()), "commitTx called on the same transaction twice"); + if (pending.containsKey(tx.getHash())) + return false; log.info("commitTx of {}", tx.getHashAsString()); BigInteger balance = getBalance(); tx.setUpdateTime(Utils.now()); @@ -1408,6 +1403,22 @@ public class Wallet implements Serializable, BlockChainListener { } finally { lock.unlock(); } + return true; + } + + /** + *

Updates the wallet with the given transaction: puts it into the pending pool, sets the spent flags and runs + * the onCoinsSent/onCoinsReceived event listener. Used in two situations:

+ * + *
    + *
  1. When we have just successfully transmitted the tx we created to the network.
  2. + *
  3. When we receive a pending transaction that didn't appear in the chain yet, and we did not create it.
  4. + *
+ * + *

Triggers an auto save.

+ */ + public void commitTx(Transaction tx) throws VerificationException { + checkArgument(maybeCommitTx(tx), "commitTx called on the same transaction twice"); } /**