mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-26 01:56:44 +00:00
move bitcoinunit to drongo
This commit is contained in:
parent
687e235c94
commit
4e7f0611c4
1 changed files with 50 additions and 0 deletions
50
src/main/java/com/sparrowwallet/drongo/BitcoinUnit.java
Normal file
50
src/main/java/com/sparrowwallet/drongo/BitcoinUnit.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
package com.sparrowwallet.drongo;
|
||||
|
||||
import com.sparrowwallet.drongo.protocol.Transaction;
|
||||
|
||||
public enum BitcoinUnit {
|
||||
BTC("BTC") {
|
||||
@Override
|
||||
public long getSatsValue(double unitValue) {
|
||||
return (long)(unitValue * Transaction.SATOSHIS_PER_BITCOIN);
|
||||
}
|
||||
|
||||
public double getValue(long satsValue) {
|
||||
return (double)satsValue / Transaction.SATOSHIS_PER_BITCOIN;
|
||||
}
|
||||
},
|
||||
SATOSHIS("sats") {
|
||||
@Override
|
||||
public long getSatsValue(double unitValue) {
|
||||
return (long)unitValue;
|
||||
}
|
||||
|
||||
public double getValue(long satsValue) {
|
||||
return (double)satsValue;
|
||||
}
|
||||
};
|
||||
|
||||
private final String label;
|
||||
|
||||
BitcoinUnit(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public abstract long getSatsValue(double unitValue);
|
||||
|
||||
public abstract double getValue(long satsValue);
|
||||
|
||||
public double convertFrom(double fromValue, BitcoinUnit fromUnit) {
|
||||
long satsValue = fromUnit.getSatsValue(fromValue);
|
||||
return getValue(satsValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return label;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue