Take out the redundant SigHashType parameter to wallet.signTransaction.

In the end the API evolved in such a way that changing this param isn't that useful. To do contracts you tend to work with transactions directly, and a Wallet subclass that needs to do special signing by default can override the signing engine used.
This commit is contained in:
Mike Hearn 2014-08-13 14:57:43 +02:00
parent c1e79b442c
commit 014438b456
3 changed files with 8 additions and 14 deletions

View File

@ -3318,7 +3318,7 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
// Now sign the inputs, thus proving that we are entitled to redeem the connected outputs.
if (req.signInputs) {
signTransaction(req.tx, Transaction.SigHash.ALL, req.aesKey);
signTransaction(req.tx, req.aesKey);
}
// Check size.
@ -3349,21 +3349,15 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
/**
* <p>Signs given transaction. Actual signing is done by pluggable {@link #signers} and it's not guaranteed that
* transaction will be complete in the end.</p>
* <p>Only {@link com.google.bitcoin.core.Transaction.SigHash#ALL} signing mode is currently supported</p>
* <p>Optional aesKey should be provided if this wallet is encrypted</p>
* transaction will be complete in the end. Optional aesKey should be provided if this wallet is encrypted</p>
*/
public void signTransaction(Transaction tx, Transaction.SigHash hashType, @Nullable KeyParameter aesKey) {
public void signTransaction(Transaction tx, @Nullable KeyParameter aesKey) {
lock.lock();
try {
List<TransactionInput> inputs = tx.getInputs();
List<TransactionOutput> outputs = tx.getOutputs();
checkState(inputs.size() > 0);
checkState(outputs.size() > 0);
// I don't currently have an easy way to test other modes work, as the official client does not use them.
checkArgument(hashType == Transaction.SigHash.ALL, "Only SIGHASH_ALL is currently supported");
KeyBag maybeDecryptingKeyBag = aesKey != null ? new DecryptingKeyBag(this, aesKey) : this;
for (TransactionSigner signer : signers) {
if (!signer.signInputs(tx, maybeDecryptingKeyBag))
@ -4270,7 +4264,7 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
}
rekeyTx.getConfidence().setSource(TransactionConfidence.Source.SELF);
rekeyTx.setPurpose(Transaction.Purpose.KEY_ROTATION);
signTransaction(rekeyTx, Transaction.SigHash.ALL, aesKey);
signTransaction(rekeyTx, aesKey);
// KeyTimeCoinSelector should never select enough inputs to push us oversize.
checkState(rekeyTx.bitcoinSerialize().length < Transaction.MAX_STANDARD_TX_SIZE);
return rekeyTx;

View File

@ -1356,7 +1356,7 @@ public class WalletTest extends TestWithWallet {
Transaction t3 = new Transaction(params);
t3.addOutput(v3, k3.toAddress(params));
t3.addInput(o2);
wallet.signTransaction(t3, Transaction.SigHash.ALL, null);
wallet.signTransaction(t3, null);
// Commit t3, so the coins from the pending t2 are spent
wallet.commitTx(t3);
@ -1897,7 +1897,7 @@ public class WalletTest extends TestWithWallet {
Transaction spendTx5 = new Transaction(params);
spendTx5.addOutput(CENT, notMyAddr);
spendTx5.addInput(tx5.getOutput(0));
wallet.signTransaction(spendTx5, Transaction.SigHash.ALL, null);
wallet.signTransaction(spendTx5, null);
wallet.receiveFromBlock(spendTx5, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 4);
assertEquals(COIN, wallet.getBalance());
@ -2148,7 +2148,7 @@ public class WalletTest extends TestWithWallet {
SendRequest request4 = SendRequest.to(notMyAddr, CENT);
request4.tx.addInput(tx3.getOutput(0));
// Now if we manually sign it, completeTx will not replace our signature
wallet.signTransaction(request4.tx, Transaction.SigHash.ALL, null);
wallet.signTransaction(request4.tx, null);
byte[] scriptSig = request4.tx.getInput(0).getScriptBytes();
wallet.completeTx(request4);
assertEquals(1, request4.tx.getInputs().size());

View File

@ -550,7 +550,7 @@ public class WalletTool {
// For lock times to take effect, at least one output must have a non-final sequence number.
t.getInputs().get(0).setSequenceNumber(0);
// And because we modified the transaction after it was completed, we must re-sign the inputs.
wallet.signTransaction(t, Transaction.SigHash.ALL, req.aesKey);
wallet.signTransaction(t, req.aesKey);
}
} catch (ParseException e) {
System.err.println("Could not understand --locktime of " + lockTimeStr);