From 9dd8e5ab92f73a078ab97668b75770554ea8b1e4 Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Thu, 25 Jan 2018 12:02:50 +0100 Subject: [PATCH] WalletTool: New option --fee-sat-per-byte to set network fee in satoshi per byte. --- .../java/org/bitcoinj/tools/WalletTool.java | 24 +++++++++++++++++++ .../org/bitcoinj/tools/wallet-tool-help.txt | 8 +++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/tools/src/main/java/org/bitcoinj/tools/WalletTool.java b/tools/src/main/java/org/bitcoinj/tools/WalletTool.java index 3228cf2c8..f139443eb 100644 --- a/tools/src/main/java/org/bitcoinj/tools/WalletTool.java +++ b/tools/src/main/java/org/bitcoinj/tools/WalletTool.java @@ -224,6 +224,7 @@ public class WalletTool { OptionSpec outputFlag = parser.accepts("output").withRequiredArg(); parser.accepts("value").withRequiredArg(); OptionSpec feePerKbOption = parser.accepts("fee-per-kb").withRequiredArg(); + OptionSpec feeSatPerByteOption = parser.accepts("fee-sat-per-byte").withRequiredArg(); unixtimeFlag = parser.accepts("unixtime").withRequiredArg().ofType(Long.class); OptionSpec conditionFlag = parser.accepts("condition").withRequiredArg(); parser.accepts("locktime").withRequiredArg(); @@ -359,10 +360,15 @@ public class WalletTool { if (options.has(paymentRequestLocation) && options.has(outputFlag)) { System.err.println("--payment-request and --output cannot be used together."); return; + } else if (options.has(feePerKbOption) && options.has(feeSatPerByteOption)) { + System.err.println("--fee-per-kb and --fee-sat-per-byte cannot be used together."); + return; } else if (options.has(outputFlag)) { Coin feePerKb = null; if (options.has(feePerKbOption)) feePerKb = parseCoin((String) options.valueOf(feePerKbOption)); + if (options.has(feeSatPerByteOption)) + feePerKb = Coin.valueOf(Long.parseLong(options.valueOf(feeSatPerByteOption)) * 1000); String lockTime = null; if (options.has("locktime")) { lockTime = (String) options.valueOf("locktime"); @@ -377,6 +383,10 @@ public class WalletTool { } break; case SEND_CLTVPAYMENTCHANNEL: { + if (options.has(feePerKbOption) && options.has(feeSatPerByteOption)) { + System.err.println("--fee-per-kb and --fee-sat-per-byte cannot be used together."); + return; + } if (!options.has(outputFlag)) { System.err.println("You must specify a --output=addr:value"); return; @@ -384,6 +394,8 @@ public class WalletTool { Coin feePerKb = null; if (options.has(feePerKbOption)) feePerKb = parseCoin((String) options.valueOf(feePerKbOption)); + if (options.has(feeSatPerByteOption)) + feePerKb = Coin.valueOf(Long.parseLong(options.valueOf(feeSatPerByteOption)) * 1000); if (!options.has("locktime")) { System.err.println("You must specify a --locktime"); return; @@ -397,6 +409,10 @@ public class WalletTool { sendCLTVPaymentChannel(refundFlag.value(options), outputFlag.value(options), feePerKb, lockTime, allowUnconfirmed); } break; case SETTLE_CLTVPAYMENTCHANNEL: { + if (options.has(feePerKbOption) && options.has(feeSatPerByteOption)) { + System.err.println("--fee-per-kb and --fee-sat-per-byte cannot be used together."); + return; + } if (!options.has(outputFlag)) { System.err.println("You must specify a --output=addr:value"); return; @@ -404,6 +420,8 @@ public class WalletTool { Coin feePerKb = null; if (options.has(feePerKbOption)) feePerKb = parseCoin((String) options.valueOf(feePerKbOption)); + if (options.has(feeSatPerByteOption)) + feePerKb = Coin.valueOf(Long.parseLong(options.valueOf(feeSatPerByteOption)) * 1000); boolean allowUnconfirmed = options.has("allow-unconfirmed"); if (!options.has(txHashFlag)) { System.err.println("You must specify the transaction to spend: --txhash=tx-hash"); @@ -412,6 +430,10 @@ public class WalletTool { settleCLTVPaymentChannel(txHashFlag.value(options), outputFlag.value(options), feePerKb, allowUnconfirmed); } break; case REFUND_CLTVPAYMENTCHANNEL: { + if (options.has(feePerKbOption) && options.has(feeSatPerByteOption)) { + System.err.println("--fee-per-kb and --fee-sat-per-byte cannot be used together."); + return; + } if (!options.has(outputFlag)) { System.err.println("You must specify a --output=addr:value"); return; @@ -419,6 +441,8 @@ public class WalletTool { Coin feePerKb = null; if (options.has(feePerKbOption)) feePerKb = parseCoin((String) options.valueOf(feePerKbOption)); + if (options.has(feeSatPerByteOption)) + feePerKb = Coin.valueOf(Long.parseLong(options.valueOf(feeSatPerByteOption)) * 1000); boolean allowUnconfirmed = options.has("allow-unconfirmed"); if (!options.has(txHashFlag)) { System.err.println("You must specify the transaction to spend: --txhash=tx-hash"); 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 6cb72693f..ba1d2005d 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 @@ -49,7 +49,7 @@ Usage: wallet-tool --flags action-name --payment-request=http://merchant.com/pay.php?123 Other options include: - --fee-per-kb=0.0005 sets the tx fee + --fee-per-kb=0.0005 or --fee-sat-per-byte=50 sets the network fee --locktime=1234 sets the lock time to block 1234 --locktime=2013/01/01 sets the lock time to 1st Jan 2013 --allow-unconfirmed will let you create spends of pending non-change outputs. @@ -73,14 +73,14 @@ Usage: wallet-tool --flags action-name Options: --output=pubkey:value sets the amount to lock and the recipient --refund-to=pubkey sets "our" public key - --fee-per-kb=value sets the network fee + --fee-per-kb=0.0005 or --fee-sat-per-byte=50 sets the network fee --locktime=YYYY/MM/DD sets the expiry time for the channel settle-cltvpaymentchannel Creates and broadcasts a transaction settling a previous micropayment channel. This tool, for testing, requires the presence of both private keys. Options: --output=pubkey:value sets the destination for the money - --fee-per-kb=value sets the network fee + --fee-per-kb=0.0005 or --fee-sat-per-byte=50 sets the network fee --txhash=hash sets the transaction to spend refund-cltvpaymentchannel Creates and broadcasts a transaction refunding a previous micropayment channel. @@ -88,7 +88,7 @@ Usage: wallet-tool --flags action-name the created transaction won't be accepted into the mempool until that point. Options: --output=pubkey:value sets the destination for the money - --fee-per-kb=value sets the network fee + --fee-per-kb=0.0005 or --fee-sat-per-byte=50 sets the network fee --txhash=hash sets the transaction to spend >>> GENERAL OPTIONS