Java Code Examples for net.bither.bitherj.utils.Utils#joinString()
The following examples show how to use
net.bither.bitherj.utils.Utils#joinString() .
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: HDAccountProvider.java From bither-desktop-java with Apache License 2.0 | 6 votes |
@Override public List<HDAccount.HDAccountAddress> belongAccount(List<String> addresses) { List<HDAccount.HDAccountAddress> hdAccountAddressList = new ArrayList<HDAccount.HDAccountAddress>(); List<String> temp = new ArrayList<String>(); for (String str : addresses) { temp.add(Utils.format("'%s'", str)); } String sql = "select address,pub,path_type,address_index,is_issued,is_synced from " + AbstractDb.Tables.HD_ACCOUNT_ADDRESS + " where address in (" + Utils.joinString(temp, ",") + ")"; try { PreparedStatement statement = this.mDb.getPreparedStatement(sql, null); ResultSet cursor = statement.executeQuery(); while (cursor.next()) { hdAccountAddressList.add(formatAddress(cursor)); } cursor.close(); statement.close(); } catch (SQLException e) { e.printStackTrace(); } return hdAccountAddressList; }
Example 2
Source File: AbstractHDAccountAddressProvider.java From bitherj with Apache License 2.0 | 6 votes |
@Override public List<HDAccount.HDAccountAddress> belongAccount(int hdAccountId, List<String> addresses) { final List<HDAccount.HDAccountAddress> hdAccountAddressList = new ArrayList<HDAccount .HDAccountAddress>(); List<String> temp = new ArrayList<String>(); for (String str : addresses) { temp.add(Utils.format("'%s'", str)); } String sql = "select address,pub,path_type,address_index,is_issued,is_synced,hd_account_id " + " from hd_account_addresses" + " where hd_account_id=? and address in (" + Utils.joinString(temp, ",") + ")"; this.execQueryLoop(sql, new String[]{Integer.toString(hdAccountId)}, new Function<ICursor, Void>() { @Nullable @Override public Void apply(@Nullable ICursor c) { hdAccountAddressList.add(formatAddress(c)); return null; } }); return hdAccountAddressList; }
Example 3
Source File: HDAccountProvider.java From bither-desktop-java with Apache License 2.0 | 6 votes |
@Override public List<HDAccount.HDAccountAddress> belongAccount(List<String> addresses) { List<HDAccount.HDAccountAddress> hdAccountAddressList = new ArrayList<HDAccount.HDAccountAddress>(); List<String> temp = new ArrayList<String>(); for (String str : addresses) { temp.add(Utils.format("'%s'", str)); } String sql = "select address,pub,path_type,address_index,is_issued,is_synced from " + AbstractDb.Tables.HD_ACCOUNT_ADDRESS + " where address in (" + Utils.joinString(temp, ",") + ")"; try { PreparedStatement statement = this.mDb.getPreparedStatement(sql, null); ResultSet cursor = statement.executeQuery(); while (cursor.next()) { hdAccountAddressList.add(formatAddress(cursor)); } cursor.close(); statement.close(); } catch (SQLException e) { e.printStackTrace(); } return hdAccountAddressList; }
Example 4
Source File: RestoreWalletSeedPhrasePanel.java From bither-desktop-java with Apache License 2.0 | 5 votes |
public void updateModelFromView() { String text = seedPhraseTextArea.getText(); seedPhraseList = Lists.newArrayList(Splitter .on(" ") .omitEmptyStrings() .trimResults() .split(text) ); boolean okEnabled; if (this.importHDSeedType == ImportHDSeed.ImportHDSeedType.HDSeedPhrase) { okEnabled = seedPhraseList.size() % 3 != 0 || !text.endsWith(" "); } else { okEnabled = seedPhraseList.size() < PHRASE_COUNT || !text.endsWith(" "); } if (okEnabled) { setOkEnabled(false); } else { List<String> faildWorldList = new ArrayList<String>(); for (String world : seedPhraseList) { if (!MnemonicCode.instance().getWordList().contains(world)) { faildWorldList.add(world); } } if (faildWorldList.size() == 0) { setOkEnabled(true); } else { String str = Utils.joinString(faildWorldList, "-"); new MessageDialog(LocaliserUtils.getString("hdm_import_word_list_wrong_word_warn") + str).showMsg(); } } }
Example 5
Source File: QRCodeTxTransport.java From bitherj with Apache License 2.0 | 5 votes |
public static String getPresignTxString(Tx tx, String changeAddress, String addressCannotParsed, int hdmIndex, TxTransportType txTransportType) { QRCodeTxTransport qrCodeTransport = fromSendRequestWithUnsignedTransaction(tx, addressCannotParsed, hdmIndex, txTransportType); 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; }
Example 6
Source File: DesktopHDMKeychain.java From bitherj with Apache License 2.0 | 5 votes |
public static boolean checkPassword(String keysString, CharSequence password) throws MnemonicException.MnemonicLengthException { String[] passwordSeeds = QRCodeUtil.splitOfPasswordSeed(keysString); String address = Base58.hexToBase58WithAddress(passwordSeeds[0]); String encreyptString = Utils.joinString(new String[]{passwordSeeds[1], passwordSeeds[2], passwordSeeds[3]}, QRCodeUtil.QR_CODE_SPLIT); byte[] seed = new EncryptedData(encreyptString).decrypt(password); MnemonicCode mnemonic = MnemonicCode.instance(); byte[] s = mnemonic.toSeed(mnemonic.toMnemonic(seed), ""); DeterministicKey master = HDKeyDerivation.createMasterPrivateKey(s); DeterministicKey purpose = master.deriveHardened(44); DeterministicKey coinType = purpose.deriveHardened(0); DeterministicKey account = coinType.deriveHardened(0); DeterministicKey external = account.deriveSoftened(0); external.clearPrivateKey(); DeterministicKey key = external.deriveSoftened(0); boolean result = Utils.compareString(address, Utils.toAddress(key.getPubKeyHash())); key.wipe(); return result; }
Example 7
Source File: HDMKeychain.java From bitherj with Apache License 2.0 | 5 votes |
public static boolean checkPassword(String keysString, CharSequence password) throws MnemonicException.MnemonicLengthException { String[] passwordSeeds = QRCodeUtil.splitOfPasswordSeed(keysString); String address = Base58.hexToBase58WithAddress(passwordSeeds[0]); String encreyptString = Utils.joinString(new String[]{passwordSeeds[1], passwordSeeds[2], passwordSeeds[3]}, QRCodeUtil.QR_CODE_SPLIT); byte[] seed = new EncryptedData(encreyptString).decrypt(password); MnemonicCode mnemonic = MnemonicCode.instance(); byte[] s = mnemonic.toSeed(mnemonic.toMnemonic(seed), ""); DeterministicKey master = HDKeyDerivation.createMasterPrivateKey(s); DeterministicKey purpose = master.deriveHardened(44); DeterministicKey coinType = purpose.deriveHardened(0); DeterministicKey account = coinType.deriveHardened(0); DeterministicKey external = account.deriveSoftened(0); external.clearPrivateKey(); DeterministicKey key = external.deriveSoftened(0); boolean result = Utils.compareString(address, Utils.toAddress(key.getPubKeyHash())); key.wipe(); return result; }
Example 8
Source File: RestoreWalletSeedPhrasePanel.java From bither-desktop-java with Apache License 2.0 | 5 votes |
public void updateModelFromView() { String text = seedPhraseTextArea.getText(); seedPhraseList = Lists.newArrayList(Splitter .on(" ") .omitEmptyStrings() .trimResults() .split(text) ); boolean okEnabled; if (this.importHDSeedType == ImportHDSeed.ImportHDSeedType.HDSeedPhrase) { okEnabled = seedPhraseList.size() % 3 != 0 || !text.endsWith(" "); } else { okEnabled = seedPhraseList.size() < PHRASE_COUNT || !text.endsWith(" "); } if (okEnabled) { setOkEnabled(false); } else { List<String> faildWorldList = new ArrayList<String>(); for (String world : seedPhraseList) { if (!MnemonicCode.instance().getWordList().contains(world)) { faildWorldList.add(world); } } if (faildWorldList.size() == 0) { setOkEnabled(true); } else { String str = Utils.joinString(faildWorldList, "-"); new MessageDialog(LocaliserUtils.getString("hdm_import_word_list_wrong_word_warn") + str).showMsg(); } } }
Example 9
Source File: QRCodeTxTransport.java From bitherj with Apache License 2.0 | 4 votes |
public static String getHDAccountMonitoredUnsignedTx(Tx tx, String toAddress, HDAccount account) { TxTransportType txTransportType = TxTransportType.ColdHD; List<HDAccount.HDAccountAddress> addresses = account.getSigningAddressesForInputs(tx .getIns()); List<byte[]> hashes = tx.getUnsignedInHashes(); QRCodeTxTransport qrCodeTransport = new QRCodeTxTransport(); qrCodeTransport.setMyAddress(tx.getFromAddress()); qrCodeTransport.setToAddress(toAddress); qrCodeTransport.setTo(tx.amountSentToAddress(toAddress)); qrCodeTransport.setFee(tx.getFee()); List<String> hashList = new ArrayList<String>(); for (int i = 0; i < addresses.size(); i++) { HDAccount.HDAccountAddress address = addresses.get(i); byte[] h = hashes.get(i); String[] strings = new String[]{Integer.toString(address.getPathType().getValue()), Integer.toString(address.getIndex()), Utils.bytesToHexString(h).toUpperCase (Locale.US)}; hashList.add(Utils.joinString(strings, QRCodeUtil.QR_CODE_SECONDARY_SPLIT)); } qrCodeTransport.setHashList(hashList); String preSignString; try { String versionStr = ""; if (txTransportType != null) { versionStr = TX_TRANSPORT_VERSION + txTransportType.getType(); } String[] preSigns = new String[]{versionStr, Base58.bas58ToHexWithAddress (qrCodeTransport.getMyAddress()), 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 null; } return preSignString; }
Example 10
Source File: QRCodeTxTransport.java From bitherj with Apache License 2.0 | 4 votes |
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; }