Coverage Summary for Class: Denomination (org.ethereum.core)

Class Class, % Method, % Line, %
Denomination 0% (0/1) 0% (0/9) 0% (0/21)


1 /* 2  * This file is part of RskJ 3  * Copyright (C) 2017 RSK Labs Ltd. 4  * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) 5  * 6  * This program is free software: you can redistribute it and/or modify 7  * it under the terms of the GNU Lesser General Public License as published by 8  * the Free Software Foundation, either version 3 of the License, or 9  * (at your option) any later version. 10  * 11  * This program is distributed in the hope that it will be useful, 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14  * GNU Lesser General Public License for more details. 15  * 16  * You should have received a copy of the GNU Lesser General Public License 17  * along with this program. If not, see <http://www.gnu.org/licenses/>. 18  */ 19  20 package org.ethereum.core; 21  22 import java.math.BigInteger; 23  24 public enum Denomination { 25  26  WEI(newBigInt(0)), 27  SATOSHI(newBigInt(10)), 28  SZABO(newBigInt(12)), 29  FINNEY(newBigInt(15)), 30  SBTC(newBigInt(18)); 31  32  private BigInteger amount; 33  34  private Denomination(BigInteger value) { 35  this.amount = value; 36  } 37  38  public BigInteger value() { 39  return amount; 40  } 41  42  public long longValue() { 43  return value().longValue(); 44  } 45  46  private static BigInteger newBigInt(int value) { 47  return BigInteger.valueOf(10).pow(value); 48  } 49  50  public static String toFriendlyString(BigInteger value) { 51  if (value.compareTo(SBTC.value()) == 1 || value.compareTo(SBTC.value()) == 0) { 52  return Float.toString(value.divide(SBTC.value()).floatValue()) + " SBTC"; 53  } 54  else if(value.compareTo(FINNEY.value()) == 1 || value.compareTo(FINNEY.value()) == 0) { 55  return Float.toString(value.divide(FINNEY.value()).floatValue()) + " FINNEY"; 56  } 57  else if(value.compareTo(SZABO.value()) == 1 || value.compareTo(SZABO.value()) == 0) { 58  return Float.toString(value.divide(SZABO.value()).floatValue()) + " SZABO"; 59  } 60  else { 61  return Float.toString(value.divide(WEI.value()).floatValue()) + " WEI"; 62  } 63  } 64  65  public static BigInteger weisToSatoshis(BigInteger weis) { 66  return weis.divide(SATOSHI.value()) ; 67  } 68  69  public static BigInteger satoshisToWeis(BigInteger satoshis) { 70  return satoshis.multiply(SATOSHI.value()); 71  } 72  73  public static BigInteger satoshisToWeis(long satoshis) { 74  return BigInteger.valueOf(satoshis).multiply(SATOSHI.value()); 75  } 76  77 }