3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-31 15:22:16 +00:00

FakeTxBuilder: don't throw checked exceptions, it's just annoying.

This commit is contained in:
Mike Hearn 2014-04-22 16:51:12 +02:00
parent e1d6707626
commit c43362e128

View File

@ -26,8 +26,7 @@ import java.math.BigInteger;
import java.nio.ByteBuffer;
public class FakeTxBuilder {
public static Transaction createFakeTxWithChangeAddress(NetworkParameters params, BigInteger nanocoins, Address to, Address changeOutput)
throws IOException, ProtocolException {
public static Transaction createFakeTxWithChangeAddress(NetworkParameters params, BigInteger nanocoins, Address to, Address changeOutput) {
// Create a fake TX of sufficient realism to exercise the unit tests. Two outputs, one to us, one to somewhere
// else to simulate change.
Transaction t = new Transaction(params);
@ -46,11 +45,11 @@ public class FakeTxBuilder {
return roundTripTransaction(params, t);
}
public static Transaction createFakeTx(NetworkParameters params, BigInteger nanocoins, Address to) throws IOException, ProtocolException {
public static Transaction createFakeTx(NetworkParameters params, BigInteger nanocoins, Address to) {
return createFakeTxWithChangeAddress(params, nanocoins, to, new ECKey().toAddress(params));
}
public static Transaction createFakeTx(NetworkParameters params, BigInteger nanocoins, ECKey to) throws IOException, ProtocolException {
public static Transaction createFakeTx(NetworkParameters params, BigInteger nanocoins, ECKey to) {
// Create a fake TX of sufficient realism to exercise the unit tests. Two outputs, one to us, one to somewhere
// else to simulate change.
Transaction t = new Transaction(params);
@ -73,7 +72,7 @@ public class FakeTxBuilder {
* @return Transaction[] Transaction[0] is a feeder transaction, supplying BTC to Transaction[1]
*/
public static Transaction[] createFakeTx(NetworkParameters params, BigInteger nanocoins,
Address to, Address from) throws IOException, ProtocolException {
Address to, Address from) {
// Create fake TXes of sufficient realism to exercise the unit tests. This transaction send BTC from the
// from address, to the to address with to one to somewhere else to simulate change.
Transaction t = new Transaction(params);
@ -103,11 +102,15 @@ public class FakeTxBuilder {
/**
* Roundtrip a transaction so that it appears as if it has just come from the wire
*/
public static Transaction roundTripTransaction(NetworkParameters params, Transaction tx) throws IOException, ProtocolException {
BitcoinSerializer bs = new BitcoinSerializer(params);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bs.serialize(tx, bos);
return (Transaction) bs.deserialize(ByteBuffer.wrap(bos.toByteArray()));
public static Transaction roundTripTransaction(NetworkParameters params, Transaction tx) {
try {
BitcoinSerializer bs = new BitcoinSerializer(params);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bs.serialize(tx, bos);
return (Transaction) bs.deserialize(ByteBuffer.wrap(bos.toByteArray()));
} catch (IOException e) {
throw new RuntimeException(e); // Should not happen.
}
}
public static class DoubleSpends {