3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-14 11:15:51 +00:00

Remove weird constructors.

This commit is contained in:
Andreas Schildbach 2014-04-26 19:03:33 +02:00 committed by Mike Hearn
parent 48a76a8a03
commit ee4dec1835
3 changed files with 8 additions and 20 deletions

View File

@ -29,9 +29,9 @@ import com.google.common.math.LongMath;
*/ */
public final class Coin implements Comparable<Coin>, Serializable { public final class Coin implements Comparable<Coin>, Serializable {
public static final Coin ZERO = new Coin(BigInteger.ZERO); public static final Coin ZERO = Coin.valueOf(0);
public static final Coin ONE = new Coin(BigInteger.ONE); public static final Coin ONE = Coin.valueOf(1);
public static final Coin TEN = new Coin(BigInteger.TEN); public static final Coin TEN = Coin.valueOf(10);
public static final Coin NEGATIVE_ONE = Coin.valueOf(-1); public static final Coin NEGATIVE_ONE = Coin.valueOf(-1);
/** /**
@ -41,7 +41,7 @@ public final class Coin implements Comparable<Coin>, Serializable {
* The term nanocoin is very misleading, though, because there are only 100 million * The term nanocoin is very misleading, though, because there are only 100 million
* of them in a coin (whereas one would expect 1 billion. * of them in a coin (whereas one would expect 1 billion.
*/ */
public static final Coin COIN = new Coin("100000000", 10); public static final Coin COIN = Coin.valueOf(100000000);
/** /**
* How many "nanocoins" there are in 0.01 BitCoins. * How many "nanocoins" there are in 0.01 BitCoins.
@ -50,7 +50,7 @@ public final class Coin implements Comparable<Coin>, Serializable {
* The term nanocoin is very misleading, though, because there are only 100 million * The term nanocoin is very misleading, though, because there are only 100 million
* of them in a coin (whereas one would expect 1 billion). * of them in a coin (whereas one would expect 1 billion).
*/ */
public static final Coin CENT = new Coin("1000000", 10); public static final Coin CENT = Coin.valueOf(1000000);
private final long value; private final long value;
@ -58,18 +58,6 @@ public final class Coin implements Comparable<Coin>, Serializable {
this.value = satoshis; this.value = satoshis;
} }
public Coin(final BigInteger value) {
this.value = value.longValue();
}
public Coin(final String value, final int radix) {
this(new BigInteger(value, radix));
}
public Coin(final byte[] value) {
this(new BigInteger(value));
}
public static Coin valueOf(final long satoshis) { public static Coin valueOf(final long satoshis) {
return new Coin(satoshis); return new Coin(satoshis);
} }
@ -141,7 +129,7 @@ public final class Coin implements Comparable<Coin>, Serializable {
* @throws ArithmeticException if you try to specify fractional nanocoins, or nanocoins out of range. * @throws ArithmeticException if you try to specify fractional nanocoins, or nanocoins out of range.
*/ */
public static Coin toNanoCoins(String coins) { public static Coin toNanoCoins(String coins) {
Coin bigint = new Coin(new BigDecimal(coins).movePointRight(8).toBigIntegerExact()); Coin bigint = Coin.valueOf(new BigDecimal(coins).movePointRight(8).toBigIntegerExact().longValue());
if (bigint.signum() < 0) if (bigint.signum() < 0)
throw new ArithmeticException("Negative coins specified"); throw new ArithmeticException("Negative coins specified");
if (bigint.compareTo(NetworkParameters.MAX_MONEY) > 0) if (bigint.compareTo(NetworkParameters.MAX_MONEY) > 0)

View File

@ -650,7 +650,7 @@ public class H2FullPrunedBlockStore implements FullPrunedBlockStore {
} }
// Parse it. // Parse it.
int height = results.getInt(1); int height = results.getInt(1);
Coin value = new Coin(results.getBytes(2)); Coin value = Coin.valueOf(new BigInteger(results.getBytes(2)).longValue());
// Tell the StoredTransactionOutput that we are a coinbase, as that is encoded in height // Tell the StoredTransactionOutput that we are a coinbase, as that is encoded in height
return new StoredTransactionOutput(hash, index, value, height, true, results.getBytes(3)); return new StoredTransactionOutput(hash, index, value, height, true, results.getBytes(3));
} catch (SQLException ex) { } catch (SQLException ex) {

View File

@ -744,7 +744,7 @@ public class PostgresFullPrunedBlockStore implements FullPrunedBlockStore {
} }
// Parse it. // Parse it.
int height = results.getInt(1); int height = results.getInt(1);
Coin value = new Coin(results.getBytes(2)); Coin value = Coin.valueOf(new BigInteger(results.getBytes(2)).longValue());
// Tell the StoredTransactionOutput that we are a coinbase, as that is encoded in height // Tell the StoredTransactionOutput that we are a coinbase, as that is encoded in height
StoredTransactionOutput txout = new StoredTransactionOutput(hash, index, value, height, true, results.getBytes(3)); StoredTransactionOutput txout = new StoredTransactionOutput(hash, index, value, height, true, results.getBytes(3));
return txout; return txout;