private static BigInteger inSatoshis ( Object qty ) { BigInteger satoshis ; // the value might be bitcoins or satoshis if ( qty instanceof Long || qty instanceof Integer ) satoshis = BigInteger . valueOf ( ( ( Number ) qty ) . longValue ( ) ) ; else if ( qty instanceof BigInteger ) satoshis = ( BigInteger ) qty ; else if ( qty instanceof BigDecimal ) satoshis = ( ( BigDecimal ) qty ) . movePointRight ( Coin . SMALLEST_UNIT_EXPONENT ) . setScale ( 0 , BigDecimal . ROUND_HALF_UP ) . unscaledValue ( ) ; else if ( qty instanceof Coin ) satoshis = BigInteger . valueOf ( ( ( Coin ) qty ) . value ) ; else throw new IllegalArgumentException ( "Cannot format a " + qty . getClass ( ) . getSimpleName ( ) + " as a Bicoin value" ) ; return satoshis ; }
Takes an object representing a bitcoin quantity of any type the client is permitted to pass us and return a BigInteger representing the number of satoshis having the equivalent value .