mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2024-11-19 09:50:32 +01:00
TransactionOutput: fix NullPointerException
in toString()
This commit is contained in:
parent
8b663363ef
commit
1c04dd94e7
@ -337,13 +337,15 @@ public class TransactionOutput extends Message {
|
||||
StringBuilder buf = new StringBuilder("TxOut of ");
|
||||
buf.append(Coin.valueOf(value).toFriendlyString());
|
||||
if (ScriptPattern.isP2PKH(script) || ScriptPattern.isP2WPKH(script) || ScriptPattern.isP2TR(script)
|
||||
|| ScriptPattern.isP2SH(script))
|
||||
buf.append(" to ").append(script.getToAddress(params.network()));
|
||||
else if (ScriptPattern.isP2PK(script))
|
||||
|| ScriptPattern.isP2SH(script)) {
|
||||
buf.append(" to ").append(script.getScriptType().name());
|
||||
if (params != null)
|
||||
buf.append(" ").append(script.getToAddress(params.network()));
|
||||
} else if (ScriptPattern.isP2PK(script)) {
|
||||
buf.append(" to pubkey ").append(ByteUtils.formatHex(ScriptPattern.extractKeyFromP2PK(script)));
|
||||
else if (ScriptPattern.isSentToMultisig(script))
|
||||
buf.append(" to multisig");
|
||||
else
|
||||
} else if (ScriptPattern.isSentToMultisig(script)) {
|
||||
final StringBuilder append = buf.append(" to multisig");
|
||||
} else
|
||||
buf.append(" (unknown type)");
|
||||
buf.append(" script:").append(script);
|
||||
return buf.toString();
|
||||
|
@ -105,4 +105,16 @@ public class TransactionOutputTest extends TestWithWallet {
|
||||
BitcoinNetwork.TESTNET));
|
||||
assertEquals(Coin.valueOf(294), p2wpkh.getMinNonDustValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toString_() {
|
||||
TransactionOutput p2pk = new TransactionOutput(null, Coin.COIN, myKey);
|
||||
p2pk.toString();
|
||||
TransactionOutput p2pkh = new TransactionOutput(null, Coin.COIN, myKey.toAddress(ScriptType.P2PKH,
|
||||
BitcoinNetwork.TESTNET));
|
||||
p2pkh.toString();
|
||||
TransactionOutput p2wpkh = new TransactionOutput(null, Coin.COIN, myKey.toAddress(ScriptType.P2WPKH,
|
||||
BitcoinNetwork.TESTNET));
|
||||
p2wpkh.toString();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user