3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-12 10:15:52 +00:00

Include PUSHDATA opcode in Script.toString(). Also, smallNums are printed in their decoded form.

This commit is contained in:
Andreas Schildbach 2014-03-08 23:39:39 +01:00 committed by Mike Hearn
parent c236ae418f
commit ff8d76cf7e
3 changed files with 17 additions and 3 deletions

View File

@ -111,11 +111,15 @@ public class Script {
if (chunk.isOpCode()) { if (chunk.isOpCode()) {
buf.append(getOpCodeName(chunk.opcode)); buf.append(getOpCodeName(chunk.opcode));
buf.append(" "); buf.append(" ");
} else { } else if (chunk.data != null) {
// Data chunk // Data chunk
buf.append(getPushDataName(chunk.opcode));
buf.append("["); buf.append("[");
buf.append(chunk.data != null ? bytesToHexString(chunk.data) : "null"); buf.append(bytesToHexString(chunk.data));
buf.append("] "); buf.append("] ");
} else {
// Small num
buf.append(decodeFromOpN(chunk.opcode));
} }
} }
return buf.toString().trim(); return buf.toString().trim();

View File

@ -392,6 +392,16 @@ public class ScriptOpCodes {
return "NON_OP(" + opcode + ")"; return "NON_OP(" + opcode + ")";
} }
/**
* Converts the given pushdata OpCode into a string (eg "PUSHDATA2", or "PUSHDATA(23)")
*/
public static String getPushDataName(int opcode) {
if (opCodeMap.containsKey(opcode))
return opCodeMap.get(opcode);
return "PUSHDATA(" + opcode + ")";
}
/** /**
* Converts the given OpCodeName into an int * Converts the given OpCodeName into an int
*/ */

View File

@ -69,7 +69,7 @@ public class ScriptTest {
// Check we can extract the to address // Check we can extract the to address
byte[] pubkeyBytes = Hex.decode(pubkeyProg); byte[] pubkeyBytes = Hex.decode(pubkeyProg);
Script pubkey = new Script(pubkeyBytes); Script pubkey = new Script(pubkeyBytes);
assertEquals("DUP HASH160 [33e81a941e64cda12c6a299ed322ddbdd03f8d0e] EQUALVERIFY CHECKSIG", pubkey.toString()); assertEquals("DUP HASH160 PUSHDATA(20)[33e81a941e64cda12c6a299ed322ddbdd03f8d0e] EQUALVERIFY CHECKSIG", pubkey.toString());
Address toAddr = new Address(params, pubkey.getPubKeyHash()); Address toAddr = new Address(params, pubkey.getPubKeyHash());
assertEquals("mkFQohBpy2HDXrCwyMrYL5RtfrmeiuuPY2", toAddr.toString()); assertEquals("mkFQohBpy2HDXrCwyMrYL5RtfrmeiuuPY2", toAddr.toString());
} }