net.bither.bitherj.core.Out Java Examples

The following examples show how to use net.bither.bitherj.core.Out. 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: AbstractHDAccountAddressProvider.java    From bitherj with Apache License 2.0 6 votes vote down vote up
@Override
public int getUnspendOutCountByHDAccountWithPath(int hdAccountId, AbstractHD.PathType
        pathType) {
    final int[] result = {0};
    String sql = "select count(tx_hash) cnt from outs where out_address in " +
            "(select address from hd_account_addresses where path_type =? and out_status=?) " +
            "and hd_account_id=?";
    this.execQueryOneRecord(sql, new String[]{Integer.toString(pathType.getValue())
            , Integer.toString(Out.OutStatus.unspent.getValue())
            , Integer.toString(hdAccountId)
    }, new Function<ICursor, Void>() {
        @Nullable
        @Override
        public Void apply(@Nullable ICursor c) {
            int idColumn = c.getColumnIndex("cnt");
            if (idColumn != -1) {
                result[0] = c.getInt(idColumn);
            }
            return null;
        }
    });
    return result[0];
}
 
Example #2
Source File: TxProvider.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
@Override
public long getConfirmedBalanceWithAddress(String address) {
    long sum = 0;
    try {

        String unspendOutSql = "select ifnull(sum(a.out_value),0) sum from outs a,txs b where a.tx_hash=b.tx_hash " +
                " and a.out_address=? and a.out_status=? and b.block_no is not null";
        PreparedStatement statement = this.mDb.getPreparedStatement(unspendOutSql,
                new String[]{address, Integer.toString(Out.OutStatus.unspent.getValue())});
        ResultSet c = statement.executeQuery();
        if (c.next()) {
            int idColumn = c.findColumn("sum");
            if (idColumn != -1) {
                sum = c.getLong(idColumn);
            }
        }
        c.close();
        statement.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return sum;
}
 
Example #3
Source File: TxHelper.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
public static void addInsAndOuts(TxDBHelper mDb, Tx txItem) throws AddressFormatException, SQLException {
    String txHashStr = Base58.encode(txItem.getTxHash());
    txItem.setOuts(new ArrayList<Out>());
    txItem.setIns(new ArrayList<In>());
    String sql = "select * from ins where tx_hash=? order by in_sn";
    PreparedStatement statement = mDb.getPreparedStatement(sql, new String[]{txHashStr});
    ResultSet c = statement.executeQuery();
    while (c.next()) {
        In inItem = TxHelper.applyCursorIn(c);
        inItem.setTx(txItem);
        txItem.getIns().add(inItem);
    }
    c.close();
    statement.close();

    sql = "select * from outs where tx_hash=? order by out_sn";
    statement = mDb.getPreparedStatement(sql, new String[]{txHashStr});
    c = statement.executeQuery();
    while (c.next()) {
        Out outItem = TxHelper.applyCursorOut(c);
        outItem.setTx(txItem);
        txItem.getOuts().add(outItem);
    }
    c.close();
    statement.close();
}
 
Example #4
Source File: WalletUtils.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
public static boolean isInternal(@Nonnull final Tx tx) {
    if (tx.isCoinBase()) {
        return false;
    }

    final List<Out> outputs = tx.getOuts();
    if (outputs.size() != 1) {
        return false;
    }

    try {
        final Out output = outputs.get(0);
        final Script scriptPubKey = output.getScriptPubKey();
        if (!scriptPubKey.isSentToRawPubKey()) {
            return false;
        }

        return true;
    } catch (final ScriptException x) {
        return false;
    }
}
 
Example #5
Source File: AbstractTxProvider.java    From bitherj with Apache License 2.0 6 votes vote down vote up
public long getConfirmedBalanceWithAddress(String address) {
    final long[] sum = {0};
    String unspendOutSql = "select ifnull(sum(a.out_value),0) sum from outs a,txs b where a.tx_hash=b.tx_hash " +
            " and a.out_address=? and a.out_status=? and b.block_no is not null";
    this.execQueryOneRecord(unspendOutSql, new String[]{address, Integer.toString(Out.OutStatus.unspent.getValue())}, new Function<ICursor, Void>() {
        @Nullable
        @Override
        public Void apply(@Nullable ICursor c) {
            int idColumn = c.getColumnIndex("sum");
            if (idColumn != -1) {
                sum[0] = c.getLong(idColumn);
            }
            return null;
        }
    });
    return sum[0];
}
 
Example #6
Source File: AbstractTxProvider.java    From bitherj with Apache License 2.0 6 votes vote down vote up
private void addOutForTxDetail(IDb db, String address, final HashMap<Sha256Hash, Tx> txDict) {
    String sql = "select b.* from addresses_txs a, outs b where a.tx_hash=b.tx_hash and a.address=? "
            + "order by b.tx_hash,b.out_sn";
    this.execQueryLoop(db, sql, new String[]{address}, new Function<ICursor, Void>() {
        @Nullable
        @Override
        public Void apply(@Nullable ICursor c) {
            Out out = applyCursorOut(c);
            Tx tx = txDict.get(new Sha256Hash(out.getTxHash()));
            if (tx != null) {
                tx.getOuts().add(out);
            }
            return null;
        }
    });
}
 
Example #7
Source File: AbstractTxProvider.java    From bitherj with Apache License 2.0 6 votes vote down vote up
@Override
public List<Tx> getTxAndDetailByAddress(String address) {
    final List<Tx> txItemList = new ArrayList<Tx>();
    final HashMap<Sha256Hash, Tx> txDict = new HashMap<Sha256Hash, Tx>();
    String sql = "select b.* from addresses_txs a, txs b" +
            " where a.tx_hash=b.tx_hash and a.address=? order by ifnull(b.block_no,4294967295) desc";
    IDb db = this.getReadDb();
    this.execQueryLoop(db, sql, new String[]{address}, new Function<ICursor, Void>() {
        @Nullable
        @Override
        public Void apply(@Nullable ICursor c) {
            Tx txItem = applyCursor(c);
            txItem.setIns(new ArrayList<In>());
            txItem.setOuts(new ArrayList<Out>());
            txItemList.add(txItem);
            txDict.put(new Sha256Hash(txItem.getTxHash()), txItem);
            return null;
        }
    });
    addInForTxDetail(db, address, txDict);
    addOutForTxDetail(db, address, txDict);

    return txItemList;
}
 
Example #8
Source File: AbstractHDAccountAddressProvider.java    From bitherj with Apache License 2.0 6 votes vote down vote up
@Override
public List<Out> getUnconfirmedSpentOutByHDAccountWithPath(int hdAccountId, AbstractHD.PathType
        pathType) {
    String sql = "select o.* from outs o, ins i, txs t, hd_account_addresses a " +
            "  where o.tx_hash=i.prev_tx_hash and o.out_sn=i.prev_out_sn and t.tx_hash=i.tx_hash " +
            "    and o.out_address=a.address and a.path_type=?" +
            "    and o.out_status=? and t.block_no is null and a.hd_account_id=?";
    final List<Out> outList = new ArrayList<Out>();
    this.execQueryLoop(sql, new String[]{Integer.toString(pathType.getValue())
            , Integer.toString(Out.OutStatus.spent.getValue())
            , Integer.toString(hdAccountId)
    }, new Function<ICursor, Void>() {
        @Nullable
        @Override
        public Void apply(@Nullable ICursor c) {
            outList.add(AbstractTxProvider.applyCursorOut(c));
            return null;
        }
    });
    return outList;
}
 
Example #9
Source File: AbstractHDAccountAddressProvider.java    From bitherj with Apache License 2.0 6 votes vote down vote up
@Override
public int getUnconfirmedSpentOutCountByHDAccountWithPath(int hdAccountId, AbstractHD.PathType
        pathType) {
    final int[] result = {0};
    String sql = "select count(0) cnt from outs o, ins i, txs t, hd_account_addresses a " +
            "  where o.tx_hash=i.prev_tx_hash and o.out_sn=i.prev_out_sn and t.tx_hash=i.tx_hash " +
            "    and o.out_address=a.address and a.path_type=?" +
            "    and o.out_status=? and t.block_no is null and a.hd_account_id=?";
    this.execQueryOneRecord(sql, new String[]{Integer.toString(pathType.getValue())
            , Integer.toString(Out.OutStatus.spent.getValue())
            , Integer.toString(hdAccountId)
    }, new Function<ICursor, Void>() {
        @Nullable
        @Override
        public Void apply(@Nullable ICursor c) {
            int idColumn = c.getColumnIndex("cnt");
            if (idColumn != -1) {
                result[0] = c.getInt(idColumn);
            }
            return null;
        }
    });
    return result[0];
}
 
Example #10
Source File: AbstractHDAccountAddressProvider.java    From bitherj with Apache License 2.0 6 votes vote down vote up
@Override
public List<Out> getUnspendOutByHDAccountWithPath(int hdAccountId, AbstractHD.PathType
        pathType) {
    String sql = "select * from outs where out_address in " +
            "(select address from hd_account_addresses where path_type =? and " +
            "out_status=?) " +
            "and hd_account_id=?";
    final List<Out> outList = new ArrayList<Out>();
    this.execQueryLoop(sql, new String[]{Integer.toString(pathType.getValue())
            , Integer.toString(Out.OutStatus.unspent.getValue())
            , Integer.toString(hdAccountId)
    }, new Function<ICursor, Void>() {
        @Nullable
        @Override
        public Void apply(@Nullable ICursor c) {
            outList.add(AbstractTxProvider.applyCursorOut(c));
            return null;
        }
    });
    return outList;
}
 
Example #11
Source File: WalletUtils.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
public static boolean isInternal(@Nonnull final Tx tx) {
    if (tx.isCoinBase()) {
        return false;
    }

    final List<Out> outputs = tx.getOuts();
    if (outputs.size() != 1) {
        return false;
    }

    try {
        final Out output = outputs.get(0);
        final Script scriptPubKey = output.getScriptPubKey();
        if (!scriptPubKey.isSentToRawPubKey()) {
            return false;
        }

        return true;
    } catch (final ScriptException x) {
        return false;
    }
}
 
Example #12
Source File: AbstractHDAccountAddressProvider.java    From bitherj with Apache License 2.0 6 votes vote down vote up
@Override
public long getHDAccountConfirmedBalance(int hdAccountId) {
    final long[] sum = {0};
    String unspendOutSql = "select ifnull(sum(a.out_value),0) sum from outs a,txs b where a" +
            ".tx_hash=b.tx_hash " +
            "  and a.out_status=? and a.hd_account_id=? and b.block_no is not null";
    this.execQueryOneRecord(unspendOutSql, new String[]{Integer.toString(Out.OutStatus.unspent.getValue()), Integer.toString
            (hdAccountId)}, new Function<ICursor, Void>() {
        @Nullable
        @Override
        public Void apply(@Nullable ICursor c) {
            int idColumn = c.getColumnIndex("sum");
            if (idColumn != -1) {
                sum[0] = c.getLong(idColumn);
            }
            return null;
        }
    });
    return sum[0];
}
 
Example #13
Source File: WalletUtils.java    From bither-android with Apache License 2.0 6 votes vote down vote up
public static boolean isInternal(@Nonnull final Tx tx) {
    if (tx.isCoinBase()) {
        return false;
    }

    final List<Out> outputs = tx.getOuts();
    if (outputs.size() != 1) {
        return false;
    }

    try {
        final Out output = outputs.get(0);
        final Script scriptPubKey = output.getScriptPubKey();
        if (!scriptPubKey.isSentToRawPubKey()) {
            return false;
        }

        return true;
    } catch (final ScriptException x) {
        return false;
    }
}
 
Example #14
Source File: DetectAnotherAssetsUtil.java    From bither-android with Apache License 2.0 6 votes vote down vote up
public void getBCCUnspentOutputs(final String address, final int position, final boolean isPrivate) {
    dp.show();
    Runnable BTCUnspentOutputs = new Runnable() {
        @Override
        public void run() {
            UnspentOutputsApi unspentOutputsApi = new UnspentOutputsApi(address);
            try {
                unspentOutputsApi.handleHttpGet();
                JSONArray jsonArray = new JSONArray(unspentOutputsApi.getResult());
                List<ExtractBccUtxo> extractBccUtxos = ExtractBccUtxo.format(jsonArray);
                final List<Out> rawOutList = ExtractBccUtxo.rawOutList(extractBccUtxos);
                extractBcc(extractBccUtxos, rawOutList, address, position, isPrivate);
                dp.dismiss();
            } catch (Exception e) {
                e.printStackTrace();
                dp.dismiss();
            }
        }
    };
    new Thread(BTCUnspentOutputs).start();
}
 
Example #15
Source File: TxHelper.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
public static void addInsAndOuts(TxDBHelper mDb, Tx txItem) throws AddressFormatException, SQLException {
    String txHashStr = Base58.encode(txItem.getTxHash());
    txItem.setOuts(new ArrayList<Out>());
    txItem.setIns(new ArrayList<In>());
    String sql = "select * from ins where tx_hash=? order by in_sn";
    PreparedStatement statement = mDb.getPreparedStatement(sql, new String[]{txHashStr});
    ResultSet c = statement.executeQuery();
    while (c.next()) {
        In inItem = TxHelper.applyCursorIn(c);
        inItem.setTx(txItem);
        txItem.getIns().add(inItem);
    }
    c.close();
    statement.close();

    sql = "select * from outs where tx_hash=? order by out_sn";
    statement = mDb.getPreparedStatement(sql, new String[]{txHashStr});
    c = statement.executeQuery();
    while (c.next()) {
        Out outItem = TxHelper.applyCursorOut(c);
        outItem.setTx(txItem);
        txItem.getOuts().add(outItem);
    }
    c.close();
    statement.close();
}
 
Example #16
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 #17
Source File: DetectAnotherAssetsUtil.java    From bither-android with Apache License 2.0 6 votes vote down vote up
public void getBCCHDUnspentOutputs(final String address, final AbstractHD.PathType path, final int index,
                                   final boolean isMonitored) {
    dp.show();
    Runnable BTCUnspentOutputs = new Runnable() {
        @Override
        public void run() {
            UnspentOutputsApi unspentOutputsApi = new UnspentOutputsApi(address);
            try {
                unspentOutputsApi.handleHttpGet();
                JSONArray jsonArray = new JSONArray(unspentOutputsApi.getResult());
                List<ExtractBccUtxo> extractBccUtxos = ExtractBccUtxo.format(jsonArray);
                final List<Out> rawOutList = ExtractBccUtxo.rawOutList(extractBccUtxos);
                extractHDBcc(extractBccUtxos, rawOutList, path, index,
                        address, isMonitored);
                dp.dismiss();
            } catch (Exception e) {
                e.printStackTrace();
                dp.dismiss();
            }
        }
    };
    new Thread(BTCUnspentOutputs).start();
}
 
Example #18
Source File: TxProvider.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
@Override
public long getConfirmedBalanceWithAddress(String address) {
    long sum = 0;
    try {

        String unspendOutSql = "select ifnull(sum(a.out_value),0) sum from outs a,txs b where a.tx_hash=b.tx_hash " +
                " and a.out_address=? and a.out_status=? and b.block_no is not null";
        PreparedStatement statement = this.mDb.getPreparedStatement(unspendOutSql,
                new String[]{address, Integer.toString(Out.OutStatus.unspent.getValue())});
        ResultSet c = statement.executeQuery();
        if (c.next()) {
            int idColumn = c.findColumn("sum");
            if (idColumn != -1) {
                sum = c.getLong(idColumn);
            }
        }
        c.close();
        statement.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return sum;
}
 
Example #19
Source File: AbstractTxProvider.java    From bitherj with Apache License 2.0 5 votes vote down vote up
@Override
public List<Tx> getUnspendTxWithAddress(String address) {
    String unspendOutSql = "select a.*,b.tx_ver,b.tx_locktime,b.tx_time,b.block_no,b.source,ifnull(b.block_no,0)*a.out_value coin_depth " +
            "from outs a,txs b where a.tx_hash=b.tx_hash" +
            " and a.out_address=? and a.out_status=?";
    final List<Tx> txItemList = new ArrayList<Tx>();

    this.execQueryLoop(unspendOutSql, new String[]{address, Integer.toString(Out.OutStatus.unspent.getValue())}, new Function<ICursor, Void>() {
        @Nullable
        @Override
        public Void apply(@Nullable ICursor c) {
            int idColumn = c.getColumnIndex("coin_depth");

            Tx txItem = applyCursor(c);
            Out outItem = applyCursorOut(c);
            if (idColumn != -1) {
                outItem.setCoinDepth(c.getLong(idColumn));
            }
            outItem.setTx(txItem);
            txItem.setOuts(new ArrayList<Out>());
            txItem.getOuts().add(outItem);
            txItemList.add(txItem);
            return null;
        }
    });
    return txItemList;
}
 
Example #20
Source File: TxHelper.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public static Out applyCursorOut(ResultSet c) throws AddressFormatException, SQLException {
    Out outItem = new Out();
    int idColumn = c.findColumn(AbstractDb.OutsColumns.TX_HASH);
    if (idColumn != -1) {
        outItem.setTxHash(Base58.decode(c.getString(idColumn)));
    }
    idColumn = c.findColumn(AbstractDb.OutsColumns.OUT_SN);
    if (idColumn != -1) {
        outItem.setOutSn(c.getInt(idColumn));
    }
    idColumn = c.findColumn(AbstractDb.OutsColumns.OUT_SCRIPT);
    if (idColumn != -1) {
        outItem.setOutScript(Base58.decode(c.getString(idColumn)));
    }
    idColumn = c.findColumn(AbstractDb.OutsColumns.OUT_VALUE);
    if (idColumn != -1) {
        outItem.setOutValue(c.getLong(idColumn));
    }
    idColumn = c.findColumn(AbstractDb.OutsColumns.OUT_STATUS);
    if (idColumn != -1) {
        outItem.setOutStatus(Out.getOutStatus(c.getInt(idColumn)));
    }
    idColumn = c.findColumn(AbstractDb.OutsColumns.OUT_ADDRESS);
    if (idColumn != -1) {
        outItem.setOutAddress(c.getString(idColumn));
    }
    return outItem;
}
 
Example #21
Source File: TxProvider.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
private void addTxToDb(Connection conn, Tx txItem) throws SQLException {
    HashSet<String> addressSet = AbstractDb.hdAccountProvider.
            getBelongAccountAddresses(txItem.getOutAddressList());
    for (Out out : txItem.getOuts()) {
        if (addressSet.contains(out.getOutAddress())) {
            out.setHDAccountId(AddressManager.getInstance().getHdAccount().getHdSeedId());
        }
    }
    insertTx(conn, txItem);
    List<AddressTx> addressesTxsRels = new ArrayList<AddressTx>();
    List<AddressTx> temp = insertIn(conn, txItem);
    if (temp != null && temp.size() > 0) {
        addressesTxsRels.addAll(temp);
    }
    temp = insertOut(conn, txItem);
    if (temp != null && temp.size() > 0) {
        addressesTxsRels.addAll(temp);
    }
    PreparedStatement statement;
    for (AddressTx addressTx : addressesTxsRels) {
        String sql = "insert or ignore into addresses_txs(address, tx_hash) values(?,?)";
        statement = conn.prepareStatement(sql);
        statement.setString(1, addressTx.getAddress());
        statement.setString(2, addressTx.getTxHash());
        statement.executeUpdate();
        statement.close();

    }

}
 
Example #22
Source File: TxProvider.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
private void addOutForTxDetail(String address, HashMap<Sha256Hash, Tx> txDict) throws AddressFormatException, SQLException {
    String sql = "select b.* from addresses_txs a, outs b where a.tx_hash=b.tx_hash and a.address=? "
            + "order by b.tx_hash,b.out_sn";
    PreparedStatement statement = this.mDb.getPreparedStatement(sql, new String[]{address});
    ResultSet c = statement.executeQuery();
    while (c.next()) {
        Out out = TxHelper.applyCursorOut(c);
        Tx tx = txDict.get(new Sha256Hash(out.getTxHash()));
        if (tx != null) {
            tx.getOuts().add(out);
        }
    }
    c.close();
    statement.close();
}
 
Example #23
Source File: TxHelper.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public static Out applyCursorOut(ResultSet c) throws AddressFormatException, SQLException {
    Out outItem = new Out();
    int idColumn = c.findColumn(AbstractDb.OutsColumns.TX_HASH);
    if (idColumn != -1) {
        outItem.setTxHash(Base58.decode(c.getString(idColumn)));
    }
    idColumn = c.findColumn(AbstractDb.OutsColumns.OUT_SN);
    if (idColumn != -1) {
        outItem.setOutSn(c.getInt(idColumn));
    }
    idColumn = c.findColumn(AbstractDb.OutsColumns.OUT_SCRIPT);
    if (idColumn != -1) {
        outItem.setOutScript(Base58.decode(c.getString(idColumn)));
    }
    idColumn = c.findColumn(AbstractDb.OutsColumns.OUT_VALUE);
    if (idColumn != -1) {
        outItem.setOutValue(c.getLong(idColumn));
    }
    idColumn = c.findColumn(AbstractDb.OutsColumns.OUT_STATUS);
    if (idColumn != -1) {
        outItem.setOutStatus(Out.getOutStatus(c.getInt(idColumn)));
    }
    idColumn = c.findColumn(AbstractDb.OutsColumns.OUT_ADDRESS);
    if (idColumn != -1) {
        outItem.setOutAddress(c.getString(idColumn));
    }
    return outItem;
}
 
Example #24
Source File: TxProvider.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
private void addOutForTxDetail(String address, HashMap<Sha256Hash, Tx> txDict) throws AddressFormatException, SQLException {
    String sql = "select b.* from addresses_txs a, outs b where a.tx_hash=b.tx_hash and a.address=? "
            + "order by b.tx_hash,b.out_sn";
    PreparedStatement statement = this.mDb.getPreparedStatement(sql, new String[]{address});
    ResultSet c = statement.executeQuery();
    while (c.next()) {
        Out out = TxHelper.applyCursorOut(c);
        Tx tx = txDict.get(new Sha256Hash(out.getTxHash()));
        if (tx != null) {
            tx.getOuts().add(out);
        }
    }
    c.close();
    statement.close();
}
 
Example #25
Source File: AbstractTxProvider.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public List<Out> getOuts() {
    final List<Out> outItemList = new ArrayList<Out>();
    String sql = "select * from outs ";
    this.execQueryLoop(sql, null, new Function<ICursor, Void>() {
        @Nullable
        @Override
        public Void apply(@Nullable ICursor c) {
            outItemList.add(applyCursorOut(c));
            return null;
        }
    });
    return outItemList;
}
 
Example #26
Source File: TxProvider.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
private void addTxToDb(Connection conn, Tx txItem) throws SQLException {
    HashSet<String> addressSet = AbstractDb.hdAccountProvider.
            getBelongAccountAddresses(txItem.getOutAddressList());
    for (Out out : txItem.getOuts()) {
        if (addressSet.contains(out.getOutAddress())) {
            out.setHDAccountId(AddressManager.getInstance().getHdAccount().getHdSeedId());
        }
    }
    insertTx(conn, txItem);
    List<AddressTx> addressesTxsRels = new ArrayList<AddressTx>();
    List<AddressTx> temp = insertIn(conn, txItem);
    if (temp != null && temp.size() > 0) {
        addressesTxsRels.addAll(temp);
    }
    temp = insertOut(conn, txItem);
    if (temp != null && temp.size() > 0) {
        addressesTxsRels.addAll(temp);
    }
    PreparedStatement statement;
    for (AddressTx addressTx : addressesTxsRels) {
        String sql = "insert or ignore into addresses_txs(address, tx_hash) values(?,?)";
        statement = conn.prepareStatement(sql);
        statement.setString(1, addressTx.getAddress());
        statement.setString(2, addressTx.getTxHash());
        statement.executeUpdate();
        statement.close();

    }

}
 
Example #27
Source File: BCCAssetsDetectHotActivity.java    From bither-android with Apache License 2.0 5 votes vote down vote up
public long getAmount(List<Out> outs) {
    long amount = 0;
    for (Out out : outs) {
        amount += out.getOutValue();
    }
    return amount;
}
 
Example #28
Source File: CompleteTransactionRunnable.java    From bither-android with Apache License 2.0 5 votes vote down vote up
private void signBccTxs(List<Out> outs) {
    try {
        List<Tx> txs = wallet.buildBccTx(amount, toAddress, changeAddress,outs);
        if (txs == null) {
            obtainMessage(HandlerMessage.MSG_FAILURE, BitherApplication.mContext.getString(R
                    .string.send_failed));
            return;
        }
        if (toSign) {
            for (Tx tx: txs) {
                tx.setDetectBcc(true);
                wallet.signTx(tx, password, isBtc,outs);
                if (!tx.verifySignatures()) {
                    obtainMessage(HandlerMessage.MSG_FAILURE, getMessageFromException(null));
                    return;
                }
            }
            if (password != null) {
                password.wipe();
            }
        }
        obtainMessage(HandlerMessage.MSG_SUCCESS, txs);
    } catch (Exception e) {
        if (password != null) {
            password.wipe();
        }

        if (e instanceof HDMSignUserCancelExcetion) {
            obtainMessage(HandlerMessage.MSG_FAILURE);
            return;
        }

        e.printStackTrace();
        String msg = getMessageFromException(e);
        obtainMessage(HandlerMessage.MSG_FAILURE, msg);
    }
}
 
Example #29
Source File: SplitBCCSendActivity.java    From bither-android with Apache License 2.0 5 votes vote down vote up
public long getAmount(List<Out> outs) {
    long amount = 0;
    for (Out out : outs) {
        amount += out.getOutValue();
    }
    return amount;
}
 
Example #30
Source File: AbstractHDAccountAddressProvider.java    From bitherj with Apache License 2.0 5 votes vote down vote up
@Override
public List<Out> getUnspendOutByHDAccount(int hdAccountId) {
    final List<Out> outItems = new ArrayList<Out>();
    String unspendOutSql = "select a.* from outs a,txs b where a.tx_hash=b.tx_hash " +
            " and a.out_status=? and a.hd_account_id=?";
    this.execQueryLoop(unspendOutSql, new String[]{Integer.toString(Out.OutStatus.unspent.getValue()), Integer.toString(hdAccountId)}, new Function<ICursor, Void>() {
        @Nullable
        @Override
        public Void apply(@Nullable ICursor c) {
            outItems.add(AbstractTxProvider.applyCursorOut(c));
            return null;
        }
    });
    return outItems;
}