TransactionOutput: fix toString() throws on unparseable script

This commit is contained in:
Andreas Schildbach 2023-04-04 10:51:57 +02:00
parent 5f510d777b
commit 37fbe5ed7d

View File

@ -343,10 +343,10 @@ public class TransactionOutput extends Message {
* @return debug string
*/
public String toString(@Nullable Network network) {
try {
Script script = getScriptPubKey();
StringBuilder buf = new StringBuilder("TxOut of ");
buf.append(Coin.valueOf(value).toFriendlyString());
try {
Script script = getScriptPubKey();
if (ScriptPattern.isP2PKH(script) || ScriptPattern.isP2WPKH(script) || ScriptPattern.isP2TR(script)
|| ScriptPattern.isP2SH(script)) {
buf.append(" to ").append(script.getScriptType().name());
@ -360,10 +360,10 @@ public class TransactionOutput extends Message {
buf.append(" (unknown type)");
}
buf.append(" script:").append(script);
return buf.toString();
} catch (ScriptException e) {
throw new RuntimeException(e);
buf.append(" [exception: ").append(e.getMessage()).append("]");
}
return buf.toString();
}
/**