public static boolean is(CoinType myType, AbstractAddress address) { return address != null && myType.equals(address.getType()); } }
boolean isExchangeNeeded() { return !sourceType.equals(sendToAddress.getType()); }
public static void edit(final FragmentManager fm, @Nonnull final AbstractAddress address) { edit(fm, address.getType(), address, null); }
public ContentValues getContentValues() { ContentValues values = new ContentValues(); values.put(KEY_STATUS, status); values.put(KEY_DEPOSIT_ADDRESS, depositAddress.toString()); values.put(KEY_DEPOSIT_COIN_ID, depositAddress.getType().getId()); values.put(KEY_DEPOSIT_AMOUNT_UNIT, depositAmount.value); values.put(KEY_DEPOSIT_TXID, depositTransactionId); if (withdrawAddress != null) values.put(KEY_WITHDRAW_ADDRESS, withdrawAddress.toString()); if (withdrawAddress != null) values.put(KEY_WITHDRAW_COIN_ID, withdrawAddress.getType().getId()); if (withdrawAmount != null) values.put(KEY_WITHDRAW_AMOUNT_UNIT, withdrawAmount.value); if (withdrawTransactionId != null) values.put(KEY_WITHDRAW_TXID, withdrawTransactionId); return values; }
private void checkAddress(AbstractAddress expected, AbstractAddress address) throws ShapeShiftException { if (!expected.getType().equals(address.getType()) || !expected.toString().equals(address.toString())) { String errorMsg = String.format("Address mismatch, expected %s but got %s.", expected, address); throw new ShapeShiftException(errorMsg); } }
public static String resolveLabel(final Context context, final AbstractAddress address) { String label = null; if (context != null) { final Uri uri = contentUri(context.getPackageName(), address.getType()) .buildUpon().appendPath(address.toString()).build(); final Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); if (cursor != null) { if (cursor.moveToFirst()) { label = cursor.getString(cursor.getColumnIndexOrThrow(AddressBookProvider.KEY_LABEL)); } cursor.close(); } } return label; }
public void onAddressSelected(AbstractAddress selectedAddress) { setAddress(selectedAddress, true); sendAmountType = selectedAddress.getType(); updateView(); }
public static boolean producesAddress(Script script, AbstractAddress address) { try { return BitAddress.from(address.getType(), script).equals(address); } catch (AddressMalformedException e) { return false; } } }
public static Uri contentUri(@Nonnull final String packageName, @Nonnull final AbstractAddress deposit) { return Uri.parse("content://" + packageName + '.' + DATABASE_TABLE).buildUpon() .appendPath(deposit.getType().getId()).appendPath(deposit.toString()).build(); }
/** * 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; } }
@Override public int update(final Uri uri, final ContentValues values, final String selection, final String[] selectionArgs) { final AbstractAddress address = getDepositAddress(uri); values.put(KEY_DEPOSIT_COIN_ID, address.getType().getId()); values.put(KEY_DEPOSIT_ADDRESS, address.toString()); final int count = helper.getWritableDatabase().update(DATABASE_TABLE, values, KEY_DEPOSIT_COIN_ID + "=? AND " + KEY_DEPOSIT_ADDRESS + "=?", new String[]{address.getType().getId(), address.toString()}); if (count > 0) getContext().getContentResolver().notifyChange(uri, null); return count; }
@Override public void markAddressAsUsed(AbstractAddress address) { checkArgument(address.getType().equals(type), "Wrong address type"); if (address instanceof BitAddress) { markAddressAsUsed((BitAddress)address); } else { throw new IllegalArgumentException("Wrong address class"); } }
@Override public Uri insert(final Uri uri, final ContentValues values) { final AbstractAddress address = getDepositAddress(uri); values.put(KEY_DEPOSIT_COIN_ID, address.getType().getId()); values.put(KEY_DEPOSIT_ADDRESS, address.toString()); long rowId = helper.getWritableDatabase().insertOrThrow(DATABASE_TABLE, null, values); final Uri rowUri = contentUri(getContext().getPackageName(), address).buildUpon() .appendPath(Long.toString(rowId)).build(); getContext().getContentResolver().notifyChange(rowUri, null); return rowUri; }
public ShapeShiftNormalTx(JSONObject data) throws ShapeShiftException { super(data); if (!isError) { try { deposit = CoinID.typeFromSymbol(data.getString("depositType")). newAddress(data.getString("deposit")); withdrawal = CoinID.typeFromSymbol(data.getString("withdrawalType")). newAddress(data.getString("withdrawal")); pair = ShapeShift.getPair(deposit.getType(), withdrawal.getType()); } catch (Exception e) { throw new ShapeShiftException("Could not parse object", e); } } else { deposit = null; withdrawal = null; pair = null; } } }
@Override public int delete(final Uri uri, final String selection, final String[] selectionArgs) { final AbstractAddress address = getDepositAddress(uri); final int count = helper.getWritableDatabase().delete(DATABASE_TABLE, KEY_DEPOSIT_COIN_ID + "=? AND " + KEY_DEPOSIT_ADDRESS + "=?", new String[]{address.getType().getId(), address.toString()}); if (count > 0) getContext().getContentResolver().notifyChange(uri, null); return count; }
public static BitAddress from(AbstractAddress address) throws AddressMalformedException { try { if (address instanceof BitAddress) { return (BitAddress) address; } else if (address instanceof Address) { return new BitAddress((Address) address); } else { return new BitAddress(address.getType(), address.toString()); } } catch (AddressFormatException e) { throw new AddressMalformedException(e); } }
private void setUri(CoinURI coinUri) throws CoinURIParseException { setAddress(coinUri.getAddress(), false); if (address == null) { // TODO when going to support the payment protocol, address could be null throw new CoinURIParseException("missing address"); } sendAmountType = address.getType(); sendAmount = coinUri.getAmount(); final String label = coinUri.getLabel(); }
@Override public boolean isAddressMine(AbstractAddress address) { return address != null && address.getType().equals(type) && (isP2SHAddress(address) ? isPayToScriptHashMine(getHash160(address)) : isPubKeyHashMine(getHash160(address))); }
private void startOrStopMarketRatePolling() { if (address != null && !account.isType(address)) { String pair = ShapeShift.getPair(account.getCoinType(), address.getType()); if (timer == null) { startPolling(pair); } else { pollTask.updatePair(pair); } } else if (timer != null) { stopPolling(); } }
@Test public void testNormalTx() throws JSONException, ShapeShiftException { JSONObject json = new JSONObject( "{" + "\"deposit\":\"18ETaXCYhJ8sxurh41vpKC3E6Tu7oJ94q8\"," + "\"depositType\":\"BTC\"," + "\"withdrawal\":\"DMHLQYG4j96V8cZX9WSuXxLs5RnZn6ibrV\"," + "\"withdrawalType\":\"DOGE\"" + "}"); ShapeShiftNormalTx normalTx = new ShapeShiftNormalTx(json); assertNotNull(normalTx); assertFalse(normalTx.isError); assertEquals("btc_doge", normalTx.pair); assertEquals("18ETaXCYhJ8sxurh41vpKC3E6Tu7oJ94q8", normalTx.deposit.toString()); assertEquals(BTC, normalTx.deposit.getType()); assertEquals("DMHLQYG4j96V8cZX9WSuXxLs5RnZn6ibrV", normalTx.withdrawal.toString()); assertEquals(DOGE, normalTx.withdrawal.getType()); }