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:
parent
e1d6707626
commit
c43362e128
@ -26,8 +26,7 @@ import java.math.BigInteger;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
public class FakeTxBuilder {
|
public class FakeTxBuilder {
|
||||||
public static Transaction createFakeTxWithChangeAddress(NetworkParameters params, BigInteger nanocoins, Address to, Address changeOutput)
|
public static Transaction createFakeTxWithChangeAddress(NetworkParameters params, BigInteger nanocoins, Address to, Address changeOutput) {
|
||||||
throws IOException, ProtocolException {
|
|
||||||
// Create a fake TX of sufficient realism to exercise the unit tests. Two outputs, one to us, one to somewhere
|
// Create a fake TX of sufficient realism to exercise the unit tests. Two outputs, one to us, one to somewhere
|
||||||
// else to simulate change.
|
// else to simulate change.
|
||||||
Transaction t = new Transaction(params);
|
Transaction t = new Transaction(params);
|
||||||
@ -46,11 +45,11 @@ public class FakeTxBuilder {
|
|||||||
return roundTripTransaction(params, t);
|
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));
|
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
|
// Create a fake TX of sufficient realism to exercise the unit tests. Two outputs, one to us, one to somewhere
|
||||||
// else to simulate change.
|
// else to simulate change.
|
||||||
Transaction t = new Transaction(params);
|
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]
|
* @return Transaction[] Transaction[0] is a feeder transaction, supplying BTC to Transaction[1]
|
||||||
*/
|
*/
|
||||||
public static Transaction[] createFakeTx(NetworkParameters params, BigInteger nanocoins,
|
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
|
// 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.
|
// from address, to the to address with to one to somewhere else to simulate change.
|
||||||
Transaction t = new Transaction(params);
|
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
|
* 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 {
|
public static Transaction roundTripTransaction(NetworkParameters params, Transaction tx) {
|
||||||
BitcoinSerializer bs = new BitcoinSerializer(params);
|
try {
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
BitcoinSerializer bs = new BitcoinSerializer(params);
|
||||||
bs.serialize(tx, bos);
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
return (Transaction) bs.deserialize(ByteBuffer.wrap(bos.toByteArray()));
|
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 {
|
public static class DoubleSpends {
|
||||||
|
Loading…
Reference in New Issue
Block a user