private String getAccountInfo(AbstractAddress address) { StringBuilder builder = new StringBuilder(); builder.append(getBaseUrl()).append(GET_REQUEST).append(GET_ACCOUNT) .append("&account=").append(address.toString()); return builder.toString(); }
public URI getAddressRequestUriResponse(AbstractAddress address) { return getAddressRequestUriResponse(address.toString()); }
public static List<CoinType> getPossibleTypes(AbstractAddress address) throws AddressMalformedException { return getPossibleTypes(address.toString()); }
public static boolean hasMultipleTypes(AbstractAddress address) { return hasMultipleTypes(address.toString()); }
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; }
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; }
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 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(); }
@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 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; }
@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; }
@Override public boolean onActionItemClicked(ActionMode mode, MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.action_change_address_type: if (listener != null) listener.showPayToDialog(getAddress().toString()); mode.finish(); return true; } return super.onActionItemClicked(mode, menuItem); } };
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); } }
/** * Time Remaining on Fixed Amount Transaction * * When a transaction is created with a fixed amount requested there is a 10 minute window for * the deposit. After the 10 minute window if the deposit has not been received the transaction * expires and a new one must be created. This api call returns how many seconds are left before * the transaction expires. */ public ShapeShiftTime getTime(AbstractAddress address) throws ShapeShiftException, IOException { String apiUrl = getApiUrl(String.format(TIME_REMAINING_API, address.toString())); Request request = new Request.Builder().url(apiUrl).build(); return new ShapeShiftTime(getMakeApiCall(request)); }
@Test public void watchingAddresses() { List<AbstractAddress> watchingAddresses = pocket.getAddressesToWatch(); assertEquals(40, watchingAddresses.size()); // 20 + 20 lookahead size for (int i = 0; i < addresses.size(); i++) { assertEquals(addresses.get(i), watchingAddresses.get(i).toString()); } }
/** * Status of deposit to address * * This returns the status of the most recent deposit transaction to the address. */ public ShapeShiftTxStatus getTxStatus(AbstractAddress address) throws ShapeShiftException, IOException { String apiUrl = getApiUrl(String.format(TX_STATUS_API, address.toString())); Request request = new Request.Builder().url(apiUrl).build(); ShapeShiftTxStatus reply = new ShapeShiftTxStatus(getMakeApiCall(request)); if (!reply.isError && reply.address != null) checkAddress(address, reply.address); return new ShapeShiftTxStatus(reply, address); }
@Override public Cursor query(final Uri uri, final String[] projection, final String selection, final String[] selectionArgs, final String sortOrder) { final SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(DATABASE_TABLE); final List<String> pathSegments = uri.getPathSegments(); if (pathSegments.size() > 2) throw new IllegalArgumentException(uri.toString()); if (pathSegments.size() == 2) { final AbstractAddress address = getDepositAddress(uri); qb.appendWhere(KEY_DEPOSIT_COIN_ID + "="); qb.appendWhereEscapeString(address.getType().getId()); qb.appendWhere(" AND " + KEY_DEPOSIT_ADDRESS + "="); qb.appendWhereEscapeString(address.toString()); } final Cursor cursor = qb.query(helper.getReadableDatabase(), projection, selection, selectionArgs, null, null, sortOrder); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
@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()); }
@Test public void brokenURIs() throws CoinURIParseException { // Check we can parse the incorrectly formatted URIs produced by blockchain.info and its iPhone app. String str = "bitcoin://1KzTSfqjF2iKCduwz59nv2uqh1W2JsTxZH?amount=0.01000000"; CoinURI uri = new CoinURI(str); assertEquals("1KzTSfqjF2iKCduwz59nv2uqh1W2JsTxZH", uri.getAddress().toString()); assertEquals(BTC.value(Coin.CENT), uri.getAmount()); }
@Test public void testTxStatus2() throws JSONException, ShapeShiftException { JSONObject json = new JSONObject( "{" + "status: \"received\"," + "address: \"1NDQPAGamGePkSZXW2CYBzXJEefB7N4bTN\"," + "incomingCoin: 0.00297537," + "incomingType: \"BTC\"" + "}"); ShapeShiftTxStatus txStatus = new ShapeShiftTxStatus(json); assertNotNull(txStatus); assertFalse(txStatus.isError); assertEquals(ShapeShiftTxStatus.Status.RECEIVED, txStatus.status); assertEquals("1NDQPAGamGePkSZXW2CYBzXJEefB7N4bTN", txStatus.address.toString()); assertEquals(BTC, txStatus.address.getType()); assertNull(txStatus.withdraw); assertEquals(BTC.value("0.00297537"), txStatus.incomingValue); assertNull(txStatus.outgoingValue); assertNull(txStatus.transactionId); }