mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-31 15:22:16 +00:00
Include PUSHDATA opcode in Script.toString(). Also, smallNums are printed in their decoded form.
This commit is contained in:
parent
c236ae418f
commit
ff8d76cf7e
@ -111,11 +111,15 @@ public class Script {
|
||||
if (chunk.isOpCode()) {
|
||||
buf.append(getOpCodeName(chunk.opcode));
|
||||
buf.append(" ");
|
||||
} else {
|
||||
} else if (chunk.data != null) {
|
||||
// Data chunk
|
||||
buf.append(getPushDataName(chunk.opcode));
|
||||
buf.append("[");
|
||||
buf.append(chunk.data != null ? bytesToHexString(chunk.data) : "null");
|
||||
buf.append(bytesToHexString(chunk.data));
|
||||
buf.append("] ");
|
||||
} else {
|
||||
// Small num
|
||||
buf.append(decodeFromOpN(chunk.opcode));
|
||||
}
|
||||
}
|
||||
return buf.toString().trim();
|
||||
|
@ -392,6 +392,16 @@ public class ScriptOpCodes {
|
||||
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
|
||||
*/
|
||||
|
@ -69,7 +69,7 @@ public class ScriptTest {
|
||||
// Check we can extract the to address
|
||||
byte[] pubkeyBytes = Hex.decode(pubkeyProg);
|
||||
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());
|
||||
assertEquals("mkFQohBpy2HDXrCwyMrYL5RtfrmeiuuPY2", toAddr.toString());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user