mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2024-11-19 18:00:39 +01:00
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:
parent
c1e79b442c
commit
014438b456
@ -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.
|
// Now sign the inputs, thus proving that we are entitled to redeem the connected outputs.
|
||||||
if (req.signInputs) {
|
if (req.signInputs) {
|
||||||
signTransaction(req.tx, Transaction.SigHash.ALL, req.aesKey);
|
signTransaction(req.tx, req.aesKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check size.
|
// 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
|
* <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>
|
* transaction will be complete in the end. Optional aesKey should be provided if this wallet is encrypted</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>
|
|
||||||
*/
|
*/
|
||||||
public void signTransaction(Transaction tx, Transaction.SigHash hashType, @Nullable KeyParameter aesKey) {
|
public void signTransaction(Transaction tx, @Nullable KeyParameter aesKey) {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
List<TransactionInput> inputs = tx.getInputs();
|
List<TransactionInput> inputs = tx.getInputs();
|
||||||
List<TransactionOutput> outputs = tx.getOutputs();
|
List<TransactionOutput> outputs = tx.getOutputs();
|
||||||
checkState(inputs.size() > 0);
|
checkState(inputs.size() > 0);
|
||||||
checkState(outputs.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;
|
KeyBag maybeDecryptingKeyBag = aesKey != null ? new DecryptingKeyBag(this, aesKey) : this;
|
||||||
for (TransactionSigner signer : signers) {
|
for (TransactionSigner signer : signers) {
|
||||||
if (!signer.signInputs(tx, maybeDecryptingKeyBag))
|
if (!signer.signInputs(tx, maybeDecryptingKeyBag))
|
||||||
@ -4270,7 +4264,7 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
|
|||||||
}
|
}
|
||||||
rekeyTx.getConfidence().setSource(TransactionConfidence.Source.SELF);
|
rekeyTx.getConfidence().setSource(TransactionConfidence.Source.SELF);
|
||||||
rekeyTx.setPurpose(Transaction.Purpose.KEY_ROTATION);
|
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.
|
// KeyTimeCoinSelector should never select enough inputs to push us oversize.
|
||||||
checkState(rekeyTx.bitcoinSerialize().length < Transaction.MAX_STANDARD_TX_SIZE);
|
checkState(rekeyTx.bitcoinSerialize().length < Transaction.MAX_STANDARD_TX_SIZE);
|
||||||
return rekeyTx;
|
return rekeyTx;
|
||||||
|
@ -1356,7 +1356,7 @@ public class WalletTest extends TestWithWallet {
|
|||||||
Transaction t3 = new Transaction(params);
|
Transaction t3 = new Transaction(params);
|
||||||
t3.addOutput(v3, k3.toAddress(params));
|
t3.addOutput(v3, k3.toAddress(params));
|
||||||
t3.addInput(o2);
|
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
|
// Commit t3, so the coins from the pending t2 are spent
|
||||||
wallet.commitTx(t3);
|
wallet.commitTx(t3);
|
||||||
@ -1897,7 +1897,7 @@ public class WalletTest extends TestWithWallet {
|
|||||||
Transaction spendTx5 = new Transaction(params);
|
Transaction spendTx5 = new Transaction(params);
|
||||||
spendTx5.addOutput(CENT, notMyAddr);
|
spendTx5.addOutput(CENT, notMyAddr);
|
||||||
spendTx5.addInput(tx5.getOutput(0));
|
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);
|
wallet.receiveFromBlock(spendTx5, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 4);
|
||||||
assertEquals(COIN, wallet.getBalance());
|
assertEquals(COIN, wallet.getBalance());
|
||||||
@ -2148,7 +2148,7 @@ public class WalletTest extends TestWithWallet {
|
|||||||
SendRequest request4 = SendRequest.to(notMyAddr, CENT);
|
SendRequest request4 = SendRequest.to(notMyAddr, CENT);
|
||||||
request4.tx.addInput(tx3.getOutput(0));
|
request4.tx.addInput(tx3.getOutput(0));
|
||||||
// Now if we manually sign it, completeTx will not replace our signature
|
// 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();
|
byte[] scriptSig = request4.tx.getInput(0).getScriptBytes();
|
||||||
wallet.completeTx(request4);
|
wallet.completeTx(request4);
|
||||||
assertEquals(1, request4.tx.getInputs().size());
|
assertEquals(1, request4.tx.getInputs().size());
|
||||||
|
@ -550,7 +550,7 @@ public class WalletTool {
|
|||||||
// For lock times to take effect, at least one output must have a non-final sequence number.
|
// For lock times to take effect, at least one output must have a non-final sequence number.
|
||||||
t.getInputs().get(0).setSequenceNumber(0);
|
t.getInputs().get(0).setSequenceNumber(0);
|
||||||
// And because we modified the transaction after it was completed, we must re-sign the inputs.
|
// 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) {
|
} catch (ParseException e) {
|
||||||
System.err.println("Could not understand --locktime of " + lockTimeStr);
|
System.err.println("Could not understand --locktime of " + lockTimeStr);
|
||||||
|
Loading…
Reference in New Issue
Block a user