From 91e7fe681642a884f61e71b3b6db102b36e63b26 Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Fri, 7 Nov 2014 13:21:46 +0100 Subject: [PATCH] WalletTool: magic --output value ALL for easier emptying of wallets. --- tools/src/main/java/org/bitcoinj/tools/WalletTool.java | 7 ++++++- .../main/resources/org/bitcoinj/tools/wallet-tool-help.txt | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/src/main/java/org/bitcoinj/tools/WalletTool.java b/tools/src/main/java/org/bitcoinj/tools/WalletTool.java index 6f3b56e82..0252dd160 100644 --- a/tools/src/main/java/org/bitcoinj/tools/WalletTool.java +++ b/tools/src/main/java/org/bitcoinj/tools/WalletTool.java @@ -18,6 +18,7 @@ package org.bitcoinj.tools; import org.bitcoinj.core.*; +import org.bitcoinj.core.Wallet.BalanceType; import org.bitcoinj.crypto.DeterministicKey; import org.bitcoinj.crypto.KeyCrypterException; import org.bitcoinj.crypto.MnemonicCode; @@ -517,7 +518,11 @@ public class WalletTool { } String destination = parts[0]; try { - Coin value = parseCoin(parts[1]); + Coin value; + if ("ALL".equalsIgnoreCase(parts[1])) + value = wallet.getBalance(BalanceType.ESTIMATED); + else + value = parseCoin(parts[1]); if (destination.startsWith("0")) { // Treat as a raw public key. byte[] pubKey = new BigInteger(destination, 16).toByteArray(); diff --git a/tools/src/main/resources/org/bitcoinj/tools/wallet-tool-help.txt b/tools/src/main/resources/org/bitcoinj/tools/wallet-tool-help.txt index 0ba1ede84..662fe1812 100644 --- a/tools/src/main/resources/org/bitcoinj/tools/wallet-tool-help.txt +++ b/tools/src/main/resources/org/bitcoinj/tools/wallet-tool-help.txt @@ -27,9 +27,11 @@ Usage: wallet-tool --flags action-name send Creates and broadcasts a transaction from the given wallet. Requires either --output or --payment-request to be specified. If --output is specified, a transaction is created from the provided output - from this wallet and broadcasted, eg: + from this wallet and broadcasted, e.g.: --output=1GthXFQMktFLWdh5EPNGqbq3H6WdG8zsWj:1.245 You can repeat --output=address:value multiple times. + There is a magic value ALL which empties the wallet to that address, e.g.: + --output=1GthXFQMktFLWdh5EPNGqbq3H6WdG8zsWj:ALL If the output destination starts with 04 and is 65 or 33 bytes long it will be treated as a public key instead of an address and the send will use CHECKSIG as the script.