3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-31 07:12:17 +00:00

Allow re-signing of transactions and re-sign after adjusting the sequence number.

This commit is contained in:
Mike Hearn 2013-01-12 14:47:43 +01:00
parent 916e33254f
commit e4e4e45a47
2 changed files with 6 additions and 2 deletions

View File

@ -709,7 +709,8 @@ public class Transaction extends ChildMessage implements Serializable {
ECKey[] signingKeys = new ECKey[inputs.size()]; ECKey[] signingKeys = new ECKey[inputs.size()];
for (int i = 0; i < inputs.size(); i++) { for (int i = 0; i < inputs.size(); i++) {
TransactionInput input = inputs.get(i); TransactionInput input = inputs.get(i);
Preconditions.checkState(input.getScriptBytes().length == 0, "Attempting to sign a non-fresh transaction"); if (input.getScriptBytes().length != 0)
log.warn("Re-signing an already signed transaction! Be sure this is what you want.");
// Find the signing key we'll need to use. // Find the signing key we'll need to use.
ECKey key = input.getOutpoint().getConnectedKey(wallet); ECKey key = input.getOutpoint().getConnectedKey(wallet);
// This assert should never fire. If it does, it means the wallet is inconsistent. // This assert should never fire. If it does, it means the wallet is inconsistent.
@ -743,7 +744,6 @@ public class Transaction extends ChildMessage implements Serializable {
// 2) For pay-to-key outputs: just a signature. // 2) For pay-to-key outputs: just a signature.
for (int i = 0; i < inputs.size(); i++) { for (int i = 0; i < inputs.size(); i++) {
TransactionInput input = inputs.get(i); TransactionInput input = inputs.get(i);
Preconditions.checkState(input.getScriptBytes().length == 0);
ECKey key = signingKeys[i]; ECKey key = signingKeys[i];
Script scriptPubKey = input.getOutpoint().getConnectedOutput().getScriptPubKey(); Script scriptPubKey = input.getOutpoint().getConnectedOutput().getScriptPubKey();
if (scriptPubKey.isSentToAddress()) { if (scriptPubKey.isSentToAddress()) {

View File

@ -424,10 +424,14 @@ public class WalletTool {
t.setLockTime(Transaction.parseLockTimeStr(lockTimeStr)); t.setLockTime(Transaction.parseLockTimeStr(lockTimeStr));
// 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.
t.signInputs(Transaction.SigHash.ALL, wallet);
} }
} catch (ParseException e) { } catch (ParseException e) {
System.err.println("Could not understand --locktime of " + lockTimeStr); System.err.println("Could not understand --locktime of " + lockTimeStr);
return; return;
} catch (ScriptException e) {
throw new RuntimeException(e);
} }
t = req.tx; // Not strictly required today. t = req.tx; // Not strictly required today.
setup(); setup();