protected static Value parseValueRound(CoinType type, String string) { return parseValue(type, string, RoundingMode.HALF_UP); }
public ShapeShiftTxStatus getShapeShiftTxStatus() { ShapeShiftTxStatus.Status shapeShiftStatus; switch (status) { case STATUS_INITIAL: shapeShiftStatus = ShapeShiftTxStatus.Status.NO_DEPOSITS; break; case STATUS_PROCESSING: shapeShiftStatus = ShapeShiftTxStatus.Status.RECEIVED; break; case STATUS_COMPLETE: shapeShiftStatus = ShapeShiftTxStatus.Status.COMPLETE; break; case STATUS_FAILED: shapeShiftStatus = ShapeShiftTxStatus.Status.FAILED; break; case STATUS_UNKNOWN: default: shapeShiftStatus = ShapeShiftTxStatus.Status.UNKNOWN; } return new ShapeShiftTxStatus(shapeShiftStatus, depositAddress, withdrawAddress, depositAmount, withdrawAmount, withdrawTransactionId); }
private void checkPair(String expectedPair, String pair) throws ShapeShiftException { if (!expectedPair.equals(pair)) { String errorMsg = String.format("Pair mismatch, expected %s but got %s.", expectedPair, pair); throw new ShapeShiftException(errorMsg); } }
public ShapeShiftMarketInfo(JSONObject data) throws ShapeShiftException { super(data); if (!isError) { // In market info minerFee is mandatory if (!data.has("minerFee")) { throw new ShapeShiftException("Missing value minerfee"); } try { CoinType[] types = ShapeShift.parsePair(pair); rate = new ShapeShiftExchangeRate(types[0], types[1], data.getString("rate"), data.getString("minerFee")); limit = parseValue(types[0], data.getString("limit"), RoundingMode.DOWN); minimum = parseValue(types[0], data.getString("minimum"), RoundingMode.UP); } catch (JSONException e) { throw new ShapeShiftException("Could not parse object", e); } } else { rate = null; limit = null; minimum = null; } } }
/** * Get the lowest deposit or withdraw for the provided amount type */ private Value getLowestAmount(ValueType type) { Value min = type.getMinNonDust(); if (marketInfo != null) { if (marketInfo.minimum.isOfType(min)) { min = Value.max(marketInfo.minimum, min); } else if (marketInfo.rate.canConvert(type, marketInfo.minimum.type)) { min = Value.max(marketInfo.rate.convert(marketInfo.minimum), min); } } return min; }
@Override public Value convert(CoinType type, Coin coin) { return convert(Value.valueOf(type, coin)); }
@Test(expected = ShapeShiftException.class) public void testInvalidTxStatus() throws ShapeShiftException { new ShapeShiftTime(new JSONObject()); } }
@Test(expected = ShapeShiftException.class) public void testInvalidMarketInfo() throws JSONException, ShapeShiftException { new ShapeShiftRate(new JSONObject( "{" + "\"pair\" : \"btc_nbt\"," + "\"rate\" : \"0\"," + "\"minerFee\" : \"0.01\"," + "\"limit\" : \"0\"," + "\"minimum\" : 0" + "}")); }
/** * Updates the exchange rate and limits for the specific market. * Note: if the current pair is different that the marketInfo pair, do nothing */ private void onMarketUpdate(ShapeShiftMarketInfo marketInfo) { if (address != null && marketInfo.isPair(account.getCoinType(), address.getType())) { this.marketInfo = marketInfo; } }
@Test(expected = IllegalArgumentException.class) public void zeroExchangeRate() throws Exception { new ShapeShiftExchangeRate(BTC, NBT, "0", "0.01"); } }
@Test(expected = ShapeShiftException.class) public void testInvalidCoin() throws ShapeShiftException, JSONException { JSONObject json = new JSONObject( "{" + "LTC: {" + "bad: \"\"" + "}" + "}"); new ShapeShiftCoin(json); }
@Test(expected = ShapeShiftException.class) public void testInvalidLimit() throws ShapeShiftException { new ShapeShiftLimit(new JSONObject()); }
/** * Get List of Supported Coins * * List of all the currencies that Shapeshift currently supports at any given time. Sometimes * coins become temporarily unavailable during updates or unexpected service issues. */ public ShapeShiftCoins getCoins() throws ShapeShiftException, IOException { Request request = new Request.Builder().url(getApiUrl(GET_COINS_API)).build(); return new ShapeShiftCoins(getMakeApiCall(request)); }
public boolean isPair(CoinType sourceType, CoinType destinationType) { return isPair(ShapeShift.getPair(sourceType, destinationType)); }
public ShapeShiftPairBase(JSONObject data) throws ShapeShiftException { super(data); if (!isError) { try { pair = data.getString("pair").toLowerCase(); } catch (JSONException e) { throw new ShapeShiftException("Could not parse object", e); } } else { pair = null; } }
@Test(expected = ShapeShiftException.class) public void testInvalidTime() throws ShapeShiftException { new ShapeShiftTime(new JSONObject()); }
@Test(expected = ShapeShiftException.class) public void testInvalidRate() throws ShapeShiftException { new ShapeShiftRate(new JSONObject()); }
public ShapeShiftEmail(JSONObject data) throws ShapeShiftException { super(data); if (!isError) { try { JSONObject innerData = data.getJSONObject("email"); message = innerData.getString("message"); String statusStr = innerData.getString("status"); switch (statusStr) { case "success": status = Status.SUCCESS; break; default: status = Status.UNKNOWN; } } catch (JSONException e) { throw new ShapeShiftException("Could not parse object", e); } } else { status = null; message = null; } } }
private void checkValue(Value expected, Value value) throws ShapeShiftException { if (!expected.equals(value)) { String errorMsg = String.format("Value mismatch, expected %s but got %s.", expected, value); throw new ShapeShiftException(errorMsg); } }
@Override protected Void doInBackground(Void... params) { if (application.isConnected()) { try { shapeShiftCoins = application.getShapeShift().getCoins(); } catch (Exception e) { error = e; } } else { error = new ShapeShiftException("No connection"); } return null; }