mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-31 15:22:16 +00:00
Fix extra signature added to the full scriptSig
This commit is contained in:
parent
3e5e3496ea
commit
cf5089697b
@ -203,7 +203,8 @@ public class ScriptBuilder {
|
|||||||
/**
|
/**
|
||||||
* Returns a copy of the given scriptSig with the signature inserted in the given position.
|
* Returns a copy of the given scriptSig with the signature inserted in the given position.
|
||||||
*
|
*
|
||||||
* This function assumes that any missing sigs have OP_0 placeholders.
|
* This function assumes that any missing sigs have OP_0 placeholders. If given scriptSig already has all the signatures
|
||||||
|
* in place, IllegalArgumentException will be thrown.
|
||||||
*
|
*
|
||||||
* @param targetIndex where to insert the signature
|
* @param targetIndex where to insert the signature
|
||||||
* @param sigsPrefixCount how many items to copy verbatim (e.g. initial OP_0 for multisig)
|
* @param sigsPrefixCount how many items to copy verbatim (e.g. initial OP_0 for multisig)
|
||||||
@ -215,6 +216,12 @@ public class ScriptBuilder {
|
|||||||
List<ScriptChunk> inputChunks = scriptSig.getChunks();
|
List<ScriptChunk> inputChunks = scriptSig.getChunks();
|
||||||
int totalChunks = inputChunks.size();
|
int totalChunks = inputChunks.size();
|
||||||
|
|
||||||
|
// Check if we have a place to insert, otherwise just return given scriptSig unchanged.
|
||||||
|
// We assume here that OP_0 placeholders always go after the sigs, so
|
||||||
|
// to find if we have sigs missing, we can just check the chunk in latest sig position
|
||||||
|
boolean hasMissingSigs = inputChunks.get(totalChunks - sigsSuffixCount - 1).equalsOpCode(OP_0);
|
||||||
|
checkArgument(hasMissingSigs, "ScriptSig is already filled with signatures");
|
||||||
|
|
||||||
// copy the prefix
|
// copy the prefix
|
||||||
for (ScriptChunk chunk: inputChunks.subList(0, sigsPrefixCount))
|
for (ScriptChunk chunk: inputChunks.subList(0, sigsPrefixCount))
|
||||||
builder.addChunk(chunk);
|
builder.addChunk(chunk);
|
||||||
|
@ -153,7 +153,7 @@ public class ScriptTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateEmptyInputScript() throws Exception {
|
public void createAndUpdateEmptyInputScript() throws Exception {
|
||||||
TransactionSignature dummySig = TransactionSignature.dummy();
|
TransactionSignature dummySig = TransactionSignature.dummy();
|
||||||
ECKey key = new ECKey();
|
ECKey key = new ECKey();
|
||||||
|
|
||||||
@ -196,6 +196,14 @@ public class ScriptTest {
|
|||||||
assertThat(inputScript.getChunks().get(1).data, equalTo(dummySig.encodeToBitcoin()));
|
assertThat(inputScript.getChunks().get(1).data, equalTo(dummySig.encodeToBitcoin()));
|
||||||
assertThat(inputScript.getChunks().get(2).data, equalTo(dummySig.encodeToBitcoin()));
|
assertThat(inputScript.getChunks().get(2).data, equalTo(dummySig.encodeToBitcoin()));
|
||||||
assertThat(inputScript.getChunks().get(3).data, equalTo(multisigScript.getProgram()));
|
assertThat(inputScript.getChunks().get(3).data, equalTo(multisigScript.getProgram()));
|
||||||
|
|
||||||
|
// updating scriptSig with no missing signatures
|
||||||
|
try {
|
||||||
|
ScriptBuilder.updateScriptWithSignature(inputScript, dummySig.encodeToBitcoin(), 1, 1, 1);
|
||||||
|
fail("Exception expected");
|
||||||
|
} catch (Exception e) {
|
||||||
|
assertEquals(IllegalArgumentException.class, e.getClass());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Script parseScriptString(String string) throws IOException {
|
private Script parseScriptString(String string) throws IOException {
|
||||||
|
Loading…
Reference in New Issue
Block a user