private List<CoinType> getCoinsTypes(Bundle args) { ArrayList<String> coinIds = args.getStringArrayList(Constants.ARG_MULTIPLE_COIN_IDS); if (coinIds != null) { List<CoinType> coinTypes = new ArrayList<CoinType>(); for (String id : coinIds) { coinTypes.add(CoinID.typeFromId(id)); } return coinTypes; } else { return Constants.DEFAULT_COINS; } }
public static CoinType[] parsePair(String pair) { String[] pairs = pair.split("_"); checkState(pairs.length == 2); return new CoinType[]{CoinID.typeFromSymbol(pairs[0]), CoinID.typeFromSymbol(pairs[1])}; } }
private TypedKey getFromWifKey() { ImmutableList.Builder<CoinType> builder = ImmutableList.builder(); for (CoinType type : CoinID.getSupportedCoins()) { if (version == type.getDumpedPrivateKeyHeader()) { builder.add(type); } } final ECKey key = compressed ? ECKey.fromPrivate(content) : ECKey.fromPrivate(content).decompress(); return new TypedKey(builder.build(), key); }
public ShapeShiftCoins(JSONObject data) throws ShapeShiftException { super(data); if (!isError) { try { ImmutableList.Builder<ShapeShiftCoin> listBuilder = ImmutableList.builder(); Iterator iter = data.keys(); while (iter.hasNext()) { String k = (String) iter.next(); listBuilder.add(new ShapeShiftCoin(data.getJSONObject(k))); } coins = listBuilder.build(); ImmutableList.Builder<CoinType> typesBuilder = ImmutableList.builder(); for (ShapeShiftCoin coin : coins) { if (coin.isAvailable && CoinID.isSymbolSupported(coin.symbol)) { typesBuilder.add(CoinID.typeFromSymbol(coin.symbol)); } } availableCoinTypes = typesBuilder.build(); } catch (Exception e) { throw new ShapeShiftException("Could not parse object", e); } } else { coins = null; availableCoinTypes = null; } } }
if (uri.getScheme() != null) { try { possibleTypes = CoinID.fromUriScheme(uri.getScheme()); uriScheme = possibleTypes.get(0).getUriScheme(); } catch (IllegalArgumentException e) {
private AbstractAddress getDepositAddress(Uri uri) { AbstractAddress address; final List<String> pathSegments = getPathSegments(uri); try { address = CoinID.typeFromId(pathSegments.get(0)).newAddress(pathSegments.get(1)); } catch (AddressMalformedException e) { throw new IllegalArgumentException(e); } return address; }
public static ExchangeRate getExchangeRate(@Nonnull final Cursor cursor) { final String codeId = getCurrencyCodeId(cursor); final CoinType type = CoinID.typeFromSymbol(cursor.getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_COIN_CODE))); final Value rateCoin = Value.valueOf(type, cursor.getLong(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_COIN))); final String fiatCode = cursor.getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_FIAT_CODE)); final Value rateFiat = FiatValue.valueOf(fiatCode, cursor.getLong(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_FIAT))); final String source = cursor.getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_SOURCE)); ExchangeRateBase rate = new ExchangeRateBase(rateCoin, rateFiat); return new ExchangeRate(rate, codeId, source); }
private TypedKey getFromMiniKey() { final ECKey key = ECKey.fromPrivate(content).decompress(); return new TypedKey(CoinID.getSupportedCoins(), key); } }
@Override public void bindView(final View view, final Context context, final Cursor cursor) { final String label = cursor.getString(cursor.getColumnIndexOrThrow(AddressBookProvider.KEY_LABEL)); final String coinId = cursor.getString(cursor.getColumnIndexOrThrow(AddressBookProvider.KEY_COIN_ID)); final String addressStr = cursor.getString(cursor.getColumnIndexOrThrow(AddressBookProvider.KEY_ADDRESS)); CoinType type = CoinID.typeFromId(coinId); final ViewGroup viewGroup = (ViewGroup) view; final TextView labelView = (TextView) viewGroup.findViewById(R.id.address_book_row_label); labelView.setText(label); final TextView addressView = (TextView) viewGroup.findViewById(R.id.address_book_row_address); try { addressView.setText(GenericUtils.addressSplitToGroupsMultiline(type.newAddress(addressStr))); } catch (AddressMalformedException e) { ACRA.getErrorReporter().handleSilentException(e); addressView.setText(addressStr); } }
public ShapeShiftRate(JSONObject data) throws ShapeShiftException { super(data); if (!isError) { try { String[] pairs = pair.split("_"); checkState(pairs.length == 2); CoinType typeFrom = CoinID.typeFromSymbol(pairs[0]); CoinType typeTo = CoinID.typeFromSymbol(pairs[1]); rate = new ShapeShiftExchangeRate(typeFrom, typeTo, data.getString("rate"), data.optString("minerFee", null)); } catch (Exception e) { throw new ShapeShiftException("Could not parse object", e); } } else { rate = null; } } }
/** * Tries to parse the addressStr as a Bitcoin style address and find potential compatible coin types * @param addressStr possible bitcoin type address * @param builder for the types list */ private static void tryBitcoinFamilyAddresses(final String addressStr, ImmutableList.Builder<CoinType> builder) { VersionedChecksummedBytes parsed; try { parsed = new VersionedChecksummedBytes(addressStr) { }; } catch (AddressFormatException e) { return; } int version = parsed.getVersion(); for (CoinType type : CoinID.getSupportedCoins()) { if (type.getAcceptableAddressCodes() == null) continue; for (int addressCode : type.getAcceptableAddressCodes()) { if (addressCode == version) { builder.add(type); break; } } } }
@Override public void onCoinSelection(Bundle args) { ArrayList<String> ids = args.getStringArrayList(Constants.ARG_MULTIPLE_COIN_IDS); // For new we add only one coin at a time selectedCoin = CoinID.typeFromId(ids.get(0)); if (wallet.isAccountExists(selectedCoin)) { new AlertDialog.Builder(this) .setTitle(getString(R.string.coin_already_added_title, selectedCoin.getName())) .setMessage(R.string.coin_already_added) .setPositiveButton(R.string.button_ok, null) .create().show(); return; } showAddCoinDialog(); }
@Nullable public static String getCurrencyName(String code) { String currencyName = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { try { Currency currency = Currency.getInstance(code); currencyName = currency.getDisplayName(Locale.getDefault()); } catch (final IllegalArgumentException x) { /* ignore */ } } else { currencyName = Currencies.CURRENCY_NAMES.get(code); } // Try cryptocurrency codes if (currencyName == null) { try { CoinType cryptoCurrency = CoinID.typeFromSymbol(code); currencyName = cryptoCurrency.getName(); } catch (final IllegalArgumentException x) { /* ignore */ } } return currencyName; } }
public TypedKey decryptBip38(String passphrase) throws BadPassphraseException { String normalizedPassphrase = Normalizer.normalize(passphrase, Normalizer.Form.NFC); ECKey key = ecMultiply ? decryptBip38EC(normalizedPassphrase) : decryptBip38NoEC(normalizedPassphrase); String address = null; for (CoinType type : CoinID.getSupportedCoins()) { String possibleAddress = key.toAddress(type).toString(); Sha256Hash hash = Sha256Hash.createDouble(possibleAddress.getBytes(Charsets.US_ASCII)); byte[] actualAddressHash = Arrays.copyOfRange(hash.getBytes(), 0, 4); if (Arrays.equals(actualAddressHash, addressHash)) { address = possibleAddress; } } if (address == null) { throw new BadPassphraseException(); } try { return new TypedKey(GenericUtils.getPossibleTypes(address), key); } catch (AddressMalformedException e) { throw new RuntimeException(e); // Should not happen } }
public static ExchangeEntry getExchangeEntry(@Nonnull final Cursor cursor) { final int status = getStatus(cursor); CoinType depositType = CoinID.typeFromId(cursor.getString(cursor.getColumnIndexOrThrow(KEY_DEPOSIT_COIN_ID))); AbstractAddress depositAddress; try { depositAddress = depositType.newAddress(cursor.getString(cursor.getColumnIndexOrThrow(KEY_DEPOSIT_ADDRESS))); } catch (AddressMalformedException e) { // Should never happen throw new RuntimeException(e); } Value depositAmount = depositType.value(cursor.getLong(cursor.getColumnIndexOrThrow(KEY_DEPOSIT_AMOUNT_UNIT))); String depositTxId = cursor.getString(cursor.getColumnIndexOrThrow(KEY_DEPOSIT_TXID)); AbstractAddress withdrawAddress; Value withdrawAmount; String withdrawTxId; try { CoinType withdrawType = CoinID.typeFromId(cursor.getString(cursor.getColumnIndexOrThrow(KEY_WITHDRAW_COIN_ID))); withdrawAddress = withdrawType.newAddress(cursor.getString(cursor.getColumnIndexOrThrow(KEY_WITHDRAW_ADDRESS))); withdrawAmount = withdrawType.value(cursor.getLong(cursor.getColumnIndexOrThrow(KEY_WITHDRAW_AMOUNT_UNIT))); withdrawTxId = cursor.getString(cursor.getColumnIndexOrThrow(KEY_WITHDRAW_TXID)); } catch (Exception e) { withdrawAddress = null; withdrawAmount = null; withdrawTxId = null; } return new ExchangeEntry(status, depositAddress, depositAmount, depositTxId, withdrawAddress, withdrawAmount, withdrawTxId); }
CoinType type = isLocalToCrypto ? null : CoinID.typeFromSymbol(fromSymbol); for (final Iterator<String> i = json.keys(); i.hasNext(); ) { final String toSymbol = i.next(); if (rateStr != null) { try { if (isLocalToCrypto) type = CoinID.typeFromSymbol(toSymbol); String localSymbol = isLocalToCrypto ? fromSymbol : toSymbol; final Value rateCoin = type.oneCoin();
private void parseWif(String key) throws KeyFormatException { byte[] keyBytes = parseBase58(key); // Check if compatible boolean isCompatible = false; for (CoinType type : CoinID.getSupportedCoins()) { if (version == type.getDumpedPrivateKeyHeader()) { isCompatible = true; } } if (!isCompatible) { clearDataAndThrow(keyBytes, "No coin with private key version: " + version); } if (keyBytes.length == 33 && keyBytes[32] == 1) { compressed = true; content = Arrays.copyOf(keyBytes, 32); // Chop off the additional marker byte. clearData(keyBytes); } else if (keyBytes.length == 32) { compressed = false; content = keyBytes; } else { clearDataAndThrow(keyBytes, "Wrong number of bytes for a private key, not 32 or 33"); } }
private static CoinType getType(Protos.WalletPocket proto) throws UnreadableWalletException { try { return CoinID.typeFromId(proto.getNetworkIdentifier()); } catch (IllegalArgumentException e) { throw new UnreadableWalletException("Unknown network parameters ID " + proto.getNetworkIdentifier()); } }
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 Dialog onCreateDialog(final Bundle savedInstanceState) { final Bundle args = getArguments(); final CoinType type = CoinID.typeFromId(args.getString(KEY_COIN_ID)); final AbstractAddress address = (AbstractAddress) args.getSerializable(KEY_ADDRESS); final String suggestedAddressLabel = args.getString(KEY_SUGGESTED_ADDRESS_LABEL);