From ea02436f965bcc09bd6b32a21dfc98f490934dda Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Wed, 22 Oct 2014 19:32:29 +0200 Subject: [PATCH] Rename maybeDoMaintenance to doMaintenance and add a bit more docs. --- .../src/main/java/org/bitcoinj/core/Wallet.java | 17 ++++++++++------- .../test/java/org/bitcoinj/core/WalletTest.java | 12 ++++++------ .../java/org/bitcoinj/tools/WalletTool.java | 2 +- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/core/Wallet.java b/core/src/main/java/org/bitcoinj/core/Wallet.java index 5581cc69..ca7150e6 100644 --- a/core/src/main/java/org/bitcoinj/core/Wallet.java +++ b/core/src/main/java/org/bitcoinj/core/Wallet.java @@ -4276,7 +4276,7 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha *

When a key rotation time is set, any money controlled by keys created before the given timestamp T will be * automatically respent to any key that was created after T. This can be used to recover from a situation where * a set of keys is believed to be compromised. You can stop key rotation by calling this method again with zero - * as the argument. Once set up, calling {@link #maybeDoMaintenance(org.spongycastle.crypto.params.KeyParameter, boolean)} + * as the argument. Once set up, calling {@link #doMaintenance(org.spongycastle.crypto.params.KeyParameter, boolean)} * will create and possibly send rotation transactions: but it won't be done automatically (because you might have * to ask for the users password).

* @@ -4298,17 +4298,20 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha } /** - * A wallet app should call this from time to time if key rotation is enabled in order to let the wallet craft and - * send transactions needed to re-organise coins internally. A good time to call this would be after receiving coins - * for an unencrypted wallet, or after sending money for an encrypted wallet. If you have an encrypted wallet and - * just want to know if some maintenance needs doing, call this method with doSend set to false and look at the - * returned list of transactions. + * A wallet app should call this from time to time in order to let the wallet craft and send transactions needed + * to re-organise coins internally. A good time to call this would be after receiving coins for an unencrypted + * wallet, or after sending money for an encrypted wallet. If you have an encrypted wallet and just want to know + * if some maintenance needs doing, call this method with andSend set to false and look at the returned list of + * transactions. Maintenance might also include internal changes that involve some processing or work but + * which don't require making transactions - these will happen automatically unless the password is required + * in which case an exception will be thrown. * * @param aesKey the users password, if any. * @param andSend if true, send the transactions via the tx broadcaster and return them, if false just return them. * @return A list of transactions that the wallet just made/will make for internal maintenance. Might be empty. + * @throws org.bitcoinj.wallet.DeterministicUpgradeRequiresPassword if key rotation requires the users password. */ - public ListenableFuture> maybeDoMaintenance(@Nullable KeyParameter aesKey, boolean andSend) throws DeterministicUpgradeRequiresPassword { + public ListenableFuture> doMaintenance(@Nullable KeyParameter aesKey, boolean andSend) throws DeterministicUpgradeRequiresPassword { List txns; lock.lock(); try { diff --git a/core/src/test/java/org/bitcoinj/core/WalletTest.java b/core/src/test/java/org/bitcoinj/core/WalletTest.java index f2f76f1d..3f0ec47f 100644 --- a/core/src/test/java/org/bitcoinj/core/WalletTest.java +++ b/core/src/test/java/org/bitcoinj/core/WalletTest.java @@ -2306,7 +2306,7 @@ public class WalletTest extends TestWithWallet { Utils.rollMockClock(1); wallet.setKeyRotationTime(compromiseTime); assertTrue(wallet.isKeyRotating(key1)); - wallet.maybeDoMaintenance(null, true); + wallet.doMaintenance(null, true); Transaction tx = broadcaster.waitForTransactionAndSucceed(); final Coin THREE_CENTS = CENT.add(CENT).add(CENT); @@ -2323,12 +2323,12 @@ public class WalletTest extends TestWithWallet { // Now receive some more money to the newly derived address via a new block and check that nothing happens. sendMoneyToWallet(wallet, CENT, toAddress, AbstractBlockChain.NewBlockType.BEST_CHAIN); - assertTrue(wallet.maybeDoMaintenance(null, true).get().isEmpty()); + assertTrue(wallet.doMaintenance(null, true).get().isEmpty()); assertEquals(0, broadcaster.size()); // Receive money via a new block on key1 and ensure it shows up as a maintenance task. sendMoneyToWallet(wallet, CENT, key1.toAddress(params), AbstractBlockChain.NewBlockType.BEST_CHAIN); - wallet.maybeDoMaintenance(null, true); + wallet.doMaintenance(null, true); tx = broadcaster.waitForTransactionAndSucceed(); assertNotNull(wallet.findKeyFromPubHash(tx.getOutput(0).getScriptPubKey().getPubKeyHash())); log.info("Unexpected thing: {}", tx); @@ -2372,7 +2372,7 @@ public class WalletTest extends TestWithWallet { Utils.rollMockClock(86400); wallet.setKeyRotationTime(Utils.currentTimeSeconds()); - List txns = wallet.maybeDoMaintenance(null, false).get(); + List txns = wallet.doMaintenance(null, false).get(); assertEquals(1, txns.size()); DeterministicKey watchKey2 = wallet.getWatchingKey(); assertNotEquals(watchKey1, watchKey2); @@ -2406,7 +2406,7 @@ public class WalletTest extends TestWithWallet { // Now we set the rotation time to the time we started making good keys. This should create a new HD chain. wallet.setKeyRotationTime(goodKey.getCreationTimeSeconds()); - List txns = wallet.maybeDoMaintenance(null, false).get(); + List txns = wallet.doMaintenance(null, false).get(); assertEquals(1, txns.size()); Address output = txns.get(0).getOutput(0).getAddressFromP2PKHScript(params); ECKey usedKey = wallet.findKeyFromPubHash(output.getHash160()); @@ -2436,7 +2436,7 @@ public class WalletTest extends TestWithWallet { Utils.rollMockClock(86400); wallet.freshReceiveKey(); wallet.setKeyRotationTime(compromise); - wallet.maybeDoMaintenance(null, true); + wallet.doMaintenance(null, true); Transaction tx = broadcaster.waitForTransactionAndSucceed(); final Coin valueSentToMe = tx.getValueSentToMe(wallet); diff --git a/tools/src/main/java/org/bitcoinj/tools/WalletTool.java b/tools/src/main/java/org/bitcoinj/tools/WalletTool.java index 622a4bf0..b977a852 100644 --- a/tools/src/main/java/org/bitcoinj/tools/WalletTool.java +++ b/tools/src/main/java/org/bitcoinj/tools/WalletTool.java @@ -455,7 +455,7 @@ public class WalletTool { if (aesKey == null) return; } - Futures.getUnchecked(wallet.maybeDoMaintenance(aesKey, true)); + Futures.getUnchecked(wallet.doMaintenance(aesKey, true)); } private static void encrypt() {