net.bither.bitherj.db.AbstractDb Java Examples

The following examples show how to use net.bither.bitherj.db.AbstractDb. 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: TxProvider.java    From bither-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void insertTxToDb(IDb db, Tx tx) {
    AndroidDb mdb = (AndroidDb)db;
    ContentValues cv = new ContentValues();
    if (tx.getBlockNo() != Tx.TX_UNCONFIRMED) {
        cv.put(AbstractDb.TxsColumns.BLOCK_NO, tx.getBlockNo());
    } else {
        cv.putNull(AbstractDb.TxsColumns.BLOCK_NO);
    }
    cv.put(AbstractDb.TxsColumns.TX_HASH, Base58.encode(tx.getTxHash()));
    cv.put(AbstractDb.TxsColumns.SOURCE, tx.getSource());
    cv.put(AbstractDb.TxsColumns.TX_TIME, tx.getTxTime());
    cv.put(AbstractDb.TxsColumns.TX_VER, tx.getTxVer());
    cv.put(AbstractDb.TxsColumns.TX_LOCKTIME, tx.getTxLockTime());
    mdb.getSQLiteDatabase().insert(AbstractDb.Tables.TXS, null, cv);
}
 
Example #2
Source File: AbstractTxProvider.java    From bitherj with Apache License 2.0 6 votes vote down vote up
public void clearAllTx() {
//        SQLiteDatabase db = mDb.getWritableDatabase();
        IDb db = this.getWriteDb();
        db.beginTransaction();
        this.execUpdate(db, "drop table " + AbstractDb.Tables.TXS + ";", null);
        this.execUpdate(db, "drop table " + AbstractDb.Tables.OUTS + ";", null);
        this.execUpdate(db, "drop table " + AbstractDb.Tables.INS + ";", null);
        this.execUpdate(db, "drop table " + AbstractDb.Tables.ADDRESSES_TXS + ";", null);
        this.execUpdate(db, "drop table " + AbstractDb.Tables.PEERS + ";", null);
        this.execUpdate(db, AbstractDb.CREATE_TXS_SQL, null);
        this.execUpdate(db, AbstractDb.CREATE_TX_BLOCK_NO_INDEX, null);
        this.execUpdate(db, AbstractDb.CREATE_OUTS_SQL, null);
        this.execUpdate(db, AbstractDb.CREATE_OUT_OUT_ADDRESS_INDEX, null);
        this.execUpdate(db, AbstractDb.CREATE_INS_SQL, null);
        this.execUpdate(db, AbstractDb.CREATE_IN_PREV_TX_HASH_INDEX, null);
        this.execUpdate(db, AbstractDb.CREATE_ADDRESSTXS_SQL, null);
        this.execUpdate(db, AbstractDb.CREATE_PEER_SQL, null);
        db.endTransaction();
    }
 
Example #3
Source File: SplitBCCHDAccountMonitoredSendActivity.java    From bither-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void validateValues() {
    boolean isValidAmounts = false;
        btcAmount = AddressManager.getInstance().getAmount(AbstractDb.
                hdAccountAddressProvider.getUnspentOutputByBlockNo(splitCoin.getForkBlockHeight(),AddressManager.getInstance()
                .getHDAccountMonitored().getHdSeedId()));
    if (btcAmount > 0) {
        isValidAmounts = true;
    }
    toAddress = etAddress.getText().toString().trim();
    boolean isValidAddress = Utils.validSplitBitCoinAddress(toAddress,splitCoin);
    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 #4
Source File: AbstractAddressProvider.java    From bitherj with Apache License 2.0 6 votes vote down vote up
@Override
public int maxHDMAddressPubIndex(int hdSeedId) {
    String sql = "select ifnull(max(hd_seed_index),-1)  hd_seed_index from hdm_addresses where hd_seed_id=?  ";
    final int[] maxIndex = {-1};
    this.execQueryOneRecord(sql, new String[]{Integer.toString(hdSeedId)}, new Function<ICursor, Void>() {
        @Nullable
        @Override
        public Void apply(@Nullable ICursor c) {
            int idColumn = c.getColumnIndex(AbstractDb.HDMAddressesColumns.HD_SEED_INDEX);
            if (idColumn != -1) {
                maxIndex[0] = c.getInt(idColumn);
            }
            return null;
        }
    });
    return maxIndex[0];
}
 
Example #5
Source File: AddressDBHelper.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Connection conn) throws SQLException {

    if (hasAddressTables(conn)) {
        return;
    }
    Statement stmt = conn.createStatement();
    stmt.executeUpdate(AbstractDb.CREATE_ADDRESSES_SQL);
    stmt.executeUpdate(AbstractDb.CREATE_HDM_BID_SQL);
    stmt.executeUpdate(AbstractDb.CREATE_HD_SEEDS_SQL);
    stmt.executeUpdate(AbstractDb.CREATE_HDM_ADDRESSES_SQL);
    stmt.executeUpdate(AbstractDb.CREATE_PASSWORD_SEED_SQL);
    stmt.executeUpdate(AbstractDb.CREATE_ALIASES_SQL);
    stmt.executeUpdate(AbstractDb.CREATE_VANITY_ADDRESS_SQL);
    stmt.executeUpdate(AbstractDb.CREATE_HD_ACCOUNT);
    conn.commit();
    stmt.close();
    UserPreference.getInstance().setAddressDbVersion(CURRENT_VERSION);

}
 
Example #6
Source File: AddressProvider.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
@Override
public int maxHDMAddressPubIndex(int hdSeedId) {
    int maxIndex = -1;
    try {
        PreparedStatement statement = this.mDb.getPreparedStatement("select ifnull(max(hd_seed_index),-1)  hd_seed_index from hdm_addresses where hd_seed_id=?  ", new String[]{
                Integer.toString(hdSeedId)
        });
        ResultSet cursor = statement.executeQuery();

        if (cursor.next()) {
            int idColumn = cursor.findColumn(AbstractDb.HDMAddressesColumns.HD_SEED_INDEX);
            if (idColumn != -1) {
                maxIndex = cursor.getInt(idColumn);
            }
        }
        cursor.close();
        statement.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return maxIndex;
}
 
Example #7
Source File: AddressProvider.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
@Override
public List<Integer> getHDSeeds() {
    List<Integer> hdSeedIds = new ArrayList<Integer>();
    try {
        String sql = "select hd_seed_id from hd_seeds";
        PreparedStatement statement = this.mDb.getPreparedStatement(sql, null);
        ResultSet c = statement.executeQuery();

        while (c.next()) {
            int idColumn = c.findColumn(AbstractDb.HDSeedsColumns.HD_SEED_ID);
            if (idColumn != 0) {
                hdSeedIds.add(c.getInt(idColumn));
            }
        }
        c.close();
        statement.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {

    }
    return hdSeedIds;
}
 
Example #8
Source File: HDAccountProvider.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
@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 #9
Source File: AbstractHDAccountAddressProvider.java    From bitherj with Apache License 2.0 6 votes vote down vote up
@Override
public HashSet<String> getBelongAccountAddresses(List<String> addressList) {
    final HashSet<String> addressSet = new HashSet<String>();

    List<String> temp = new ArrayList<String>();
    if (addressList != null) {
        for (String str : addressList) {
            temp.add(Utils.format("'%s'", str));
        }
    }
    String sql = Utils.format("select address from hd_account_addresses where address in (%s) "
            , Utils.joinString(temp, ","));
    this.execQueryLoop(sql, null, new Function<ICursor, Void>() {
        @Nullable
        @Override
        public Void apply(@Nullable ICursor c) {
            int idColumn = c.getColumnIndex(AbstractDb.HDAccountAddressesColumns.ADDRESS);
            if (idColumn != -1) {
                addressSet.add(c.getString(idColumn));
            }
            return null;
        }
    });
    return addressSet;
}
 
Example #10
Source File: AddressProvider.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
@Override
public String getHDAccountEncryptSeed(int hdSeedId) {
    String hdAccountEncryptSeed = null;
    try {
        PreparedStatement statement = this.mDb.getPreparedStatement("select " + AbstractDb.HDAccountColumns.ENCRYPT_SEED + " from hd_account where hd_account_id=? "
                , new String[]{Integer.toString(hdSeedId)});
        ResultSet c = statement.executeQuery();
        if (c.next()) {
            int idColumn = c.findColumn(AbstractDb.HDAccountColumns.ENCRYPT_SEED);
            if (idColumn != -1) {
                hdAccountEncryptSeed = c.getString(idColumn);
            }
        }
        c.close();
        statement.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return hdAccountEncryptSeed;

}
 
Example #11
Source File: AbstractTxProvider.java    From bitherj with Apache License 2.0 6 votes vote down vote up
@Override
public long sentFromAddress(byte[] txHash, String address) {
    String sql = "select  sum(o.out_value) out_value from ins i,outs o where" +
            " i.tx_hash=? and o.tx_hash=i.prev_tx_hash and i.prev_out_sn=o.out_sn and o.out_address=?";
    final long[] sum = {0};
    this.execQueryOneRecord(sql, new String[]{Base58.encode(txHash), address}, new Function<ICursor, Void>() {
        @Nullable
        @Override
        public Void apply(@Nullable ICursor c) {
            int idColumn = c.getColumnIndex(AbstractDb.OutsColumns.OUT_VALUE);
            if (idColumn != -1) {
                sum[0] = c.getLong(idColumn);
            }
            return null;
        }
    });
    return sum[0];
}
 
Example #12
Source File: AddressProvider.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
@Override
public String getEncryptHDSeed(int hdSeedId) {
    String encryptHDSeed = null;

    try {
        String sql = "select encrypt_hd_seed from hd_seeds where hd_seed_id=?";
        PreparedStatement statement = this.mDb.getPreparedStatement(sql, new String[]{Integer.toString(hdSeedId)});
        ResultSet c = statement.executeQuery();
        if (c.next()) {
            int idColumn = c.findColumn(AbstractDb.HDSeedsColumns.ENCRYPT_HD_SEED);
            if (idColumn != -1) {
                encryptHDSeed = c.getString(idColumn);
            }
        }
        c.close();
        statement.close();
    } catch (SQLException ex) {
        ex.printStackTrace();
    }
    return encryptHDSeed;
}
 
Example #13
Source File: TxProvider.java    From bither-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void insertOutToDb(IDb db, Out out) {
    AndroidDb mdb = (AndroidDb)db;
    ContentValues cv = new ContentValues();
    cv.put(AbstractDb.OutsColumns.TX_HASH, Base58.encode(out.getTxHash()));
    cv.put(AbstractDb.OutsColumns.OUT_SN, out.getOutSn());
    cv.put(AbstractDb.OutsColumns.OUT_SCRIPT, Base58.encode(out.getOutScript()));
    cv.put(AbstractDb.OutsColumns.OUT_VALUE, out.getOutValue());
    cv.put(AbstractDb.OutsColumns.OUT_STATUS, out.getOutStatus().getValue());
    if (!Utils.isEmpty(out.getOutAddress())) {
        cv.put(AbstractDb.OutsColumns.OUT_ADDRESS, out.getOutAddress());
    } else {
        cv.putNull(AbstractDb.OutsColumns.OUT_ADDRESS);
    }
    //support hd
    if (out.getHDAccountId() != -1) {
        cv.put(AbstractDb.OutsColumns.HD_ACCOUNT_ID,
                out.getHDAccountId());
    } else {
        cv.putNull(AbstractDb.OutsColumns.HD_ACCOUNT_ID);
    }
    mdb.getSQLiteDatabase().insert(AbstractDb.Tables.OUTS, null, cv);
}
 
Example #14
Source File: HDAccountProvider.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
@Override
public String externalAddress() {
    String address = null;
    try {
        PreparedStatement statement = this.mDb.getPreparedStatement("select address from " + AbstractDb.Tables.HD_ACCOUNT_ADDRESS
                        + " where path_type=? and is_issued=? order by address_index asc limit 1 ",
                new String[]{Integer.toString(AbstractHD.PathType.EXTERNAL_ROOT_PATH.getValue()), "0"});
        ResultSet cursor = statement.executeQuery();
        if (cursor.next()) {
            int idColumn = cursor.findColumn(AbstractDb.HDAccountAddressesColumns.ADDRESS);
            if (idColumn != -1) {
                address = cursor.getString(idColumn);
            }
        }
        cursor.close();
        statement.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return address;
}
 
Example #15
Source File: AbstractHDAccountAddressProvider.java    From bitherj with Apache License 2.0 6 votes vote down vote up
@Override
public List<byte[]> getPubs(int hdAccountId, AbstractHD.PathType pathType) {
    String sql = "select pub from hd_account_addresses where path_type=? and hd_account_id=?";
    final List<byte[]> adressPubList = new ArrayList<byte[]>();
    this.execQueryLoop(sql, new String[]{Integer.toString(pathType.getValue()), Integer.toString(hdAccountId)}, new Function<ICursor, Void>() {
        @Nullable
        @Override
        public Void apply(@Nullable ICursor c) {
            int idColumn = c.getColumnIndex(AbstractDb.HDAccountAddressesColumns.PUB);
            if (idColumn != -1) {
                try {
                    adressPubList.add(Base58.decode(c.getString(idColumn)));
                } catch (AddressFormatException e) {
                    e.printStackTrace();
                }
            }
            return null;
        }
    });
    return adressPubList;
}
 
Example #16
Source File: AddressProvider.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isHDSeedFromXRandom(int hdSeedId) {
    boolean isXRandom = false;
    try {
        PreparedStatement statement = this.mDb.getPreparedStatement("select is_xrandom from hd_seeds where hd_seed_id=?"
                , new String[]{Integer.toString(hdSeedId)});
        ResultSet cursor = statement.executeQuery();
        if (cursor.next()) {
            int idColumn = cursor.findColumn(AbstractDb.HDSeedsColumns.IS_XRANDOM);
            if (idColumn != -1) {
                isXRandom = cursor.getInt(idColumn) == 1;
            }
        }
        cursor.close();
        statement.close();
    } catch (SQLException ex) {
        ex.printStackTrace();
    }
    return isXRandom;
}
 
Example #17
Source File: HDAccountProvider.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
@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 #18
Source File: AddressProvider.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
@Override
public int maxHDMAddressPubIndex(int hdSeedId) {
    int maxIndex = -1;
    try {
        PreparedStatement statement = this.mDb.getPreparedStatement("select ifnull(max(hd_seed_index),-1)  hd_seed_index from hdm_addresses where hd_seed_id=?  ", new String[]{
                Integer.toString(hdSeedId)
        });
        ResultSet cursor = statement.executeQuery();

        if (cursor.next()) {
            int idColumn = cursor.findColumn(AbstractDb.HDMAddressesColumns.HD_SEED_INDEX);
            if (idColumn != -1) {
                maxIndex = cursor.getInt(idColumn);
            }
        }
        cursor.close();
        statement.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return maxIndex;
}
 
Example #19
Source File: AddressProvider.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
@Override
public List<Integer> getHDAccountSeeds() {
    List<Integer> hdSeedIds = new ArrayList<Integer>();

    try {

        String sql = "select " + AbstractDb.HDAccountColumns.HD_ACCOUNT_ID + " from " + AbstractDb.Tables.HD_ACCOUNT;
        PreparedStatement statement = this.mDb.getPreparedStatement(sql, null);
        ResultSet c = statement.executeQuery();
        while (c.next()) {
            int idColumn = c.findColumn(AbstractDb.HDAccountColumns.HD_ACCOUNT_ID);
            if (idColumn != -1) {
                hdSeedIds.add(c.getInt(idColumn));
            }
        }
        c.close();
        statement.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return hdSeedIds;
}
 
Example #20
Source File: AddressManager.java    From bitherj with Apache License 2.0 6 votes vote down vote up
private void initAddress() {
    List<Address> addressList = AbstractDb.addressProvider.getAddresses();
    for (Address address : addressList) {

        if (address.hasPrivKey()) {
            if (address.isTrashed()) {
                this.trashAddresses.add(address);
            } else {
                this.privKeyAddresses.add(address);
                this.addressHashSet.add(address.getAddress());
            }
        } else {
            this.watchOnlyAddresses.add(address);
            this.addressHashSet.add(address.getAddress());
        }

    }
}
 
Example #21
Source File: OptionHotFragment.java    From bither-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    if (AppSharedPreference.getInstance().isSegwitAddressType()) {
        changeAddressType(false);
        return;
    }
    final AddressManager addressManager = AddressManager.getInstance();
    if (addressManager.hasHDAccountHot()) {
        if (addressManager.hasHDAccountMonitored() && AbstractDb.hdAccountProvider.getSegwitExternalPub(addressManager.getHDAccountMonitored().getHdSeedId()) == null) {
            DialogConfirmTask tip = new DialogConfirmTask(getActivity(), getString(R.string.address_type_switch_hd_account_cold_no_segwit_pub_tips), new Runnable() {
                @Override
                public void run() {
                    ThreadUtil.runOnMainThread(new Runnable() {
                        @Override
                        public void run() {
                            changeAddressType(false);
                        }
                    });
                }
            }, false);
            tip.setCancelable(false);
            tip.show();
        } else {
            if (addressManager.getHDAccountHot().getExternalPub(AbstractHD.PathType.EXTERNAL_BIP49_PATH) == null) {
                changeAddressType(true);
            } else {
                changeAddressType(false);
            }
        }
    } else if (addressManager.hasHDAccountMonitored()) {
        if (AbstractDb.hdAccountProvider.getSegwitExternalPub(addressManager.getHDAccountMonitored().getHdSeedId()) == null) {
            DropdownMessage.showDropdownMessage(getActivity(), getString(R.string.address_type_switch_hd_account_cold_no_segwit_pub_tips));
        } else {
            changeAddressType(false);
        }
    } else {
        DropdownMessage.showDropdownMessage(getActivity(), getString(R.string.open_segwit_only_support_hd_account));
    }
}
 
Example #22
Source File: Tx.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public long deltaAmountFrom(Address address) {
    if (address instanceof HDAccount) {
        return deltaAmountFrom((HDAccount) address);
    }
    long receive = 0;
    for (Out out : this.outs) {
        if (Utils.compareString(address.getAddress(), out.getOutAddress())) {
            receive += out.getOutValue();
        }
    }
    long sent = AbstractDb.txProvider.sentFromAddress(getTxHash(), address.getAddress());
    return receive - sent;
}
 
Example #23
Source File: AbstractPeerProvider.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public void recreate() {
    IDb writeDb = this.getWriteDb();
    writeDb.beginTransaction();
    this.execUpdate(writeDb, "drop table peers", null);
    this.execUpdate(writeDb, AbstractDb.CREATE_PEER_SQL, null);
    writeDb.endTransaction();
}
 
Example #24
Source File: AddressManager.java    From bitherj with Apache License 2.0 5 votes vote down vote up
private boolean isSendFromHDAccount(Tx tx, Map<Sha256Hash, Tx> txHashList) {
    List<String> inAddressList = new ArrayList<String>();
    for (In in : tx.getIns()) {
        Sha256Hash prevTxHahs = new Sha256Hash(in.getPrevTxHash());
        if (txHashList.containsKey(prevTxHahs)) {
            Tx preTx = txHashList.get(prevTxHahs);
            for (Out out : preTx.getOuts()) {
                if (out.getOutSn() == in.getPrevOutSn()) {
                    inAddressList.add(out.getOutAddress());
                }
            }
        }
    }
    return AbstractDb.hdAccountAddressProvider.getRelatedAddressCnt(inAddressList) > 0;
}
 
Example #25
Source File: AbstractHDAccountProvider.java    From bitherj with Apache License 2.0 5 votes vote down vote up
@Override
    public byte[] getExternalPub(int hdSeedId) {
        final byte[][] pub = {null};
        String sql = "select external_pub from hd_account where hd_account_id=?";
        this.execQueryOneRecord(sql, new String[]{Integer.toString(hdSeedId)}, new Function<ICursor, Void>() {
            @Nullable
            @Override
            public Void apply(@Nullable ICursor c) {
                int idColumn = c.getColumnIndex(AbstractDb.HDAccountColumns.EXTERNAL_PUB);
                if (idColumn != -1) {
                    String pubStr = c.getString(idColumn);
                    try {
                        pub[0] = Base58.decode(pubStr);
                    } catch (AddressFormatException e) {
                        e.printStackTrace();
                    }
                }
                return null;
            }
        });
        return pub[0];

//        try {
//            SQLiteDatabase db = this.mDb.getReadableDatabase();
//            Cursor c = db.rawQuery("select external_pub from hd_account where hd_account_id=? "
//                    , new String[]{Integer.toString(hdSeedId)});
//            if (c.moveToNext()) {
//                int idColumn = c.getColumnIndex(AbstractDb.HDAccountColumns.EXTERNAL_PUB);
//                if (idColumn != -1) {
//                    String pubStr = c.getString(idColumn);
//                    pub = Base58.decode(pubStr);
//                }
//            }
//            c.close();
//        } catch (AddressFormatException e) {
//            e.printStackTrace();
//        }
//
//        return pub;
    }
 
Example #26
Source File: EnterpriseHDMProvider.java    From bither-android with Apache License 2.0 5 votes vote down vote up
@Override
public void addEnterpriseHDMAddress(List<EnterpriseHDMAddress> enterpriseHDMAddressList) {

    SQLiteDatabase db = this.mDb.getWritableDatabase();
    db.beginTransaction();
    for (EnterpriseHDMAddress enterpriseHDMAddress : enterpriseHDMAddressList) {
        ContentValues cv = applyContentValues(enterpriseHDMAddress);
        db.insert(AbstractDb.Tables.ENTERPRISE_HDM_ADDRESS, null, cv);
    }
    db.setTransactionSuccessful();
    db.endTransaction();

}
 
Example #27
Source File: HDMBId.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public byte[] decryptHDMBIdPassword(CharSequence password) {
    HDMBId hdmbId = AbstractDb.addressProvider.getHDMBId();
    if (!Utils.isEmpty(hdmbId.getEncryptedBitherPasswordString())) {
        encryptedBitherPassword = new EncryptedData(hdmbId.getEncryptedBitherPasswordString());
    }
    decryptedPassword = encryptedBitherPassword.decrypt(password);
    return decryptedPassword;
}
 
Example #28
Source File: HDAccount.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public Tx newTx(String[] toAddresses, Long[] amounts) throws TxBuilderException,
        MnemonicException.MnemonicLengthException {
    List<Out> outs = AbstractDb.hdAccountAddressProvider.getUnspendOutByHDAccount(hdSeedId);
    Tx tx = TxBuilder.getInstance().buildTxFromAllAddress(outs, getNewChangeAddress(), Arrays
            .asList(amounts), Arrays.asList(toAddresses));
    return tx;
}
 
Example #29
Source File: HDAccount.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public int elementCountForBloomFilter() {
    return allGeneratedExternalAddressCount() * 2 + AbstractDb.hdAccountAddressProvider
            .getUnspendOutCountByHDAccountWithPath(getHdSeedId(), AbstractHD.PathType
                    .INTERNAL_ROOT_PATH) + AbstractDb.hdAccountAddressProvider
            .getUnconfirmedSpentOutCountByHDAccountWithPath(getHdSeedId(), AbstractHD
                    .PathType.INTERNAL_ROOT_PATH);
}
 
Example #30
Source File: BitpieHDAccountProvider.java    From bither-android with Apache License 2.0 5 votes vote down vote up
@Override
protected int insertMonitorHDAccountToDb(IDb db, String firstAddress, boolean isXrandom, byte[] externalPub, byte[] internalPub) {
    AndroidDb mdb = (AndroidDb)db;
    ContentValues cv = new ContentValues();
    cv.put(AbstractDb.HDAccountColumns.HD_ADDRESS, firstAddress);
    cv.put(AbstractDb.HDAccountColumns.IS_XRANDOM, isXrandom ? 1 : 0);
    cv.put(AbstractDb.HDAccountColumns.EXTERNAL_PUB, Base58.encode(externalPub));
    cv.put(AbstractDb.HDAccountColumns.INTERNAL_PUB, Base58.encode(internalPub));
    return (int) mdb.getSQLiteDatabase().insert(AbstractDb.Tables.BITPIE_HD_ACCOUNT, null, cv);
}