Java Code Examples for net.bither.bitherj.utils.Utils#validBicoinAddress()

The following examples show how to use net.bither.bitherj.utils.Utils#validBicoinAddress() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScanQRCodeTransportActivity.java    From bither-android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean resultValid(String result) {
       boolean repeated = true;
	if (!Utils.compareString(result, lastResult)) {
           repeated = false;
		shake();
	}
	lastResult = result;
	QRCodeTransportPage page = QRCodeTransportPage
			.formatQrCodeTransport(result);
	if (page == null) {
           if (!repeated && Utils.validBicoinAddress(result) && Utils.compareString(tvTitle.getText()
                   .toString(), getString(R.string.scan_for_all_addresses_in_bither_cold_title))) {
               DropdownMessage.showDropdownMessage(this,
                       R.string.add_address_watch_only_scanned_address_warning);
           }
           return false;
       }
       if (page.getCurrentPage() == pages.size()) {
           return true;
       }
	return false;
}
 
Example 2
Source File: GenerateUnsignedTxActivity.java    From bither-android with Apache License 2.0 6 votes vote down vote up
private void processIntent() {
    isDonate = false;
    Intent intent = getIntent();
    if (intent.hasExtra(SelectAddressToSendActivity.INTENT_EXTRA_ADDRESS)) {
        String address = intent.getExtras().getString(SelectAddressToSendActivity
                .INTENT_EXTRA_ADDRESS);
        if (Utils.validBicoinAddress(address)) {
            if (Utils.compareString(address, BitherjSettings.DONATE_ADDRESS)) {
                isDonate = true;
            }
            etAddress.setText(address);
            long btc = intent.getExtras().getLong(SelectAddressToSendActivity
                    .INTENT_EXTRA_AMOUNT, 0);
            if (btc > 0) {
                amountCalculatorLink.setBtcAmount(btc);
            }
            validateValues();
        }
    }
}
 
Example 3
Source File: GenerateUnsignedTxActivity.java    From bither-android with Apache License 2.0 6 votes vote down vote up
private void validateValues() {
    boolean isValidAmounts = false;

    final long amount = amountCalculatorLink.getAmount();

    if (amount > 0) {
        isValidAmounts = true;
    }
    String address = etAddress.getText().toString().trim();
    boolean isValidAddress = Utils.validBicoinAddress(address);
    if (isValidAddress && Utils.validBech32Address(address)) {
        isValidAddress = false;
        DropdownMessage.showDropdownMessage(this, R.string.cold_no_support_bc1_segwit_address);
        etAddress.setText("");
    }
    btnSend.setEnabled(isValidAddress && isValidAmounts);
}
 
Example 4
Source File: HDAccountMonitoredSendActivity.java    From bither-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void sendClicked() {
    final long btc = amountCalculatorLink.getAmount();
    if (btc > 0) {
        btcAmount = btc;
        tx = null;
        String address = etAddress.getText().toString().trim();
        if (Utils.validBicoinAddress(address)) {
            toAddress = address;
            if (!dp.isShowing()) {
                dp.show();
            }
            new Thread() {
                @Override
                public void run() {
                    send();
                }
            }.start();
        } else {
            DropdownMessage.showDropdownMessage(HDAccountMonitoredSendActivity.this, R.string
                    .send_failed);
        }
    }
}
 
Example 5
Source File: AddAddressListItem.java    From bither-android with Apache License 2.0 6 votes vote down vote up
private void checkAddress() {
    if (Utils.validBicoinAddress(etAddress.getText().toString())) {
        ibtnDelete.setVisibility(View.VISIBLE);
        ibtnScan.setVisibility(View.GONE);
        etAddress.setEnabled(false);
        ViewParent parent = getParent();
        if (parent != null && parent instanceof ViewGroup) {
            ViewGroup group = (ViewGroup) parent;
            View lastChild = group.getChildAt(group.getChildCount() - 1);
            if (lastChild == this) {
                group.addView(new AddAddressListItem(activity, listener),
                        ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT);
            }
        }
        if (listener != null) {
            listener.onAddressChanged();
        }
    } else {
        ibtnDelete.setVisibility(View.GONE);
        ibtnScan.setVisibility(View.VISIBLE);
        etAddress.setEnabled(true);
    }
}
 
Example 6
Source File: SendHDMBitcoinPanel.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
private void validateValues() {
    boolean isValidAmounts = false;

    String amtString = tfAmt.getText().trim();

    if (Utils.isNubmer(amtString)) {
        long btc = GenericUtils.toNanoCoins(amtString, 0).longValue();
        if (btc > 0) {
            isValidAmounts = true;
        } else {
        }
    }
    boolean isValidAddress = Utils.validBicoinAddress(tfAddress.getText().trim());
    SecureCharSequence password = new SecureCharSequence(currentPassword.getPassword());
    boolean isValidPassword = Utils.validPassword(password) && password.length() >= BitherSetting.PASSWORD_LENGTH_MIN &&
            password.length() <= BitherSetting.PASSWORD_LENGTH_MAX;
    password.wipe();
    setOkEnabled(isValidAddress && isValidAmounts && isValidPassword);
}
 
Example 7
Source File: SendBitcoinPanel.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
private void validateValues() {
    boolean isValidAmounts = false;

    String amtString = tfAmt.getText().trim();

    if (Utils.isNubmer(amtString)) {
        long btc = GenericUtils.toNanoCoins(amtString, 0).longValue();
        if (btc > 0) {
            isValidAmounts = true;
        } else {
        }
    }
    boolean isValidAddress = Utils.validBicoinAddress(tfAddress.getText().trim());
    SecureCharSequence password = new SecureCharSequence(currentPassword.getPassword());
    boolean isValidPassword = Utils.validPassword(password) && password.length() >= BitherSetting.PASSWORD_LENGTH_MIN &&
            password.length() <= BitherSetting.PASSWORD_LENGTH_MAX;
    password.wipe();
    setOkEnabled(isValidAddress && isValidAmounts && isValidPassword);
}
 
Example 8
Source File: BCCAssetsHDAccountMonitoredActivity.java    From bither-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void validateValues() {
    boolean isValidAmounts = false;
    btcAmount = getAmount(outs);
    if (btcAmount > 0) {
        isValidAmounts = true;
    }
    toAddress = etAddress.getText().toString().trim();
    boolean isValidAddress = Utils.validBicoinAddress(toAddress);
    boolean isValidPassword = true;
    if (etPassword.getVisibility() == View.VISIBLE) {
        SecureCharSequence password = new SecureCharSequence(etPassword.getText());
        isValidPassword = Utils.validPassword(password) && password.length() >= 6 &&
                password.length() <= getResources().getInteger(R.integer.password_length_max);
        password.wipe();
    }
    btnSend.setEnabled(isValidAddress && isValidAmounts && isValidPassword);
}
 
Example 9
Source File: UnSignTxPanel.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
private void onOK() {
    bitcoinAddress = tfAddress.getText().trim();
    if (Utils.validBicoinAddress(bitcoinAddress)) {
        if (Utils.compareString(bitcoinAddress, changeAddress)) {
            new MessageDialog(LocaliserUtils.getString("select_change_address_change_to_same_warn")).showMsg();
            return;
        }
        String amtString = tfAmt.getText().trim();
        long btc = GenericUtils.toNanoCoins(amtString, 0).longValue();
        try {
            CompleteTransactionRunnable completeTransactionRunnable = new CompleteTransactionRunnable(
                    Bither.getActionAddress(), btc, bitcoinAddress, changeAddress, null);
            completeTransactionRunnable.setRunnableListener(completeTransactionListener);
            new Thread(completeTransactionRunnable).start();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
 
Example 10
Source File: UnSignTxPanel.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
private void onOK() {
    bitcoinAddress = tfAddress.getText().trim();
    if (Utils.validBicoinAddress(bitcoinAddress)) {
        if (Utils.compareString(bitcoinAddress, changeAddress)) {
            new MessageDialog(LocaliserUtils.getString("select_change_address_change_to_same_warn")).showMsg();
            return;
        }
        String amtString = tfAmt.getText().trim();
        long btc = GenericUtils.toNanoCoins(amtString, 0).longValue();
        try {
            CompleteTransactionRunnable completeTransactionRunnable = new CompleteTransactionRunnable(
                    Bither.getActionAddress(), btc, bitcoinAddress, changeAddress, null);
            completeTransactionRunnable.setRunnableListener(completeTransactionListener);
            new Thread(completeTransactionRunnable).start();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
 
Example 11
Source File: HDAccountSendActivity.java    From bither-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void sendClicked() {
    final long btc = amountCalculatorLink.getAmount();
    if (btc > 0) {
        btcAmount = btc;
        tx = null;
        String address = etAddress.getText().toString().trim();
        if (Utils.validBicoinAddress(address)) {
            toAddress = address;
            if (!dp.isShowing()) {
                dp.show();
            }
            new Thread() {
                @Override
                public void run() {
                    send();
                }
            }.start();
        } else {
            DropdownMessage.showDropdownMessage(HDAccountSendActivity.this, R.string
                    .send_failed);
        }
    }
}
 
Example 12
Source File: SendBitcoinPanel.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
protected void onSend() {
    bitcoinAddress = tfAddress.getText().trim();
    if (Utils.validBicoinAddress(bitcoinAddress)) {
        if (Utils.compareString(bitcoinAddress, changeAddress)) {
            new MessageDialog(LocaliserUtils.getString("select_change_address_change_to_same_warn")).showMsg();
            return;
        }
        String amtString = tfAmt.getText().trim();
        long btc = GenericUtils.toNanoCoins(amtString, 0).longValue();
        try {
            SecureCharSequence secureCharSequence = new SecureCharSequence(currentPassword.getPassword());
            CompleteTransactionRunnable completeTransactionRunnable = new CompleteTransactionRunnable(
                    Bither.getActionAddress(), btc, bitcoinAddress, changeAddress, secureCharSequence);
            completeTransactionRunnable.setRunnableListener(completeTransactionListener);
            new Thread(completeTransactionRunnable).start();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
 
Example 13
Source File: QRCodeTxTransport.java    From bitherj with Apache License 2.0 5 votes vote down vote up
private static QRCodeTxTransport changeFormatQRCodeTransport(String str) {
    try {
        String[] strArray = QRCodeUtil.splitString(str);
        QRCodeTxTransport qrCodeTransport = new QRCodeTxTransport();

        String address = Base58.hexToBase58WithAddress(strArray[0]);
        if (!Utils.validBicoinAddress(address)) {
            return null;
        }
        qrCodeTransport.setMyAddress(address);
        String changeAddress = Base58.hexToBase58WithAddress(strArray[1]);
        if (!Utils.validBicoinAddress(changeAddress)) {
            return null;
        }
        qrCodeTransport.setChangeAddress(changeAddress);
        qrCodeTransport.setChangeAmt(Long.parseLong(strArray[2], 16));
        qrCodeTransport.setFee(Long.parseLong(strArray[3], 16));
        String toAddress = Base58.hexToBase58WithAddress(strArray[4]);
        if (!Utils.validBicoinAddress(toAddress)) {
            return null;
        }
        qrCodeTransport.setToAddress(toAddress);
        qrCodeTransport.setTo(Long.parseLong(strArray[5], 16));
        List<String> hashList = new ArrayList<String>();
        for (int i = 6;
             i < strArray.length;
             i++) {
            String text = strArray[i];
            if (!Utils.isEmpty(text)) {
                hashList.add(text);
            }
        }
        qrCodeTransport.setHashList(hashList);
        return qrCodeTransport;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 14
Source File: QRCodeTxTransport.java    From bitherj with Apache License 2.0 5 votes vote down vote up
private static QRCodeTxTransport noChangeFormatQRCodeTransport(String str) {
    try {
        String[] strArray = QRCodeUtil.splitString(str);
        if (Utils.validBicoinAddress(strArray[0])) {
            return oldFormatQRCodeTransport(str);
        }
        QRCodeTxTransport qrCodeTransport = new QRCodeTxTransport();
        String address = Base58.hexToBase58WithAddress(strArray[0]);

        if (!Utils.validBicoinAddress(address)) {
            return null;
        }
        qrCodeTransport.setMyAddress(address);
        qrCodeTransport.setFee(Long.parseLong(strArray[1], 16));
        qrCodeTransport.setToAddress(Base58.hexToBase58WithAddress(strArray[2]));
        qrCodeTransport.setTo(Long.parseLong(strArray[3], 16));
        List<String> hashList = new ArrayList<String>();
        for (int i = 4;
             i < strArray.length;
             i++) {
            String text = strArray[i];
            if (!Utils.isEmpty(text)) {
                hashList.add(text);
            }
        }
        qrCodeTransport.setHashList(hashList);
        return qrCodeTransport;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 15
Source File: SendActivity.java    From bither-android with Apache License 2.0 5 votes vote down vote up
protected void sendClicked() {
    final long btc = amountCalculatorLink.getAmount();
    if (btc > 0) {
        String address = etAddress.getText().toString().trim();
        if (Utils.validBicoinAddress(address)) {
            if (Utils.compareString(address,
                    dialogSelectChangeAddress.getChangeAddress().getAddress())) {
                DropdownMessage.showDropdownMessage(SendActivity.this,
                        R.string.select_change_address_change_to_same_warn);
                return;
            }
            try {
                CompleteTransactionRunnable completeRunnable = new
                        CompleteTransactionRunnable(addressPosition,
                        amountCalculatorLink.getAmount(), address
                        , dialogSelectChangeAddress.getChangeAddress().getAddress
                        (), new SecureCharSequence(etPassword.getText()));
                completeRunnable.setHandler(completeTransactionHandler);
                Thread thread = new Thread(completeRunnable);
                dp.setThread(thread);
                if (!dp.isShowing()) {
                    dp.show();
                }
                thread.start();
            } catch (Exception e) {
                e.printStackTrace();
                DropdownMessage.showDropdownMessage(SendActivity.this,
                        R.string.send_failed);
            }
        } else {
            DropdownMessage.showDropdownMessage(SendActivity.this, R.string.send_failed);
        }
    }
}
 
Example 16
Source File: QRCodeTxTransport.java    From bitherj with Apache License 2.0 5 votes vote down vote up
private static QRCodeTxTransport noChangeFormatDesktopHDMQRCodeTransport(String str) {
    try {
        String[] strArray = QRCodeUtil.splitString(str);
        if (Utils.validBicoinAddress(strArray[0])) {
            return oldFormatQRCodeTransport(str);
        }
        QRCodeTxTransport qrCodeTransport = new QRCodeTxTransport();
        String address = Base58.hexToBase58WithAddress(strArray[0]);

        if (!Utils.validBicoinAddress(address)) {
            return null;
        }
        qrCodeTransport.setMyAddress(address);
        qrCodeTransport.setFee(Long.parseLong(strArray[1], 16));
        qrCodeTransport.setToAddress(Base58.hexToBase58WithAddress(strArray[2]));
        qrCodeTransport.setTo(Long.parseLong(strArray[3], 16));
        List<String> hashList = new ArrayList<String>();
        List<AbstractHD.PathTypeIndex> pathTypeIndexList = new ArrayList<AbstractHD.PathTypeIndex>();
        for (int i = 4;
             i < strArray.length;
             i++) {
            String text = strArray[i];
            if (!Utils.isEmpty(text)) {
                String[] hashPathTypeIndex = text.split(QRCodeUtil.QR_CODE_SECONDARY_SPLIT_ESCAPE);
                AbstractHD.PathTypeIndex pathTypeIndex = new AbstractHD.PathTypeIndex();
                pathTypeIndex.pathType = AbstractHD.getTernalRootType(Integer.valueOf(hashPathTypeIndex[0]));
                pathTypeIndex.index = Integer.valueOf(hashPathTypeIndex[1]);
                pathTypeIndexList.add(pathTypeIndex);
                hashList.add(hashPathTypeIndex[2]);
            }
        }
        qrCodeTransport.setHashList(hashList);
        qrCodeTransport.setPathTypeIndexes(pathTypeIndexList);
        return qrCodeTransport;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 17
Source File: GenerateUnsignedTxActivity.java    From bither-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    final long btc = amountCalculatorLink.getAmount();
    if (btc > 0) {
        if (Utils.validBicoinAddress(etAddress.getText().toString().trim())) {
            if (Utils.compareString(etAddress.getText().toString().trim(),
                    dialogSelectChangeAddress.getChangeAddress().getAddress())) {
                DropdownMessage.showDropdownMessage(GenerateUnsignedTxActivity.this,
                        R.string.select_change_address_change_to_same_warn);
                return;
            }
            try {
                CompleteTransactionRunnable completeRunnable = new
                        CompleteTransactionRunnable(addressPosition, amountCalculatorLink
                        .getAmount(), etAddress.getText().toString().trim(),
                        dialogSelectChangeAddress.getChangeAddress().getAddress(), null);
                completeRunnable.setHandler(completeTransactionHandler);
                Thread thread = new Thread(completeRunnable);
                dp.setThread(thread);
                if (!dp.isShowing()) {
                    dp.show();
                }
                thread.start();
            } catch (Exception e) {
                e.printStackTrace();
                DropdownMessage.showDropdownMessage(GenerateUnsignedTxActivity.this,
                        R.string.send_failed);
            }
        } else {
            DropdownMessage.showDropdownMessage(GenerateUnsignedTxActivity.this,
                    R.string.send_failed);
        }
    }
}
 
Example 18
Source File: HDAccountSendPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
@Override
protected void onSend() {
    String amtString = tfAmt.getText().trim();
    long btc = GenericUtils.toNanoCoins(amtString, 0).longValue();

    if (btc > 0) {
        btcAmount = btc;
        tx = null;
        if (Utils.validBicoinAddress(tfAddress.getText().toString().trim())) {
            toAddress = tfAddress.getText().toString().trim();

            new Thread() {
                @Override
                public void run() {
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            dp.pack();
                            dp.setVisible(true);
                        }
                    });
                    send();
                }
            }.start();
        } else {
            new MessageDialog(LocaliserUtils.getString("send_failed")).showMsg();

        }
    }
}
 
Example 19
Source File: SendHDMBitcoinPanel.java    From bither-desktop-java with Apache License 2.0 4 votes vote down vote up
private void onOK() {
    spinner.setVisible(true);
    bitcoinAddress = tfAddress.getText().trim();
    String amtString = tfAmt.getText().trim();
    long btc = GenericUtils.toNanoCoins(amtString, 0).longValue();

    if (btc > 0) {
        if (Utils.validBicoinAddress(bitcoinAddress)) {
            if (Utils.compareString(bitcoinAddress,
                    changeAddress)) {
                new MessageDialog(LocaliserUtils.getString("select_change_address_change_to_same_warn")).showMsg();
                return;
            }
            try {
                CompleteTransactionRunnable completeRunnable;
                if (!isInRecovery) {
                    completeRunnable = new CompleteTransactionRunnable(hdmAddress,
                            btc,
                            bitcoinAddress,
                            changeAddress,
                            new SecureCharSequence(currentPassword.getPassword()),
                            signWithCold ? coldSignatureFetcher : remoteSignatureFetcher);
                } else {
                    completeRunnable = new CompleteTransactionRunnable(hdmAddress,
                            btc,
                            bitcoinAddress,
                            changeAddress,
                            new SecureCharSequence(currentPassword.getPassword()),
                            coldSignatureFetcher, remoteSignatureFetcher);
                }
                completeRunnable.setRunnableListener(completeTransactionListener);
                Thread thread = new Thread(completeRunnable);
                thread.start();
            } catch (Exception e) {
                e.printStackTrace();
                new MessageDialog(LocaliserUtils.getString("send_failed")).showMsg();
            }
        } else {
            new MessageDialog(LocaliserUtils.getString("send_failed")).showMsg();
        }
    }
}
 
Example 20
Source File: QRCodeTxTransport.java    From bitherj with Apache License 2.0 4 votes vote down vote up
private static QRCodeTxTransport changeFormatQRCodeTransportOfDesktopHDM(String str) {
    try {
        String[] strArray = QRCodeUtil.splitString(str);
        QRCodeTxTransport qrCodeTransport = new QRCodeTxTransport();

        String address = Base58.hexToBase58WithAddress(strArray[0]);
        if (!Utils.validBicoinAddress(address)) {
            return null;
        }
        qrCodeTransport.setMyAddress(address);
        String changeAddress = Base58.hexToBase58WithAddress(strArray[1]);
        if (!Utils.validBicoinAddress(changeAddress)) {
            return null;
        }
        qrCodeTransport.setChangeAddress(changeAddress);
        qrCodeTransport.setChangeAmt(Long.parseLong(strArray[2], 16));
        qrCodeTransport.setFee(Long.parseLong(strArray[3], 16));
        String toAddress = Base58.hexToBase58WithAddress(strArray[4]);
        if (!Utils.validBicoinAddress(toAddress)) {
            return null;
        }
        qrCodeTransport.setToAddress(toAddress);
        qrCodeTransport.setTo(Long.parseLong(strArray[5], 16));
        List<AbstractHD.PathTypeIndex> pathTypeIndexList = new ArrayList<AbstractHD.PathTypeIndex>();
        List<String> hashList = new ArrayList<String>();
        for (int i = 6;
             i < strArray.length;
             i++) {
            String text = strArray[i];

            if (!Utils.isEmpty(text)) {
                String[] hashPathTypeIndex = text.split(QRCodeUtil.QR_CODE_SECONDARY_SPLIT_ESCAPE);
                AbstractHD.PathTypeIndex pathTypeIndex = new AbstractHD.PathTypeIndex();
                pathTypeIndex.pathType = AbstractHD.getTernalRootType(Integer.valueOf(hashPathTypeIndex[0]));
                pathTypeIndex.index = Integer.valueOf(hashPathTypeIndex[1]);
                pathTypeIndexList.add(pathTypeIndex);
                hashList.add(hashPathTypeIndex[2]);
            }
        }
        qrCodeTransport.setPathTypeIndexes(pathTypeIndexList);
        qrCodeTransport.setHashList(hashList);
        return qrCodeTransport;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}