/** Returns a human readable debug string. */
 @Override
 public String toString() {
   try {
     Script script = getScriptPubKey();
     StringBuilder buf = new StringBuilder("TxOut of ");
     buf.append(Coin.valueOf(value).toFriendlyString());
     if (script.isSentToAddress() || script.isPayToScriptHash())
       buf.append(" to ").append(script.getToAddress(params));
     else if (script.isSentToRawPubKey())
       buf.append(" to pubkey ").append(Utils.HEX.encode(script.getPubKey()));
     else if (script.isSentToMultiSig()) buf.append(" to multisig");
     else buf.append(" (unknown type)");
     buf.append(" script:");
     buf.append(script);
     return buf.toString();
   } catch (ScriptException e) {
     throw new RuntimeException(e);
   }
 }