forked from tronprotocol/java-tron
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoin.java
More file actions
51 lines (40 loc) · 1.02 KB
/
Coin.java
File metadata and controls
51 lines (40 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package org.tron.core;
import com.google.common.primitives.Longs;
import java.io.Serializable;
/**
* Represents a monetary Bitcoin value. This class is immutable.
*/
public final class Coin implements Monetary, Comparable<Coin>, Serializable {
/**
* Number of decimals for one Bitcoin. This constant is useful for quick adapting to other coins because a lot of
* constants derive from it.
*/
public static final int SMALLEST_UNIT_EXPONENT = 8;
public final long value;
private Coin(long satoshis) {
this.value = satoshis;
}
public static Coin valueOf(final long satoshis) {
return new Coin(satoshis);
}
@Override
public int compareTo(final Coin other) {
return Longs.compare(this.value, other.value);
}
@Override
public int smallestUnitExponent() {
return SMALLEST_UNIT_EXPONENT;
}
@Override
public long getValue() {
return value;
}
@Override
public int signum() {
if (this.value == 0) {
return 0;
} else {
return this.value < 0 ? -1 : 1;
}
}
}