Java Code Examples for net.bither.bitherj.core.Address

The following examples show how to use net.bither.bitherj.core.Address. These examples are extracted from open source projects. 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 Project: bither-desktop-java   Source File: AddressTableModel.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object getValueAt(int i, int i2) {
    Address address = this.addressList.get(i);
    switch (i2) {
        case 0:
            if (address instanceof HDAccount) {
                return LocaliserUtils.getString("add_hd_account_tab_hd");
            }
            return address.getAddress();
        case 1:

            return address.hasPrivKey();
        case 2:
            return Utils.compareString(address.getAddress(), selectAddress);

    }

    return "";
}
 
Example 2
Source Project: bitherj   Source File: AbstractAddressProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, Integer> getVanitylens() {
    String sql = "select * from vanity_address";
    final Map<String, Integer> vanityLenMap = new HashMap<String, Integer>();

    this.execQueryLoop(sql, null, new Function<ICursor, Void>() {
        @Nullable
        @Override
        public Void apply(@Nullable ICursor c) {
            int idColumn = c.getColumnIndex(AbstractDb.VanityAddressColumns.ADDRESS);
            String address = null;
            int alias = Address.VANITY_LEN_NO_EXSITS;
            if (idColumn > -1) {
                address = c.getString(idColumn);
            }
            idColumn = c.getColumnIndex(AbstractDb.VanityAddressColumns.VANITY_LEN);
            if (idColumn > -1) {
                alias = c.getInt(idColumn);
            }
            vanityLenMap.put(address, alias);
            return null;
        }
    });
    return vanityLenMap;
}
 
Example 3
Source Project: bither-desktop-java   Source File: AddressProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void addAddress(final Address address) {
    try {

        this.mDb.getConn().setAutoCommit(false);
        String[] params = new String[]{address.getAddress(), address.hasPrivKey() ? address.getEncryptPrivKeyOfDb() : null, Base58.encode(address.getPubKey()),
                Integer.toString(address.isFromXRandom() ? 1 : 0), Integer.toString(address.isSyncComplete() ? 1 : 0), Integer.toString(address.isTrashed() ? 1 : 0), Long.toString(address.getSortTime())};
        PreparedStatement stmt = this.mDb.getConn().prepareStatement(insertAddressSql);
        if (params != null) {
            for (int i = 0; i < params.length; i++) {
                stmt.setString(i + 1, params[i]);
            }
        }
        stmt.executeUpdate();
        if (address.hasPrivKey()) {
            if (!hasPasswordSeed(this.mDb.getConn())) {
                PasswordSeed passwordSeed = new PasswordSeed(address.getAddress(), address.getFullEncryptPrivKeyOfDb());
                addPasswordSeed(this.mDb.getConn(), passwordSeed);
            }
        }
        this.mDb.getConn().commit();
        stmt.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
 
Example 4
Source Project: bither-android   Source File: TrashCanActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder h;
    if (convertView == null) {
        if (inflater == null) {
            inflater = LayoutInflater.from(TrashCanActivity.this);
        }
        convertView = inflater.inflate(R.layout.list_item_trash_can, null);
        h = new ViewHolder(convertView);
    } else {
        h = (ViewHolder) convertView.getTag();
    }
    Address address = getItem(position);
    h.tv.setText(WalletUtils.formatHash(address.getAddress(), 4, 12));
    h.flAddress.setOnClickListener(new CopyClick(address.getAddress()));
    h.ibtnViewOnNet.setOnClickListener(new ViewOnNetClick(address, h));
    if (AppSharedPreference.getInstance().getAppMode() == BitherjSettings.AppMode.HOT) {
        h.ibtnViewOnNet.setVisibility(View.VISIBLE);
    } else {
        h.ibtnViewOnNet.setVisibility(View.GONE);
    }
    h.ibtnRestore.setOnClickListener(new RestoreClick(address));
    h.btnAlias.setOnClickListener(new AliasClick(address, h));
    h.onAddressAliasChanged(address, address.getAlias());
    return convertView;
}
 
Example 5
public AddressOfColdFragmentListAdapter(FragmentActivity activity,
                                        List<Address> privates, ColdAddressFragmentHDMListItemView.RequestHDMServerQrCodeDelegate requestHDMServerQrCodeDelegate) {
    this.activity = activity;
    this.privates = privates;
    this.requestHDMServerQrCodeDelegate = requestHDMServerQrCodeDelegate;
    if (AddressManager.getInstance().hasHDAccountCold()) {
        hdAccountCold = AddressManager.getInstance().getHDAccountCold();
    } else {
        hdAccountCold = null;
    }
    if (AddressManager.getInstance().hasBitpieHDAccountCold()) {
        bitpieHDAccountCold = AddressManager.getInstance().getBitpieHDAccountCold();
    } else {
        bitpieHDAccountCold = null;
    }
    if (EnterpriseHDMSeed.hasSeed()) {
        enterpriseHDMSeed = EnterpriseHDMSeed.seed();
    } else {
        enterpriseHDMSeed = null;
    }
}
 
Example 6
Source Project: bitherj   Source File: QRCodeEnodeUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static String getPublicKeyStrOfPrivateKey() {
    String content = "";
    List<Address> addresses = AddressManager.getInstance().getPrivKeyAddresses();
    for (int i = 0; i < addresses.size(); i++) {
        Address address = addresses.get(i);
        String pubStr = "";
        if (address.isFromXRandom()) {
            pubStr = QRCodeUtil.XRANDOM_FLAG;
        }
        pubStr = pubStr + Utils.bytesToHexString(address.getPubKey());
        content += pubStr;
        if (i < addresses.size() - 1) {
            content += QRCodeUtil.QR_CODE_SPLIT;
        }
    }
    content.toUpperCase(Locale.US);
    return content;
}
 
Example 7
Source Project: bitherj   Source File: UpgradeAddressUtil.java    License: Apache License 2.0 5 votes vote down vote up
private static List<Address> initWatchOnlyListByDesc() {
    List<Address> watchOnlyAddresses = new ArrayList<Address>();
    File[] files = Utils.getWatchOnlyDir().listFiles();
    if (files != null) {
        for (File file : files) {
            if (file.getName().contains(Address.PUBLIC_KEY_FILE_NAME_SUFFIX)) {
                String content = Utils.readFile(file);
                String[] strings = content.split(Address.KEY_SPLIT_STRING);
                String address = file.getName().substring(0,
                        file.getName().length() - Address.PUBLIC_KEY_FILE_NAME_SUFFIX.length());
                String publicKey = strings[0];
                int isSyncComplete = Integer.valueOf(strings[1]);
                long sortTime = Long.valueOf(strings[2]);
                boolean isFromXRandom = false;
                if (strings.length == 4) {
                    isFromXRandom = Utils.compareString(strings[3], QRCodeUtil.XRANDOM_FLAG);
                }
                Address add = new Address(address, Utils.hexStringToByteArray(publicKey), sortTime
                        , isSyncComplete == 1, isFromXRandom, false, null);
                watchOnlyAddresses.add(add);

            }
        }
        if (watchOnlyAddresses.size() > 0) {
            Collections.sort(watchOnlyAddresses);
        }
    }
    return watchOnlyAddresses;
}
 
Example 8
Source Project: bitherj   Source File: ImportPrivateKey.java    License: Apache License 2.0 5 votes vote down vote up
public Address initPrivateKey() {
    ECKey ecKey = getEckey();
    try {
        if (ecKey == null) {
            if (importPrivateKeyType == ImportPrivateKeyType.BitherQrcode) {
                importError(PASSWORD_WRONG);
            } else {
                importError(IMPORT_FAILED);
            }
            return null;
        } else {
            List<String> addressList = new ArrayList<String>();
            addressList.add(ecKey.toAddress());
            return addECKey(ecKey);
        }
    } catch (Exception e) {
        e.printStackTrace();
        importError(IMPORT_FAILED);
        return null;
    } finally {
        password.wipe();
        if (ecKey != null) {
            ecKey.clearPrivateKey();
        }
    }

}
 
Example 9
Source Project: bither-desktop-java   Source File: WalletUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static Address findPrivateKey(String address) {
    for (Address bitherAddressWithPrivateKey : AddressManager.getInstance().getPrivKeyAddresses()) {

        if (Utils.compareString(address,
                bitherAddressWithPrivateKey.getAddress())) {
            return bitherAddressWithPrivateKey;
        }
    }
    return null;
}
 
Example 10
Source Project: bither-desktop-java   Source File: CheckUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static Check initCheckForPrivateKey(
        final Address address, final SecureCharSequence password) {
    String title = String.format(LocaliserUtils.getString("check_address_private_key_title"), address
            .getShortAddress());
    Check check = new Check(title, new ICheckAction() {

        @Override
        public boolean check() {
            boolean result = new PasswordSeed(address.getAddress(), address.getFullEncryptPrivKey()).checkPassword(password);
            if (!result) {
                try {
                    ECKey eckeyFromBackup = BackupUtil.getEckeyFromBackup(
                            address.getAddress(), password);
                    if (eckeyFromBackup != null) {
                        String encryptPrivateKey = PrivateKeyUtil.getEncryptedString(eckeyFromBackup);
                        if (!Utils.isEmpty(encryptPrivateKey)) {
                            address.recoverFromBackup(encryptPrivateKey);
                            result = true;
                        }
                        eckeyFromBackup.clearPrivateKey();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    password.wipe();
                }


            }
            return result;
        }
    });
    return check;
}
 
Example 11
Source Project: bither-desktop-java   Source File: MonitorAddress.java    License: Apache License 2.0 5 votes vote down vote up
private void processQrCodeContent(String content) {
    try {
        addresses.clear();
        java.util.List<Address> wallets = QRCodeEnodeUtil.formatPublicString(content);
        for (Address address : wallets) {
            if (!AddressManager.getInstance().getAllAddresses().contains(address)) {
                addresses.add(address.getAddress());
            }
        }
        addAddress(wallets);
    } catch (Exception e) {
        new MessageDialog(LocaliserUtils.getString("scan_for_all_addresses_in_bither_cold_failed")).showMsg();

    }
}
 
Example 12
Source Project: bither-desktop-java   Source File: MonitorAddress.java    License: Apache License 2.0 5 votes vote down vote up
private void addAddress(
        final List<Address> wallets) {
    try {
        List<String> addressList = new ArrayList<String>();
        for (Address bitherAddress : wallets) {
            addressList.add(bitherAddress.getAddress());
        }
        KeyUtil.addAddressListByDesc(wallets);
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                progressDialog.dispose();
                Bither.refreshFrame();

            }
        });

    } catch (Exception e) {
        e.printStackTrace();
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                progressDialog.dispose();
                new MessageDialog(LocaliserUtils.getString("network_or_connection_error")).showMsg();
            }
        });

    }
}
 
Example 13
public void importPrivateKey() {
    new Thread() {


        @Override
        public void run() {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    dialogProgress.pack();
                    dialogProgress.setVisible(true);
                }
            });
            Address address = initPrivateKey();
            if (address != null) {
                List<Address> addressList = new ArrayList<Address>();
                addressList.add(address);
                KeyUtil.addAddressListByDesc(addressList);
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        dialogProgress.dispose();
                        Bither.refreshFrame();
                        new MessageDialog(LocaliserUtils.getString("import_private_key_qr_code_success")).showMsg();
                        if (importPrivateKeyListener != null) {
                            importPrivateKeyListener.importSuccess();
                        }
                    }
                });
            }
        }

    }.start();
}
 
Example 14
Source Project: bither-desktop-java   Source File: AddressCheck.java    License: Apache License 2.0 5 votes vote down vote up
public AddressCheck(Address address, CheckStatus checkStatus) {
    this.address = address;
    this.checkStatus = checkStatus;
    this.dispalyName = address.getAddress();
    this.checkType = CheckType.Address;

}
 
Example 15
Source Project: bither-android   Source File: WalletUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static Address findPrivateKey(String address) {
    for (Address bitherAddressWithPrivateKey : AddressManager.getInstance().getPrivKeyAddresses()) {
        if (Utils.compareString(address, bitherAddressWithPrivateKey.getAddress())) {
            return bitherAddressWithPrivateKey;
        }
    }
    if (AddressManager.getInstance().hasHDMKeychain()) {
        for (HDMAddress a : AddressManager.getInstance().getHdmKeychain().getAddresses()) {
            if (Utils.compareString(address, a.getAddress())) {
                return a;
            }
        }
    }
    return null;
}
 
Example 16
Source Project: bither-android   Source File: KeyUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void addAddressListByDesc(BlockchainService service, List<Address> addressList) {
    if (service != null) {
        service.stopAndUnregister();
    }
    boolean hasPrivateKey = false;
    AddressManager addressManager = AddressManager.getInstance();
    //need reverse addressList
    Collections.reverse(addressList);
    for (Address address : addressList) {
        if (address.hasPrivKey() && !hasPrivateKey) {
            hasPrivateKey = true;
        }
        if (!addressManager.getPrivKeyAddresses().contains(address) &&
                !addressManager.getWatchOnlyAddresses().contains(address)) {
            addressManager.addAddress(address);

        }
    }
    if (hasPrivateKey) {
        if (AppSharedPreference.getInstance().getAppMode() == BitherjSettings.AppMode.COLD) {
            BackupUtil.backupColdKey(false);
        } else {
            BackupUtil.backupHotKey();
        }
    }
    if (service != null) {
        service.startAndRegister();
    }

}
 
Example 17
Source Project: bither-desktop-java   Source File: ReplayTask.java    License: Apache License 2.0 5 votes vote down vote up
public ReplayTask(List<Address> perWalletModelDataToReplay, Date startDate, int startHeight) {
    this.perWalletModelDataToReplay = perWalletModelDataToReplay;
    this.startDate = startDate;
    this.startHeight = startHeight;
    this.percentComplete = Message.NOT_RELEVANT_PERCENTAGE_COMPLETE;
    this.uuid = UUID.randomUUID();
}
 
Example 18
Source Project: bitherj   Source File: AbstractAddressProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void addAddress(Address address) {
    IDb writeDb = this.getWriteDb();
    writeDb.beginTransaction();
    this.insertAddressToDb(writeDb, address);
    if (address.hasPrivKey()) {
        if (!hasPasswordSeed(writeDb)) {
            PasswordSeed passwordSeed = new PasswordSeed(address.getAddress(), address.getFullEncryptPrivKeyOfDb());
            addPasswordSeed(writeDb, passwordSeed);
        }
    }
    writeDb.endTransaction();
}
 
Example 19
@Override
public void onAddressAliasChanged(Address address, String alias) {
    if (!Utils.isEmpty(alias)) {
        btnAlias.setText(alias);
        btnAlias.setVisibility(View.VISIBLE);
    } else {
        btnAlias.setText("");
        btnAlias.setVisibility(View.INVISIBLE);
    }
}
 
Example 20
Source Project: bither-desktop-java   Source File: CheckUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static Check initCheckForPrivateKey(
        final Address address, final SecureCharSequence password) {
    String title = String.format(LocaliserUtils.getString("check_address_private_key_title"), address
            .getShortAddress());
    Check check = new Check(title, new ICheckAction() {

        @Override
        public boolean check() {
            boolean result = new PasswordSeed(address.getAddress(), address.getFullEncryptPrivKey()).checkPassword(password);
            if (!result) {
                try {
                    ECKey eckeyFromBackup = BackupUtil.getEckeyFromBackup(
                            address.getAddress(), password);
                    if (eckeyFromBackup != null) {
                        String encryptPrivateKey = PrivateKeyUtil.getEncryptedString(eckeyFromBackup);
                        if (!Utils.isEmpty(encryptPrivateKey)) {
                            address.recoverFromBackup(encryptPrivateKey);
                            result = true;
                        }
                        eckeyFromBackup.clearPrivateKey();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    password.wipe();
                }


            }
            return result;
        }
    });
    return check;
}
 
Example 21
Source Project: bither-desktop-java   Source File: WalletListPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void addColdAddressList(GridBagConstraints constraints, List<Address> addresses) {
    synchronized (walletPanels) {
        for (Address loopPerWalletModelData : addresses) {
            if (loopPerWalletModelData != null) {
                JPanel outerPanel = new JPanel();
                outerPanel.setOpaque(false);
                outerPanel.setBorder(BorderFactory.createEmptyBorder(TOP_BORDER, LEFT_BORDER, 0, RIGHT_BORDER));
                outerPanel.setLayout(new GridBagLayout());

                GridBagConstraints constraints2 = new GridBagConstraints();
                constraints2.fill = GridBagConstraints.BOTH;
                constraints2.gridx = 0;
                constraints2.gridy = 0;
                constraints2.weightx = 1.0;
                constraints2.weighty = 1.0;
                constraints2.gridwidth = 1;
                constraints2.gridheight = 1;
                constraints2.anchor = GridBagConstraints.CENTER;

                SingleColdWalletFrom coldWalletFrom = new SingleColdWalletFrom(loopPerWalletModelData, this);
                coldWalletFrom.getPanel().setComponentOrientation(ComponentOrientation
                        .getOrientation(LocaliserUtils.getLocale()));


                outerPanel.add(coldWalletFrom.getPanel(), constraints2);


                walletListPanel.add(outerPanel, constraints);
                walletPanels.add(coldWalletFrom);
                constraints.gridy = constraints.gridy + 1;

            }
        }
    }


}
 
Example 22
Source Project: bither-desktop-java   Source File: ImportPrivateKeyPanel.java    License: Apache License 2.0 5 votes vote down vote up
public void run() {
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {

        }
    });
    List<Address> addressList = PrivateKeyUtil.getECKeysFromBackupString(content, password);
    HDMKeychain hdmKeychain = PrivateKeyUtil.getHDMKeychain(content, password);

    if ((addressList == null || addressList.size() == 0) && (hdmKeychain == null)) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                dp.dispose();
                new MessageDialog(LocaliserUtils.getString("clone_from_failed")).showMsg();
            }
        });
        return;
    }

    KeyUtil.addAddressListByDesc(addressList);
    if (hdmKeychain != null) {
        KeyUtil.setHDKeyChain(hdmKeychain);
    }
    password.wipe();

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            dp.dispose();
            new MessageDialog(LocaliserUtils.getString("clone_from_success")).showMsg();
            closePanel();
            Bither.refreshFrame();
        }
    });
}
 
Example 23
Source Project: bither-desktop-java   Source File: MonitorAddress.java    License: Apache License 2.0 5 votes vote down vote up
private void processQrCodeContent(String content) {
    try {
        addresses.clear();
        java.util.List<Address> wallets = QRCodeEnodeUtil.formatPublicString(content);
        for (Address address : wallets) {
            if (!AddressManager.getInstance().getAllAddresses().contains(address)) {
                addresses.add(address.getAddress());
            }
        }
        addAddress(wallets);
    } catch (Exception e) {
        new MessageDialog(LocaliserUtils.getString("scan_for_all_addresses_in_bither_cold_failed")).showMsg();

    }
}
 
Example 24
Source Project: bither-desktop-java   Source File: MenuBar.java    License: Apache License 2.0 5 votes vote down vote up
private void updateTickerInfo() {
    new Thread(new Runnable() {
        @Override
        public void run() {

            long finalEstimatedBalance = 0;
            for (Address address : AddressManager.getInstance().getAllAddresses()) {
                finalEstimatedBalance = finalEstimatedBalance + address.getBalance();
            }
            if (AddressManager.getInstance().getHdAccount() != null) {
                finalEstimatedBalance = finalEstimatedBalance + AddressManager.getInstance().getHdAccount().getBalance();
            }
            final long total = finalEstimatedBalance;
            final String exchange = MarketUtil.getMarketName(UserPreference.getInstance().getDefaultMarket());
            final String currency = UserPreference.getInstance().getDefaultCurrency().getName();
            final Ticker ticker = MarketUtil.getTickerOfDefaultMarket();


            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    updateHeaderOnSwingThread("", total, currency, ticker, exchange);
                }
            });

        }


    }).start();


}
 
Example 25
Source Project: bither-desktop-java   Source File: WalletListPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void addColdAddressList(GridBagConstraints constraints, List<Address> addresses) {
    synchronized (walletPanels) {
        for (Address loopPerWalletModelData : addresses) {
            if (loopPerWalletModelData != null) {
                JPanel outerPanel = new JPanel();
                outerPanel.setOpaque(false);
                outerPanel.setBorder(BorderFactory.createEmptyBorder(TOP_BORDER, LEFT_BORDER, 0, RIGHT_BORDER));
                outerPanel.setLayout(new GridBagLayout());

                GridBagConstraints constraints2 = new GridBagConstraints();
                constraints2.fill = GridBagConstraints.BOTH;
                constraints2.gridx = 0;
                constraints2.gridy = 0;
                constraints2.weightx = 1.0;
                constraints2.weighty = 1.0;
                constraints2.gridwidth = 1;
                constraints2.gridheight = 1;
                constraints2.anchor = GridBagConstraints.CENTER;

                SingleColdWalletFrom coldWalletFrom = new SingleColdWalletFrom(loopPerWalletModelData, this);
                coldWalletFrom.getPanel().setComponentOrientation(ComponentOrientation
                        .getOrientation(LocaliserUtils.getLocale()));


                outerPanel.add(coldWalletFrom.getPanel(), constraints2);


                walletListPanel.add(outerPanel, constraints);
                walletPanels.add(coldWalletFrom);
                constraints.gridy = constraints.gridy + 1;

            }
        }
    }


}
 
Example 26
Source Project: bither-android   Source File: DialogSelectChangeAddress.java    License: Apache License 2.0 5 votes vote down vote up
public DialogSelectChangeAddress(Context context, Address fromAddress) {
    super(context);
    this.fromAddress = fromAddress;
    this.changeAddress = fromAddress;
    setContentView(R.layout.dialog_select_change_address);
    fl = (FrameLayout) findViewById(R.id.fl);
    lv = (ListView) findViewById(R.id.lv);
    lv.setAdapter(adapter);
}
 
Example 27
Source Project: bither-android   Source File: AddressProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void insertAddressToDb(IDb db, Address address) {
    AndroidDb mdb = (AndroidDb)db;
    ContentValues cv = new ContentValues();
    cv.put(AbstractDb.AddressesColumns.ADDRESS, address.getAddress());
    if (address.hasPrivKey()) {
        cv.put(AbstractDb.AddressesColumns.ENCRYPT_PRIVATE_KEY, address.getEncryptPrivKeyOfDb());
    }
    cv.put(AbstractDb.AddressesColumns.PUB_KEY, Base58.encode(address.getPubKey()));
    cv.put(AbstractDb.AddressesColumns.IS_XRANDOM, address.isFromXRandom() ? 1 : 0);
    cv.put(AbstractDb.AddressesColumns.IS_SYNCED, address.isSyncComplete() ? 1 : 0);
    cv.put(AbstractDb.AddressesColumns.IS_TRASH, address.isTrashed() ? 1 : 0);
    cv.put(AbstractDb.AddressesColumns.SORT_TIME, address.getSortTime());
    mdb.getSQLiteDatabase().insert(AbstractDb.Tables.Addresses, null, cv);
}
 
Example 28
Source Project: bitherj   Source File: PrivateKeyUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static List<Address> getECKeysFromBackupString(String str, CharSequence password) {
    String[] strs = QRCodeUtil.splitOfPasswordSeed(str);
    if (strs.length % 3 != 0) {
        log.error("Backup: PrivateKeyFromString format error");
        return null;
    }
    ArrayList<Address> list = new ArrayList<Address>();
    for (int i = 0;
         i < strs.length;
         i += 3) {
        if (strs[i].indexOf(QRCodeUtil.HDM_QR_CODE_FLAG) == 0) {
            continue;
        }
        if (strs[i].indexOf(QRCodeUtil.HD_QR_CODE_FLAG) == 0){
            continue;
        }
        String encryptedString = strs[i] + QRCodeUtil.QR_CODE_SPLIT + strs[i + 1]
                + QRCodeUtil.QR_CODE_SPLIT + strs[i + 2];
        ECKey key = getECKeyFromSingleString(encryptedString, password);

        if (key == null) {
            return null;
        } else {
            Address address = new Address(key.toAddress(), key.getPubKey(), encryptedString,
                    false, key.isFromXRandom());
            key.clearPrivateKey();
            list.add(address);
        }
    }
    return list;
}
 
Example 29
Source Project: bither-desktop-java   Source File: MenuBar.java    License: Apache License 2.0 5 votes vote down vote up
private void updateTickerInfo() {
    new Thread(new Runnable() {
        @Override
        public void run() {

            long finalEstimatedBalance = 0;
            for (Address address : AddressManager.getInstance().getAllAddresses()) {
                finalEstimatedBalance = finalEstimatedBalance + address.getBalance();
            }
            if (AddressManager.getInstance().getHdAccount() != null) {
                finalEstimatedBalance = finalEstimatedBalance + AddressManager.getInstance().getHdAccount().getBalance();
            }
            final long total = finalEstimatedBalance;
            final String exchange = MarketUtil.getMarketName(UserPreference.getInstance().getDefaultMarket());
            final String currency = UserPreference.getInstance().getDefaultCurrency().getName();
            final Ticker ticker = MarketUtil.getTickerOfDefaultMarket();


            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    updateHeaderOnSwingThread("", total, currency, ticker, exchange);
                }
            });

        }


    }).start();


}
 
Example 30
Source Project: bither-android   Source File: ColdAddressFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_cold_address, container,
            false);
    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            FileUtil.getBackupFileListOfCold();
            FileUtil.getBackupFileOfCold();
        }
    });
    lvPrivate = (ListView) view.findViewById(R.id.lv_address);
    ivNoAddress = view.findViewById(R.id.iv_no_address);
    privates = new ArrayList<Address>();
    mAdapter = new AddressOfColdFragmentListAdapter(getActivity(), privates, this);
    lvPrivate.setAdapter(mAdapter);
    if (AbstractApp.addressIsReady) {
        List<Address> ps = AddressManager.getInstance().getPrivKeyAddresses();
        if (ps != null) {
            privates.addAll(ps);
            mAdapter.notifyDataSetChanged();
        }
    }
    return view;
}