Skip to content

Commit

Permalink
FakeTxBuilder: don't throw checked exceptions, it's just annoying.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehearn committed Apr 22, 2014
1 parent e1d6707 commit c43362e
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions core/src/main/java/com/google/bitcoin/testing/FakeTxBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
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);
Expand All @@ -46,11 +45,11 @@ public static Transaction createFakeTxWithChangeAddress(NetworkParameters params
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);
Expand All @@ -73,7 +72,7 @@ public static Transaction createFakeTx(NetworkParameters params, BigInteger nano
* @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);
Expand Down Expand Up @@ -103,11 +102,15 @@ public static Transaction[] createFakeTx(NetworkParameters params, BigInteger na
/**
* 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 {
Expand Down

0 comments on commit c43362e

Please sign in to comment.