mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-12 18:25:51 +00:00
Script.getPubKey(): Remove ability to extract the pubKey from inputs spending from P2PKH outputs.
This was only used in unit tests to determine the from address. One of the tests now tests this manually so that we don't loose test coverage.
This commit is contained in:
parent
ea2dc695d7
commit
234384c87e
@ -258,9 +258,7 @@ public class Script {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the public key in this script. If a script contains two constants and nothing else, it is assumed to
|
||||
* be a scriptSig (input) for a pay-to-address output and the second constant is returned (the first is the
|
||||
* signature). If a script contains a constant and an OP_CHECKSIG opcode, the constant is returned as it is
|
||||
* Returns the public key in this script. If a script contains a constant and an OP_CHECKSIG opcode, the constant is returned as it is
|
||||
* assumed to be a direct pay-to-key scriptPubKey (output) and the first constant is the public key.
|
||||
*
|
||||
* @throws ScriptException if the script is none of the named forms.
|
||||
@ -272,11 +270,7 @@ public class Script {
|
||||
final ScriptChunk chunk0 = chunks.get(0);
|
||||
final byte[] chunk0data = chunk0.data;
|
||||
final ScriptChunk chunk1 = chunks.get(1);
|
||||
final byte[] chunk1data = chunk1.data;
|
||||
if (chunk0data != null && chunk0data.length > 2 && chunk1data != null && chunk1data.length > 2) {
|
||||
// If we have two large constants assume the input to a pay-to-address output.
|
||||
return chunk1data;
|
||||
} else if (chunk1.equalsOpCode(OP_CHECKSIG) && chunk0data != null && chunk0data.length > 2) {
|
||||
if (chunk1.equalsOpCode(OP_CHECKSIG) && chunk0data != null && chunk0data.length > 2) {
|
||||
// A large constant followed by an OP_CHECKSIG is the key.
|
||||
return chunk0data;
|
||||
} else {
|
||||
|
@ -68,10 +68,9 @@ public class ScriptTest {
|
||||
public void testScriptSig() throws Exception {
|
||||
byte[] sigProgBytes = HEX.decode(sigProg);
|
||||
Script script = new Script(sigProgBytes);
|
||||
// Test we can extract the from address.
|
||||
byte[] hash160 = Utils.sha256hash160(script.getPubKey());
|
||||
Address a = new Address(PARAMS, hash160);
|
||||
assertEquals("mkFQohBpy2HDXrCwyMrYL5RtfrmeiuuPY2", a.toString());
|
||||
assertEquals(
|
||||
"PUSHDATA(71)[304402202b4da291cc39faf8433911988f9f49fc5c995812ca2f94db61468839c228c3e90220628bff3ff32ec95825092fa051cba28558a981fcf59ce184b14f2e215e69106701] PUSHDATA(65)[0414b38f4be3bb9fa0f4f32b74af07152b2f2f630bc02122a491137b6c523e46f18a0d5034418966f93dfc37cc3739ef7b2007213a302b7fba161557f4ad644a1c]",
|
||||
script.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -39,6 +39,7 @@ import org.bitcoinj.core.TransactionConfidence.ConfidenceType;
|
||||
import org.bitcoinj.crypto.*;
|
||||
import org.bitcoinj.script.Script;
|
||||
import org.bitcoinj.script.ScriptBuilder;
|
||||
import org.bitcoinj.script.ScriptChunk;
|
||||
import org.bitcoinj.signers.StatelessTransactionSigner;
|
||||
import org.bitcoinj.signers.TransactionSigner;
|
||||
import org.bitcoinj.store.BlockStoreException;
|
||||
@ -481,8 +482,10 @@ public class WalletTest extends TestWithWallet {
|
||||
|
||||
// Do some basic sanity checks.
|
||||
assertEquals(1, t2.getInputs().size());
|
||||
List<ScriptChunk> scriptSigChunks = t2.getInput(0).getScriptSig().getChunks();
|
||||
// check 'from address' -- in a unit test this is fine
|
||||
assertEquals(myAddress, new Address(PARAMS, Utils.sha256hash160(t2.getInput(0).getScriptSig().getPubKey())));
|
||||
assertEquals(2, scriptSigChunks.size());
|
||||
assertEquals(myAddress, new Address(PARAMS, Utils.sha256hash160(scriptSigChunks.get(1).data)));
|
||||
assertEquals(TransactionConfidence.ConfidenceType.UNKNOWN, t2.getConfidence().getConfidenceType());
|
||||
|
||||
// We have NOT proven that the signature is correct!
|
||||
|
Loading…
x
Reference in New Issue
Block a user