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

The following examples show how to use net.bither.bitherj.utils.Utils#isEmpty() . 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: QRCodeTxTransport.java    From bitherj with Apache License 2.0 6 votes vote down vote up
private static QRCodeTxTransport oldFromSendRequestWithUnsignedTransaction(Tx tx,
                                                                           String addressCannotParsed) {
    QRCodeTxTransport qrCodeTransport = new QRCodeTxTransport();
    qrCodeTransport.setMyAddress(tx.getFromAddress());
    String toAddress = tx.getFirstOutAddress();
    if (Utils.isEmpty(toAddress)) {
        toAddress = addressCannotParsed;
    }
    qrCodeTransport.setToAddress(toAddress);
    qrCodeTransport.setTo(tx.amountSentToAddress(toAddress));
    qrCodeTransport.setFee(tx.getFee());
    List<String> hashList = new ArrayList<String>();
    for (byte[] h : tx.getUnsignedInHashes()) {
        hashList.add(Utils.bytesToHexString(h));
    }
    qrCodeTransport.setHashList(hashList);
    return qrCodeTransport;
}
 
Example 2
Source File: SelectTransportQRCodePanel.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
public void handleResult(String result) {
    if (Utils.isEmpty(result)) {
        setMsg(LocaliserUtils.getString("no_format_qr_code"));
    } else {
        if (resultValid(result)) {
            QRCodeTransportPage page = QRCodeTransportPage
                    .formatQrCodeTransport(result);
            pages.add(page);
            totalPage = page.getSumPage();
            if (page.getCurrentPage() < totalPage - 1) {
                String str = String.format(LocaliserUtils.getString("scan_qr_transport_page_label"),
                        pages.size() + 1, totalPage);
                setMsg(str);

            } else {
                complete();
            }
        } else {
            shake();
        }

    }

}
 
Example 3
Source File: AddErrorMsgRunnable.java    From bither-android with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    obtainMessage(HandlerMessage.MSG_PREPARE);
    try {
        File errorFile = new File(UEHandler.getErrorLogFile(),"error.log");
        if (errorFile.exists()) {
            String errorMsg = Utils.readFile(errorFile);
            if (!Utils.isEmpty(errorMsg)) {
                BitherErrorApi addFeedbackApi = new BitherErrorApi(errorMsg);
                addFeedbackApi.handleHttpPost();
            }
            errorFile.delete();
            obtainMessage(HandlerMessage.MSG_SUCCESS);
        }

    } catch (Exception e) {
        e.printStackTrace();
        obtainMessage(HandlerMessage.MSG_FAILURE_NETWORK);
    }

}
 
Example 4
Source File: SignTxDialg.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
private void showTransaction() {
    if (Utils.isEmpty(qrCodeTransport.getChangeAddress()) || qrCodeTransport.getChangeAmt() == 0) {
        labChangeAmt.setVisible(false);
        labChangeAmtValue.setVisible(false);
        labChangeTo.setVisible(false);
        labChangeToValue.setVisible(false);
    } else {
        labChangeToValue.setText(qrCodeTransport.getChangeAddress());
        labChangeAmtValue.setText(UnitUtil.formatValue(qrCodeTransport.getChangeAmt(), UnitUtil.BitcoinUnit.BTC));
    }
    panelTx.setVisible(true);
    labFrom.setText(qrCodeTransport.getMyAddress());
    labPayTo.setText(qrCodeTransport.getToAddress());
    labFee.setText(UnitUtil.formatValue(qrCodeTransport.getFee(), UnitUtil.BitcoinUnit.BTC));
    labPayAmt.setText(UnitUtil.formatValue(qrCodeTransport.getTo(), UnitUtil.BitcoinUnit.BTC));

}
 
Example 5
Source File: MonitorBitherColdUtil.java    From bither-android with Apache License 2.0 6 votes vote down vote up
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == BitherSetting.INTENT_REF.SCAN_ALL_IN_BITHER_COLD_REUEST_CODE &&
            resultCode == Activity.RESULT_OK) {
        if (data.getExtras().containsKey(ScanActivity.INTENT_EXTRA_RESULT)) {
            final String content = data.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
            if (Utils.isEmpty(content) || !checkQrCodeContent(content)) {
                DropdownMessage.showDropdownMessage(activity, R.string
                        .scan_for_all_addresses_in_bither_cold_failed);
                return true;
            }
            ThreadNeedService thread = new ThreadNeedService(dp, activity) {

                @Override
                public void runWithService(BlockchainService service) {
                    processQrCodeContent(content, service);
                }
            };
            thread.start();
        }
        return true;
    }
    return false;
}
 
Example 6
Source File: SignHashActivity.java    From bither-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ScanRequestCode && resultCode == RESULT_OK) {
        final String input = data.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
        if (Utils.isEmpty(input)) {
            return;
        }
        etInput.setText(input);
        btnQr.setEnabled(true);
        btnSign.setVisibility(View.VISIBLE);
        pbSign.setVisibility(View.INVISIBLE);
        ivArrow.setVisibility(View.INVISIBLE);
        return;
    }
    super.onActivityResult(requestCode, resultCode, data);
}
 
Example 7
Source File: EnterpriseHDMSendCollectSignatureActivity.java    From bither-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == SignCode) {
        if (resultCode == RESULT_OK) {
            final String qr = data.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
            if (Utils.isEmpty(qr)) {
                LogUtil.w("EnterpriseHDM", "EnterpriseHDMSendCollectSignature qr empty");
                return;
            }
            addSignature(qr);
            showSignatures();
            if (pool.satisfied()) {
                sign();
            }
        }
        return;
    }
    super.onActivityResult(requestCode, resultCode, data);
}
 
Example 8
Source File: TxHelper.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public static In applyCursorIn(ResultSet c) throws AddressFormatException, SQLException {
    In inItem = new In();
    int idColumn = c.findColumn(AbstractDb.InsColumns.TX_HASH);
    if (idColumn != -1) {
        inItem.setTxHash(Base58.decode(c.getString(idColumn)));
    }
    idColumn = c.findColumn(AbstractDb.InsColumns.IN_SN);
    if (idColumn != -1) {
        inItem.setInSn(c.getInt(idColumn));
    }
    idColumn = c.findColumn(AbstractDb.InsColumns.PREV_TX_HASH);
    if (idColumn != -1) {
        inItem.setPrevTxHash(Base58.decode(c.getString(idColumn)));
    }
    idColumn = c.findColumn(AbstractDb.InsColumns.PREV_OUT_SN);
    if (idColumn != -1) {
        inItem.setPrevOutSn(c.getInt(idColumn));
    }
    idColumn = c.findColumn(AbstractDb.InsColumns.IN_SIGNATURE);
    if (idColumn != -1) {
        String inSignature = c.getString(idColumn);
        if (!Utils.isEmpty(inSignature)) {
            inItem.setInSignature(Base58.decode(c.getString(idColumn)));
        }
    }
    idColumn = c.findColumn(AbstractDb.InsColumns.IN_SEQUENCE);
    if (idColumn != -1) {
        inItem.setInSequence(c.getInt(idColumn));
    }
    return inItem;
}
 
Example 9
Source File: UserPreference.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
private int getLong(String key, int defaultValue) {
    String result = userPreferences.getProperty(key);
    if (Utils.isEmpty(result)) {
        return defaultValue;
    } else {
        if (Utils.isInteger(result)) {
            return Integer.valueOf(result);
        } else {
            return defaultValue;
        }
    }
}
 
Example 10
Source File: UserPreference.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
private int getInt(String key, int defaultValue) {
    String result = userPreferences.getProperty(key);
    if (Utils.isEmpty(result)) {
        return defaultValue;
    } else {
        if (Utils.isInteger(result)) {
            return Integer.valueOf(result);
        } else {
            return defaultValue;
        }
    }
}
 
Example 11
Source File: BackupUtil.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public static String[] getBackupKeyStrList(File file) {
    String keyStrs = Utils.readFile(file);
    String[] result = null;
    if (!Utils.isEmpty(keyStrs)) {
        result = keyStrs.split(PrivateKeyUtil.BACKUP_KEY_SPLIT_MUTILKEY_STRING);
    }
    return result;
}
 
Example 12
Source File: VanitygenPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
private void generateAddress() {
    if (textField.getText().length() <= 0) {
        new MessageDialog(LocaliserUtils.getString("vanity_address_not_empty")).showMsg();
        return;
    }
    final String input = "1" + textField.getText();
    String vaildBitcoinAddress = StringUtil.validBicoinAddressBegin(input);
    if (!Utils.isEmpty(vaildBitcoinAddress)) {
        String prompt = Utils.format(LocaliserUtils.getString("vanity_address_not_contains"), vaildBitcoinAddress);
        new MessageDialog(prompt).showMsg();
        return;

    }
    pb.setVisible(true);
    textField.setEnabled(false);
    caseInsensitiveBox.setEnabled(false);
    setOkEnabled(false);
    computingThread = new Thread() {
        @Override
        public void run() {
            boolean useOpenCL = shouldUseOpenCL();
            boolean igoreCase = caseInsensitiveBox.isSelected();
            String openclConfig = null;
            if (selectedDevice != null) {
                openclConfig = selectedDevice.getConfigureString();
            }
            bitherVanitygen = new BitherVanitygen(input, useOpenCL, igoreCase, threadNum,
                    ecKeyType, openclConfig, VanitygenPanel.this);
            bitherVanitygen.generateAddress();

        }
    };
    computingThread.start();
}
 
Example 13
Source File: BitherVanitygen.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
private void dealErrorWithString(String line) {
    if (Utils.isEmpty(line)) {
        return;
    }
    if (line.contains(DIFFICULTY_FORMAT)) {
        if (vanitygenListener != null) {

            vanitygenListener.onDifficulty(line.replace(DIFFICULTY_FORMAT, "").trim());
        }
        return;
    }

}
 
Example 14
Source File: SendHDMBitcoinPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public boolean setQrCodeResult(String qr) {

            if (!Utils.isEmpty(qr)) {
                try {
                    String[] stringArray = QRCodeUtil.splitString(qr);
                    sigs = new ArrayList<TransactionSignature>();
                    for (String str : stringArray) {
                        if (!Utils.isEmpty(str)) {
                            TransactionSignature transactionSignature = new
                                    TransactionSignature(ECKey.ECDSASignature.decodeFromDER
                                    (Utils.hexStringToByteArray(str)),
                                    TransactionSignature.SigHash.ALL, false);
                            sigs.add(transactionSignature);
                        }
                    }
                } catch (Exception e) {
                    sigs = null;
                    e.printStackTrace();
                    new MessageDialog(LocaliserUtils.getString("send_failed")).showMsg();
                }
            } else {
                sigs = null;
            }
            try {
                lock.lock();
                fetchedCondition.signal();
            } finally {
                lock.unlock();
            }
            return true;

        }
 
Example 15
Source File: HdmImportWordListActivity.java    From bither-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    if (words.size() >= WordCount) {
        return;
    }
    String word = etInput.getText().toString().toLowerCase().trim();
    if (Utils.isEmpty(word)) {
        return;
    }
    try {
        mnemonic = MnemonicCode.instanceForWord(new MnemonicCodeAndroid(), word);
        if (mnemonic == null) {
            DropdownMessage.showDropdownMessage(HdmImportWordListActivity.this,
                    R.string.hdm_import_word_list_wrong_word_warn);
            return;
        }
        words.add(word);
        etInput.setText("");
        refresh();
        gv.smoothScrollToPosition(words.size() - 1);
        if (words.size() >= WordCount) {
            complete();
        }
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }
}
 
Example 16
Source File: SendHDMBitcoinPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
@Override
public void initialiseContent(JPanel panel) {
    panel.setLayout(new MigLayout(
            Panels.migXYLayout(),
            "[]", // Column constraints
            "[][][][]" // Row constraints
    ));

    JLabel label = Labels.newValueLabel(LocaliserUtils.getString("address_balance") + " : " + Utils.bitcoinValueToPlainString(Bither.getActionAddress().getBalance()));
    panel.add(label, "align center,wrap");
    panel.add(newEnterAddressPanel(), "push,wrap");
    panel.add(newAmountPanel(), "push,wrap");
    panel.add(getenterPasswordMaV(), "push,wrap");
    if (!hdmAddress.isInRecovery()) {
        JButton btnSwitchCold = Buttons.newNormalButton(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                signWithCold = true;
                onOK();
            }
        }, MessageKey.hdm_send_with_cold, AwesomeIcon.QRCODE);
        panel.add(btnSwitchCold, "push ,align right,shrink");
    }
    if (!Utils.isEmpty(this.doateAddress)) {
        tfAddress.setText(this.doateAddress);
    }
    validateValues();


}
 
Example 17
Source File: AddressDetailPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
private void updateUI() {
    String address = "";
    if (Bither.getActionAddress() != null) {
        address = Bither.getActionAddress().getAddress();
    }
    if (Utils.isEmpty(address)) {
        btnAddressQRCode.setVisible(false);
    } else {

        taAddress.setText(WalletUtils.formatHash(address, 4, 12));
    }
}
 
Example 18
Source File: BitherQRCodeActivity.java    From bither-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_qr_code);
    Intent intent = getIntent();
    String codeString = null;
    String oldString = null;
    if (intent != null && intent.getExtras() != null) {
        if (intent.getExtras().containsKey(BitherSetting.INTENT_REF.QR_CODE_STRING)) {
            codeString = intent.getExtras().getString(BitherSetting.INTENT_REF.QR_CODE_STRING);
        }
        if (intent.getExtras().containsKey(BitherSetting.INTENT_REF.OLD_QR_CODE_STRING)) {
            oldString = intent.getExtras().getString(BitherSetting.INTENT_REF.OLD_QR_CODE_STRING);
        }
        if (intent.getExtras().containsKey(BitherSetting.INTENT_REF.QR_CODE_HAS_CHANGE_ADDRESS_STRING)) {
            hasChangeAddress = intent.getExtras().getBoolean(BitherSetting.INTENT_REF.QR_CODE_HAS_CHANGE_ADDRESS_STRING);
        }
        if (intent.getExtras().containsKey(BitherSetting.INTENT_REF.BITPIE_COLD_SIGN_MESSAGE_TYPE_STRING)) {
            signMessageType = QRCodeBitpieColdSignMessage.getSignMessageType(intent.getExtras().getInt(BitherSetting.INTENT_REF.BITPIE_COLD_SIGN_MESSAGE_TYPE_STRING, 0));
        }
        if (intent.getExtras().containsKey(BitherSetting.INTENT_REF.BITPIE_COLD_SIGN_FEE_TX_STRING)) {
            isFeeTx = intent.getExtras().getBoolean(BitherSetting.INTENT_REF.BITPIE_COLD_SIGN_FEE_TX_STRING, false);
        }
        if (intent.getExtras().containsKey(BitherSetting.INTENT_REF.BITPIE_COLD_CHANGE_COIN_IS_ONLY_GET_XPUB_STRING)) {
            isOnlyGetXpub = intent.getExtras().getBoolean(BitherSetting.INTENT_REF.BITPIE_COLD_CHANGE_COIN_IS_ONLY_GET_XPUB_STRING, false);
        }
    }
    hasOldQRCode = !Utils.isEmpty(oldString) || hasChangeAddress;
    if (!Utils.isEmpty(oldString)) {
        this.oldContents = QRCodeUtil.getQrCodeStringList(QRCodeEnodeUtil.oldEncodeQrCodeString(oldString));
    }
    if (Utils.isEmpty(codeString)) {
        super.finish();
        overridePendingTransition(0, 0);
    } else {
        isNewVerion = true;
        if (signMessageType != null) {
            this.contents = new ArrayList<>();
            contents.add(codeString);
        } else {
            this.contents = QRCodeUtil.getQrCodeStringList(QRCodeUtil.encodeQrCodeString(codeString));
        }
        initView();
        String title = getTitleString();
        if (!Utils.isEmpty(title)) {
            tvTitle.setText(title);
        }
    }
}
 
Example 19
Source File: DialogSendConfirm.java    From bither-android with Apache License 2.0 4 votes vote down vote up
public DialogSendConfirm(Context context, Tx tx, String changeAddress,
                             SendConfirmListener listener) {
        super(context);
        this.tx = tx;
        this.listener = listener;
        setOnDismissListener(this);
        setContentView(R.layout.dialog_send_confirm);
        TextView tvAddress = (TextView) findViewById(R.id.tv_address);
        TextView tvBtc = (TextView) findViewById(R.id.tv_btc);
        TextView tvFee = (TextView) findViewById(R.id.tv_fee);
        TextView tvSymbol = (TextView) findViewById(R.id.tv_symbol);
        TextView tvFeeSymbol = (TextView) findViewById(R.id.tv_fee_symbol);
        View llChange = findViewById(R.id.ll_change);
        TextView tvAddressChange = (TextView) findViewById(R.id.tv_address_change);
        TextView tvBtcChange = (TextView) findViewById(R.id.tv_btc_change);
        TextView tvSymbolChange = (TextView) findViewById(R.id.tv_symbol_change);
        String symbol = AppSharedPreference.getInstance().getBitcoinUnit().name();
        tvSymbol.setText(symbol);
        tvFeeSymbol.setText(symbol);
        tvSymbolChange.setText(symbol);
        Button btnCancel = (Button) findViewById(R.id.btn_cancel);
        Button btnOk = (Button) findViewById(R.id.btn_ok);
        String outAddress = tx.getFirstOutAddressOtherThanChange(changeAddress);
        if (Utils.isEmpty(changeAddress) || tx.amountSentToAddress(changeAddress) <= 0) {
            llChange.setVisibility(View.GONE);
        } else {
            tvAddressChange.setText(WalletUtils.formatHash(changeAddress, 4, 24));
            tvBtcChange.setText(UnitUtilWrapper.formatValueWithBold(tx.amountSentToAddress(changeAddress)));
        }
        if (tx.getFirstOutAddress() != null) {
            tvAddress.setText(WalletUtils.formatHash(outAddress, 4, 24));
        }
        tvBtc.setText(UnitUtilWrapper.formatValueWithBold(tx.amountSentToAddress(outAddress)));
        tvFee.setText(UnitUtilWrapper.formatValueWithBold(tx.getFee()));
        // This warning is no longer needed. As more and more mining pool upgrade their
        // bitcoin client to 0.9.+, low fee transactions get confirmed soon enough.
//		if (isLowPriority(tx)) {
//			tvLowPriorityWarn.setVisibility(View.VISIBLE);
//		} else {
//			tvLowPriorityWarn.setVisibility(View.GONE);
//		}
        btnCancel.setOnClickListener(cancelClick);
        btnOk.setOnClickListener(okClick);
    }
 
Example 20
Source File: QRCodeTxTransport.java    From bitherj with Apache License 2.0 4 votes vote down vote up
public static String getDeskpHDMPresignTxString(TxTransportType txTransportType, Tx tx, String changeAddress,
                                                String addressCannotParsed, List<DesktopHDMAddress> desktopHDMAddresses) {
    QRCodeTxTransport qrCodeTransport = fromDeskpHDMSendRequestWithUnsignedTransaction(txTransportType, tx, desktopHDMAddresses,
            addressCannotParsed);
    String preSignString = "";
    try {
        String versionStr = "";
        if (txTransportType != null) {
            versionStr = TX_TRANSPORT_VERSION + txTransportType.getType();
        }
        String changeStr = "";
        if (!Utils.isEmpty(changeAddress)) {
            long changeAmt = tx.amountSentToAddress(changeAddress);
            if (changeAmt != 0) {
                String[] changeStrings = new String[]{Base58.bas58ToHexWithAddress
                        (changeAddress), Long.toHexString(changeAmt)};
                changeStr = Utils.joinString(changeStrings, QRCodeUtil.QR_CODE_SPLIT);

            }
        }
        String hdmIndexString = "";
        if (qrCodeTransport.getHdmIndex() != QRCodeTxTransport.NO_HDM_INDEX) {
            hdmIndexString = Integer.toHexString(qrCodeTransport.getHdmIndex());
        }
        String[] preSigns = new String[]{versionStr, hdmIndexString, Base58.bas58ToHexWithAddress
                (qrCodeTransport.getMyAddress()), changeStr, Long.toHexString(qrCodeTransport
                .getFee()), Base58.bas58ToHexWithAddress(qrCodeTransport.getToAddress()),
                Long.toHexString(qrCodeTransport.getTo())};
        preSignString = Utils.joinString(preSigns, QRCodeUtil.QR_CODE_SPLIT);
        String[] hashStrings = new String[qrCodeTransport.getHashList().size()];
        hashStrings = qrCodeTransport.getHashList().toArray(hashStrings);
        preSignString = preSignString + QRCodeUtil.QR_CODE_SPLIT + Utils.joinString
                (hashStrings, QRCodeUtil.QR_CODE_SPLIT);
        preSignString.toUpperCase(Locale.US);
    } catch (AddressFormatException e) {
        e.printStackTrace();
    }

    return preSignString;

}