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

The following examples show how to use net.bither.bitherj.core.Tx. 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: WalletUtils.java    License: 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 2
Source Project: bither-desktop-java   Source File: TxHelper.java    License: 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 3
Source Project: bitherj   Source File: AbstractTxProvider.java    License: Apache License 2.0 6 votes vote down vote up
public Tx getTxDetailByTxHash(byte[] txHash) {
    final Tx[] txItem = {null};
    final boolean[] txExists = {false};
    String txHashStr = Base58.encode(txHash);
    String sql = "select * from txs where tx_hash=?";
    IDb db = this.getReadDb();
    this.execQueryOneRecord(db, sql, new String[]{txHashStr}, new Function<ICursor, Void>() {
        @Nullable

        @Override
        public Void apply(@Nullable ICursor c) {
            txItem[0] = applyCursor(c);
            txExists[0] = true;
            return null;
        }
    });
    if (txExists[0]) {
        addInsAndOuts(db, txItem[0]);
    }
    return txItem[0];
}
 
Example 4
Source Project: bither-desktop-java   Source File: TxProvider.java    License: Apache License 2.0 6 votes vote down vote up
public boolean isTxDoubleSpendWithConfirmedTx(Tx tx) {
    String sql = "select count(0) cnt from ins a, txs b where a.tx_hash=b.tx_hash and" +
            " b.block_no is not null and a.prev_tx_hash=? and a.prev_out_sn=?";
    ResultSet rs;
    try {
        for (In inItem : tx.getIns()) {
            PreparedStatement statement = this.mDb.getPreparedStatement(sql, new String[]{Base58.encode(inItem.getPrevTxHash()), Integer.toString(inItem.getPrevOutSn())});
            rs = statement.executeQuery();
            if (rs.next()) {
                int columnIndex = rs.findColumn("cnt");
                if (columnIndex != -1 && rs.getInt(columnIndex) > 0) {
                    rs.close();
                    statement.close();
                    return true;
                }
            }
            rs.close();
            statement.close();

        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return false;
}
 
Example 5
Source Project: bither-desktop-java   Source File: TxProvider.java    License: Apache License 2.0 6 votes vote down vote up
public List<String> getInAddresses(Tx tx) {
    List<String> result = new ArrayList<String>();
    String sql = "select out_address from outs where tx_hash=? and out_sn=?";
    ResultSet c;
    try {
        for (In inItem : tx.getIns()) {
            PreparedStatement statement = this.mDb.getPreparedStatement(sql, new String[]{Base58.encode(inItem.getPrevTxHash()), Integer.toString(inItem.getPrevOutSn())});
            c = statement.executeQuery();
            if (c.next()) {
                int column = c.findColumn("out_address");
                if (column != -1) {
                    result.add(c.getString(column));
                }
            }
            c.close();
            statement.close();
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return result;
}
 
Example 6
Source Project: bitherj   Source File: QRCodeTxTransport.java    License: Apache License 2.0 6 votes vote down vote up
public static String oldGetPreSignString(Tx tx, String addressCannotParsed) {
    QRCodeTxTransport qrCodeTransport = oldFromSendRequestWithUnsignedTransaction(tx,
            addressCannotParsed);
    String preSignString = qrCodeTransport.getMyAddress() + QRCodeUtil.OLD_QR_CODE_SPLIT +
            Long.toHexString(qrCodeTransport.getFee()).toLowerCase(Locale.US) + QRCodeUtil
            .OLD_QR_CODE_SPLIT + qrCodeTransport.getToAddress() + QRCodeUtil
            .OLD_QR_CODE_SPLIT + Long.toHexString(qrCodeTransport.getTo()).toLowerCase(Locale
            .US) + QRCodeUtil.OLD_QR_CODE_SPLIT;
    for (int i = 0;
         i < qrCodeTransport.getHashList().size();
         i++) {
        String hash = qrCodeTransport.getHashList().get(i);
        if (i < qrCodeTransport.getHashList().size() - 1) {
            preSignString = preSignString + hash + QRCodeUtil.OLD_QR_CODE_SPLIT;
        } else {
            preSignString = preSignString + hash;
        }
    }

    return preSignString;
}
 
Example 7
Source Project: bither-desktop-java   Source File: UnSignTxPanel.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void success(Object obj) {
    if (obj != null && obj instanceof Tx) {
        tx = (Tx) obj;
        if (needConfirm) {
            SendBitcoinConfirmPanel confirmPanel = new SendBitcoinConfirmPanel
                    (sendConfirmListener, bitcoinAddress, changeAddress, tx);
            confirmPanel.showPanel();
        } else {
            sendConfirmListener.onConfirm(tx);
        }
    } else {
        new MessageDialog(LocaliserUtils.getString("password_wrong")).showMsg();
    }

}
 
Example 8
Source Project: bitherj   Source File: AbstractTxProvider.java    License: Apache License 2.0 6 votes vote down vote up
public void insertTx(IDb db, Tx txItem) {
    final int[] cnt = {0};
    String existSql = "select count(0) cnt from txs where tx_hash=?";
    this.execQueryOneRecord(db, existSql, new String[]{Base58.encode(txItem.getTxHash())}, new Function<ICursor, Void>() {
        @Nullable
        @Override
        public Void apply(@Nullable ICursor c) {
            int idColumn = c.getColumnIndex("cnt");
            if (idColumn != -1) {
                cnt[0] = c.getInt(idColumn);
            }
            return null;
        }
    });

    if (cnt[0] == 0) {
        this.insertTxToDb(db, txItem);
    }

}
 
Example 9
Source Project: bither-android   Source File: TxProvider.java    License: 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 10
Source Project: bitherj   Source File: AbstractTxProvider.java    License: 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 11
Source Project: bither-desktop-java   Source File: UnSignTxPanel.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void success(Object obj) {
    if (obj != null && obj instanceof Tx) {
        tx = (Tx) obj;
        if (needConfirm) {
            SendBitcoinConfirmPanel confirmPanel = new SendBitcoinConfirmPanel
                    (sendConfirmListener, bitcoinAddress, changeAddress, tx);
            confirmPanel.showPanel();
        } else {
            sendConfirmListener.onConfirm(tx);
        }
    } else {
        new MessageDialog(LocaliserUtils.getString("password_wrong")).showMsg();
    }

}
 
Example 12
Source Project: bitherj   Source File: AbstractTxProvider.java    License: 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 13
Source Project: bither-desktop-java   Source File: WalletUtils.java    License: 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 Project: bither-android   Source File: GenerateUnsignedTxActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onConfirm(Tx tx) {
    GenerateUnsignedTxActivity.this.tx = tx;
    String addressCannotBtParsed = getString(R.string.address_cannot_be_parsed);
    Intent intent = new Intent(GenerateUnsignedTxActivity.this,
            UnsignedTxQrCodeActivity.class);
    String changeAddress = dialogSelectChangeAddress
            .getChangeAddress().equals(address) ? null :
            dialogSelectChangeAddress.getChangeAddress().getAddress();
    intent.putExtra(BitherSetting.INTENT_REF.QR_CODE_STRING,
            QRCodeTxTransport.getPresignTxString(tx, changeAddress, addressCannotBtParsed, QRCodeTxTransport.NO_HDM_INDEX));
    if (Utils.isEmpty(changeAddress)) {
        intent.putExtra(BitherSetting.INTENT_REF.OLD_QR_CODE_STRING,
                QRCodeTxTransport.oldGetPreSignString(tx, addressCannotBtParsed));
    } else {
        intent.putExtra(BitherSetting.INTENT_REF.QR_CODE_HAS_CHANGE_ADDRESS_STRING
                , true);
    }

    intent.putExtra(BitherSetting.INTENT_REF.TITLE_STRING,
            getString(R.string.unsigned_transaction_qr_code_title));
    startActivityForResult(intent, BitherSetting.INTENT_REF.SIGN_TX_REQUEST_CODE);
    btnSend.setEnabled(true);
}
 
Example 15
Source Project: bitherj   Source File: ECKeyTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetPubs() {
    List<byte[]> pubKeyS = Arrays.asList(Utils.hexStringToByteArray("02d8ed584a211a9195f0d580617c60398f82f58dcd5b104249737762656e62d52e"),
            Utils.hexStringToByteArray("026fd10f953a13ac14041460cd01eab3d665d140d1c978a01db4bc669bab9a77db"), Utils.hexStringToByteArray("03b5eceb6f5a9a12b8b7fe23ae6297bfdb46aeab39ab0ee89efd4068d251667ae0"));
    byte[] params = Utils.hexStringToByteArray("522102d8ed584a211a9195f0d580617c60398f82f58dcd5b104249737762656e62d52e21026fd10f953a13ac14041460cd01eab3d665d140d1c978a01db4bc669bab9a77db2103b5eceb6f5a9a12b8b7fe23ae6297bfdb46aeab39ab0ee89efd4068d251667ae053ae");
    Tx tx = new Tx(Utils.hexStringToByteArray("010000000196d607b6c1647a1cccd9db40e918627e4d5e190ba56a5663ccef5e1a8ecada0700000000fdfd0000473044022041b2a5f1965b060bbf484218ac1e3b7ced9ec908078ca4565f9c4eef4f0dfec902206c3f3a1320dac89fd1e58627a1208510328d618365dd033d90ce5230c40884fa01483045022100abd2696052faa6e707e02402b7c654d0ab3be7d1d7f14af541abf99eaf16e1fd02205da8e8e2c4a9795046aa4c380e6f1c005e6619b16f7182df37b54405eb28aedc014c69522102d8ed584a211a9195f0d580617c60398f82f58dcd5b104249737762656e62d52e21026fd10f953a13ac14041460cd01eab3d665d140d1c978a01db4bc669bab9a77db2103b5eceb6f5a9a12b8b7fe23ae6297bfdb46aeab39ab0ee89efd4068d251667ae053aeffffffff0128230000000000001976a914f307ea0809f5c60d42482e57dfdd78ed53df580688ac00000000"));
    List<byte[]> signPubs = tx.getIns().get(0).getP2SHPubKeys();
    for (byte[] signs : signPubs) {
        boolean isPub = false;
        for (byte[] pubs : pubKeyS) {
            isPub = Arrays.equals(signs, pubs);
            if (isPub) {
                break;
            }
        }
        System.out.println("pub:" + Utils.bytesToHexString(signs));
        assertTrue(Utils.bytesToHexString(signs), isPub);
    }

}
 
Example 16
Source Project: bitherj   Source File: AbstractTxProvider.java    License: Apache License 2.0 6 votes vote down vote up
public List<String> getInAddresses(Tx tx) {
    final List<String> result = new ArrayList<String>();
    String sql = "select out_address from outs where tx_hash=? and out_sn=?";
    IDb db = this.getReadDb();
    for (In inItem : tx.getIns()) {
        this.execQueryOneRecord(db, sql, new String[]{Base58.encode(inItem.getPrevTxHash())
                , Integer.toString(inItem.getPrevOutSn())}, new Function<ICursor, Void>() {
            @Nullable
            @Override
            public Void apply(@Nullable ICursor c) {
                if (!c.isNull(0)) {
                    result.add(c.getString(0));
                }
                return null;
            }
        });
    }
    return result;
}
 
Example 17
Source Project: bither-desktop-java   Source File: TxProvider.java    License: Apache License 2.0 6 votes vote down vote up
public boolean isTxDoubleSpendWithConfirmedTx(Tx tx) {
    String sql = "select count(0) cnt from ins a, txs b where a.tx_hash=b.tx_hash and" +
            " b.block_no is not null and a.prev_tx_hash=? and a.prev_out_sn=?";
    ResultSet rs;
    try {
        for (In inItem : tx.getIns()) {
            PreparedStatement statement = this.mDb.getPreparedStatement(sql, new String[]{Base58.encode(inItem.getPrevTxHash()), Integer.toString(inItem.getPrevOutSn())});
            rs = statement.executeQuery();
            if (rs.next()) {
                int columnIndex = rs.findColumn("cnt");
                if (columnIndex != -1 && rs.getInt(columnIndex) > 0) {
                    rs.close();
                    statement.close();
                    return true;
                }
            }
            rs.close();
            statement.close();

        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return false;
}
 
Example 18
Source Project: bither-desktop-java   Source File: TxHelper.java    License: 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 19
Source Project: bither-android   Source File: CommitTransactionThread.java    License: 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 20
Source Project: bither-android   Source File: TxReceiver.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (intent == null || !Utils.compareString(intent.getAction(), NotificationAndroidImpl.ACTION_ADDRESS_BALANCE)) {
        return;
    }
    if (tickReceiver != null) {
        tickReceiver.setTransactionsReceived();
    }
    String address = intent.getStringExtra(NotificationAndroidImpl.MESSAGE_ADDRESS);
    long amount = intent.getLongExtra(NotificationAndroidImpl.MESSAGE_DELTA_BALANCE, 0);
    int txNotificationType = intent.getIntExtra(NotificationAndroidImpl.MESSAGE_TX_NOTIFICATION_TYPE, 0);
    if (txNotificationType == Tx.TxNotificationType.txReceive.getValue()) {
        boolean isReceived = amount > 0;
        amount = Math.abs(amount);
        notifyCoins(address, amount, isReceived);
    }

}
 
Example 21
Source Project: bither-desktop-java   Source File: TxNotificationCenter.java    License: Apache License 2.0 6 votes vote down vote up
public static void notificatTx(final String address, final Tx tx,
                               final Tx.TxNotificationType txNotificationType, final long deltaBalance) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            if (Utils.compareString(address, HDAccount.HDAccountPlaceHolder)) {
                Bither.refreshFrame();
            }
            for (ITxListener txListener : txListenerList) {
                txListener.notificatTx(address, tx, txNotificationType, deltaBalance);
            }
            if (txNotificationType == Tx.TxNotificationType.txReceive) {
                boolean isReceived = deltaBalance > 0;
                long balance = Math.abs(deltaBalance);
                notifyCoins(address, balance, isReceived);
            }
        }
    });


}
 
Example 22
Source Project: bither-android   Source File: HdmSendActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onConfirm(Tx tx) {
    String addressCannotBtParsed = getString(R.string.address_cannot_be_parsed);
    Intent intent = new Intent(HdmSendActivity.this, UnsignedTxQrCodeActivity.class);
    String changeAddress = dialogSelectChangeAddress.getChangeAddress().equals
            (address) ? null : dialogSelectChangeAddress.getChangeAddress()
            .getAddress();
    intent.putExtra(BitherSetting.INTENT_REF.QR_CODE_STRING,
            QRCodeTxTransport.getPresignTxString(tx, changeAddress,
                    addressCannotBtParsed, signingIndex));
    if (Utils.isEmpty(changeAddress)) {
        intent.putExtra(BitherSetting.INTENT_REF.OLD_QR_CODE_STRING,
                QRCodeTxTransport.oldGetPreSignString(tx, addressCannotBtParsed));
    } else {
        intent.putExtra(BitherSetting.INTENT_REF.QR_CODE_HAS_CHANGE_ADDRESS_STRING,
                true);
    }

    intent.putExtra(BitherSetting.INTENT_REF.TITLE_STRING,
            getString(R.string.unsigned_transaction_qr_code_title));
    startActivityForResult(intent, RequestCode);
    sigs = null;
}
 
Example 23
Source Project: bither-android   Source File: DialogHdSendConfirm.java    License: Apache License 2.0 6 votes vote down vote up
public DialogHdSendConfirm(Context context, String toAddress, List<Tx> txs, long fee, SendConfirmListener listener) {
    super(context);
    this.listener = listener;
    this.splitCoin = SplitCoin.BCC;
    setOnDismissListener(this);
    setContentView(R.layout.dialog_send_confirm);
    configureUI(toAddress);
    TextView tvBtc = (TextView) findViewById(R.id.tv_btc);
    TextView tvFee = (TextView) findViewById(R.id.tv_fee);
    long amount = 0;
    for (Tx tx: txs) {
        amount += tx.amountSentToAddress(toAddress);
    }
    tvBtc.setText(UnitUtilWrapper.formatValueWithBold(amount));
    tvFee.setText(UnitUtilWrapper.formatValueWithBold(fee));
}
 
Example 24
Source Project: bither-android   Source File: CurrencyAmountView.java    License: Apache License 2.0 6 votes vote down vote up
private boolean isValidAmount(final boolean zeroIsValid) {
    final String amount = textView.getText().toString().trim();

    try {
        if (!amount.isEmpty()) {
            final BigInteger nanoCoins = GenericUtils.toNanoCoins(amount, shift);

            // exactly zero
            if (zeroIsValid && nanoCoins.signum() == 0) {
                return true;
            }

            // too small
            if (nanoCoins.longValue() < Tx.MIN_NONDUST_OUTPUT) {
                return false;
            }

            return true;
        }
    } catch (final Exception x) {
    }

    return false;
}
 
Example 25
Source Project: bither-android   Source File: HdmSendActivity.java    License: Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message msg) {
    switch (msg.what) {
        case HandlerMessage.MSG_SUCCESS:
            if (!dp.isShowing()) {
                dp.show();
            }
            if (msg.obj != null && msg.obj instanceof Tx) {
                Tx tx = (Tx) msg.obj;
                //dp.setRChecking();
                RCheckRunnable run = new RCheckRunnable(address, tx);
                run.setHandler(rcheckHandler);
                new Thread(run).start();
            } else {
                DropdownMessage.showDropdownMessage(HdmSendActivity.this,
                        R.string.password_wrong);
            }
            break;
        case HandlerMessage.MSG_PASSWORD_WRONG:
            if (dp.isShowing()) {
                dp.dismiss();
            }
            DropdownMessage.showDropdownMessage(HdmSendActivity.this,
                    R.string.password_wrong);
            break;
        case HandlerMessage.MSG_FAILURE:
            if (dp.isShowing()) {
                dp.dismiss();
            }
            if (msg.obj != null) {
                String msgError = getString(R.string.send_failed);
                if (msg.obj instanceof String) {
                    msgError = (String) msg.obj;
                }
                DropdownMessage.showDropdownMessage(HdmSendActivity.this, msgError);
            }
            break;
        default:
            break;
    }
}
 
Example 26
Source Project: bither-desktop-java   Source File: TxProvider.java    License: Apache License 2.0 5 votes vote down vote up
private void addInForTxDetail(String address, HashMap<Sha256Hash, Tx> txDict) throws AddressFormatException, SQLException {
    String sql = "select b.* from addresses_txs a, ins b where a.tx_hash=b.tx_hash and a.address=? "
            + "order by b.tx_hash ,b.in_sn";
    PreparedStatement statement = this.mDb.getPreparedStatement(sql, new String[]{address});
    ResultSet c = statement.executeQuery();
    while (c.next()) {
        In inItem = TxHelper.applyCursorIn(c);
        Tx tx = txDict.get(new Sha256Hash(inItem.getTxHash()));
        if (tx != null) {
            tx.getIns().add(inItem);
        }
    }
    c.close();
    statement.close();
}
 
Example 27
Source Project: bitherj   Source File: QRCodeTxTransport.java    License: Apache License 2.0 5 votes vote down vote up
public static String getPresignTxString(Tx tx, String changeAddress,
                                        String addressCannotParsed, int hdmIndex, TxTransportType txTransportType) {
    QRCodeTxTransport qrCodeTransport = fromSendRequestWithUnsignedTransaction(tx,
            addressCannotParsed, hdmIndex, txTransportType);
    String preSignString = "";
    try {
        String versionStr = "";
        if (txTransportType != null) {
            versionStr = TX_TRANSPORT_VERSION + txTransportType.getType();
        }
        String changeStr = "";
        if (!Utils.isEmpty(changeAddress)) {
            long changeAmt = tx.amountSentToAddress(changeAddress);
            if (changeAmt != 0) {
                String[] changeStrings = new String[]{Base58.bas58ToHexWithAddress
                        (changeAddress), Long.toHexString(changeAmt)};
                changeStr = Utils.joinString(changeStrings, QRCodeUtil.QR_CODE_SPLIT);

            }
        }
        String hdmIndexString = "";
        if (qrCodeTransport.getHdmIndex() != QRCodeTxTransport.NO_HDM_INDEX) {
            hdmIndexString = Integer.toHexString(qrCodeTransport.getHdmIndex());
        }
        String[] preSigns = new String[]{versionStr, hdmIndexString, Base58.bas58ToHexWithAddress
                (qrCodeTransport.getMyAddress()), changeStr, Long.toHexString(qrCodeTransport
                .getFee()), Base58.bas58ToHexWithAddress(qrCodeTransport.getToAddress()),
                Long.toHexString(qrCodeTransport.getTo())};
        preSignString = Utils.joinString(preSigns, QRCodeUtil.QR_CODE_SPLIT);
        String[] hashStrings = new String[qrCodeTransport.getHashList().size()];
        hashStrings = qrCodeTransport.getHashList().toArray(hashStrings);
        preSignString = preSignString + QRCodeUtil.QR_CODE_SPLIT + Utils.joinString
                (hashStrings, QRCodeUtil.QR_CODE_SPLIT);
        preSignString.toUpperCase(Locale.US);
    } catch (AddressFormatException e) {
        e.printStackTrace();
    }

    return preSignString;
}
 
Example 28
Source Project: bither-desktop-java   Source File: TxProvider.java    License: Apache License 2.0 5 votes vote down vote up
public void addTxs(List<Tx> txItems) {
    try {
        Connection connection = this.mDb.getConn();
        connection.setAutoCommit(false);
        for (Tx txItem : txItems) {
            addTxToDb(connection, txItem);
        }
        connection.commit();
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
 
Example 29
Source Project: bitherj   Source File: QRCodeTxTransport.java    License: Apache License 2.0 5 votes vote down vote up
private static QRCodeTxTransport fromDeskpHDMSendRequestWithUnsignedTransaction(TxTransportType txTransportType, Tx tx, List<DesktopHDMAddress> desktopHDMAddresses,
                                                                                String addressCannotParsed) {
    if (!AddressManager.getInstance().hasDesktopHDMKeychain()) {
        return null;
    }
    QRCodeTxTransport qrCodeTransport = new QRCodeTxTransport();
    qrCodeTransport.setMyAddress(tx.getFromAddress());
    String toAddress = tx.getFirstOutAddress();
    if (Utils.isEmpty(toAddress)) {
        toAddress = addressCannotParsed;
    }

    qrCodeTransport.setToAddress(toAddress);
    qrCodeTransport.setTo(tx.amountSentToAddress(toAddress));
    qrCodeTransport.setFee(tx.getFee());
    List<String> hashList = new ArrayList<String>();
    if (txTransportType == TxTransportType.DesktopHDM) {

        for (int i = 0; i < desktopHDMAddresses.size(); i++) {
            DesktopHDMAddress desktopHDMAddress = desktopHDMAddresses.get(i);
            for (byte[] h : tx.getUnsignedInHashesForDesktpHDM(desktopHDMAddress.getPubKey(), i)) {
                String[] strings = new String[]{Integer.toString(desktopHDMAddress.getPathType().getValue()),
                        Integer.toString(desktopHDMAddress.getIndex()), Utils.bytesToHexString(h)};
                hashList.add(Utils.joinString(strings, QRCodeUtil.QR_CODE_SECONDARY_SPLIT));
            }

        }
    }
    qrCodeTransport.setHashList(hashList);
    return qrCodeTransport;
}
 
Example 30
Source Project: bitherj   Source File: AbstractTxProvider.java    License: 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;
}