Java Code Examples for net.bither.bitherj.core.Address#hasPrivKey()

The following examples show how to use net.bither.bitherj.core.Address#hasPrivKey() . 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: AddressTableModel.java    From bither-desktop-java with 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 File: AddressProvider.java    From bither-desktop-java with 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 3
Source File: CommitTransactionThread.java    From bither-android with Apache License 2.0 6 votes vote down vote up
public CommitTransactionThread(DialogProgress dp, int addressPosition, Tx tx, boolean isHDM,
                               boolean withPrivateKey, CommitTransactionListener listener)
        throws Exception {
    super(dp, dp.getContext());
    this.addressPosition = addressPosition;
    this.listener = listener;
    if (isHDM) {
        wallet = AddressManager.getInstance().getHdmKeychain().getAddresses().get
                (addressPosition);
    } else if (withPrivateKey) {
        Address a = AddressManager.getInstance().getPrivKeyAddresses().get(addressPosition);
        if (a.hasPrivKey()) {
            wallet = a;
        } else {
            throw new Exception("address not with private key");
        }
    } else {
        wallet = AddressManager.getInstance().getWatchOnlyAddresses().get(addressPosition);
    }
    this.tx = tx;
}
 
Example 4
Source File: AddressTableModel.java    From bither-desktop-java with 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 5
Source File: AddressProvider.java    From bither-desktop-java with 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 6
Source File: CompleteTransactionRunnable.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public CompleteTransactionRunnable(Address a, long amount, String toAddress,
                                   String changeAddress, SecureCharSequence password,
                                   HDMAddress.HDMFetchOtherSignatureDelegate
                                           otherSigFetcher1,
                                   HDMAddress.HDMFetchOtherSignatureDelegate
                                           otherSigFetcher2) throws Exception {
    boolean isHDM = otherSigFetcher1 != null || otherSigFetcher2 != null;
    this.amount = amount;
    this.toAddress = toAddress;
    this.password = password;
    sigFetcher1 = otherSigFetcher1;
    sigFetcher2 = otherSigFetcher2;
    if (isHDM) {
        wallet = a;
        toSign = true;
    } else if (password == null || password.length() == 0) {
        wallet = a;
        toSign = false;
    } else {
        if (a.hasPrivKey()) {
            wallet = a;
        } else {
            throw new Exception("address not with private key");
        }
        toSign = true;
    }
    if (!Utils.isEmpty(changeAddress)) {
        this.changeAddress = changeAddress;
    } else {
        this.changeAddress = wallet.getAddress();
    }
}
 
Example 7
Source File: DialogSelectChangeAddress.java    From bither-android with Apache License 2.0 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (inflater == null) {
        inflater = LayoutInflater.from(getContext());
    }
    ViewHolder h;
    if (convertView != null && convertView.getTag() != null && convertView.getTag()
            instanceof ViewHolder) {
        h = (ViewHolder) convertView.getTag();
    } else {
        convertView = inflater.inflate(R.layout.list_item_select_change_address, null);
        h = new ViewHolder(convertView);
        convertView.setTag(h);
    }
    Address a = getItem(position);
    h.tvAddress.setText(a.getShortAddress());
    if (a.isHDM()) {
        h.ivType.setImageResource(R.drawable.address_type_hdm);
    } else if (a.hasPrivKey()) {
        h.ivType.setImageResource(R.drawable.address_type_private);
    } else {
        h.ivType.setImageResource(R.drawable.address_type_watchonly);
    }
    if (a.equals(changeAddress)) {
        h.ivCheck.setVisibility(View.VISIBLE);
    } else {
        h.ivCheck.setVisibility(View.INVISIBLE);
    }
    convertView.setOnClickListener(new ListItemClick(a));
    return convertView;
}
 
Example 8
Source File: AddressProvider.java    From bither-android with 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 9
Source File: HotActivity.java    From bither-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == BitherSetting.INTENT_REF.SCAN_REQUEST_CODE && resultCode == RESULT_OK) {
        ArrayList<String> addresses = (ArrayList<String>) data.getExtras().getSerializable
                (BitherSetting.INTENT_REF.ADDRESS_POSITION_PASS_VALUE_TAG);
        if (addresses != null && addresses.size() > 0) {
            Address a = WalletUtils.findPrivateKey(addresses.get(0));
            if (a != null && a.hasPrivKey() && !a.isFromXRandom()) {
                new DialogGenerateAddressFinalConfirm(this, addresses.size(),
                        a.isFromXRandom()).show();
            }

            Fragment f = getFragmentAtIndex(1);
            if (f != null && f instanceof HotAddressFragment) {
                mPager.setCurrentItem(1, true);
                HotAddressFragment af = (HotAddressFragment) f;
                af.showAddressesAdded(addresses);
            }
            if (f != null && f instanceof Refreshable) {
                Refreshable r = (Refreshable) f;
                r.doRefresh();
            }
        }
        return;
    }

    if (requestCode == SelectAddressToSendActivity.SEND_REQUEST_CODE && resultCode ==
            RESULT_OK) {
        DropdownMessage.showDropdownMessage(this, R.string.donate_thanks);
    }
    super.onActivityResult(requestCode, resultCode, data);
}
 
Example 10
Source File: KeyUtil.java    From bither-android with 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 11
Source File: AbstractAddressProvider.java    From bitherj with 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 12
Source File: CompleteTransactionRunnable.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public CompleteTransactionRunnable(Address a, long amount, String toAddress,
                                   String changeAddress, SecureCharSequence password,
                                   HDMAddress.HDMFetchOtherSignatureDelegate
                                           otherSigFetcher1,
                                   HDMAddress.HDMFetchOtherSignatureDelegate
                                           otherSigFetcher2) throws Exception {
    boolean isHDM = otherSigFetcher1 != null || otherSigFetcher2 != null;
    this.amount = amount;
    this.toAddress = toAddress;
    this.password = password;
    sigFetcher1 = otherSigFetcher1;
    sigFetcher2 = otherSigFetcher2;
    if (isHDM) {
        wallet = a;
        toSign = true;
    } else if (password == null || password.length() == 0) {
        wallet = a;
        toSign = false;
    } else {
        if (a.hasPrivKey()) {
            wallet = a;
        } else {
            throw new Exception("address not with private key");
        }
        toSign = true;
    }
    if (!Utils.isEmpty(changeAddress)) {
        this.changeAddress = changeAddress;
    } else {
        this.changeAddress = wallet.getAddress();
    }
}
 
Example 13
Source File: AddressDetailHeader.java    From bither-android with Apache License 2.0 4 votes vote down vote up
public void showAddress(final Address address, int addressPosition, boolean isSegwitAddress) {
        this.addressPosition = addressPosition;
        String addrStr;
        if (address.isHDAccount()) {
            addrStr = address.getAddress(isSegwitAddress);
        } else {
            addrStr = address.getAddress();
        }
        if (addrStr == null) {
            return;
        }
        tvAddress.setText(WalletUtils.formatHash(addrStr,4,12));
        if (!Utils.compareString(strAddress, addrStr)) {
            Qr.QrCodeTheme theme = AppSharedPreference.getInstance().getFancyQrCodeTheme();
            ivQr.setContent(addrStr, theme.getFgColor(), theme.getBgColor());
        }
        strAddress = addrStr;
        llMore.setVisibility(View.VISIBLE);
        if (address.txCount() == 0) {
            tvNoTransactions.setVisibility(View.VISIBLE);
        } else {
            tvNoTransactions.setVisibility(View.GONE);
        }
        btnBalance.setAmount(address.getBalance());
        if ((address.isHDM() && !(address instanceof EnterpriseHDMAddress)) || address.hasPrivKey
                ()) {
            btnSend.setCompoundDrawables(null, null, null, null);
        } else {
            Drawable d = getContext().getResources().getDrawable(R.drawable
                    .unsigned_transaction_button_icon);
            int size = UIUtil.dip2pix(20);
            int topOffset = UIUtil.dip2pix(0.5f);
            d.setBounds(0, topOffset, size, size + topOffset);
            btnSend.setCompoundDrawables(null, null, d, null);
        }
//        } else {
//            llMore.setVisibility(View.GONE);
//        }
        llMonitorFailed.setVisibility(View.GONE);
//        } else {
//            llMore.setVisibility(View.GONE);
//            tvNoTransactions.setVisibility(View.GONE);
//            llMonitorFailed.setVisibility(View.VISIBLE);
//        }
        if (address.isHDAccount()) {
            ibtnBalanceDetail.setVisibility(View.GONE);
        } else {
            ibtnBalanceDetail.setVisibility(View.VISIBLE);
        }
        this.address = address;
        if(balanceDetailFuture != null){
            balanceDetailFuture.cancel(true);
        }
        balanceDetailFuture = new FutureTask<DialogBalanceDetail.Info>(getBalanceInfo);
        new Thread(balanceDetailFuture).start();
    }