Search in sources :

Example 31 with Transaction

use of org.bitcoinj.core.Transaction in project bitcoin-wallet by bitcoin-wallet.

the class RaiseFeeDialogFragment method doRaiseFee.

private void doRaiseFee(final KeyParameter encryptionKey) {
    // construct child-pays-for-parent
    final TransactionOutput outputToSpend = checkNotNull(findSpendableOutput(wallet, transaction, feeRaise));
    final Transaction transactionToSend = new Transaction(Constants.NETWORK_PARAMETERS);
    transactionToSend.addInput(outputToSpend);
    transactionToSend.addOutput(outputToSpend.getValue().subtract(feeRaise), wallet.freshAddress(KeyPurpose.CHANGE));
    transactionToSend.setPurpose(Transaction.Purpose.RAISE_FEE);
    final SendRequest sendRequest = SendRequest.forTx(transactionToSend);
    sendRequest.aesKey = encryptionKey;
    try {
        wallet.signTransaction(sendRequest);
        log.info("raise fee: cpfp {}", transactionToSend);
        wallet.commitTx(transactionToSend);
        BlockchainService.broadcastTransaction(activity, transactionToSend);
        state = State.DONE;
        updateView();
        dismiss();
    } catch (final KeyCrypterException x) {
        badPasswordView.setVisibility(View.VISIBLE);
        state = State.INPUT;
        updateView();
        passwordView.requestFocus();
        log.info("raise fee: bad spending password");
    }
}
Also used : TransactionOutput(org.bitcoinj.core.TransactionOutput) SendRequest(org.bitcoinj.wallet.SendRequest) Transaction(org.bitcoinj.core.Transaction) KeyCrypterException(org.bitcoinj.crypto.KeyCrypterException)

Example 32 with Transaction

use of org.bitcoinj.core.Transaction in project bitcoin-wallet by bitcoin-wallet.

the class SendCoinsFragment method initStateFromBitcoinUri.

private void initStateFromBitcoinUri(final Uri bitcoinUri) {
    final String input = bitcoinUri.toString();
    new StringInputParser(input) {

        @Override
        protected void handlePaymentIntent(final PaymentIntent paymentIntent) {
            updateStateFrom(paymentIntent);
        }

        @Override
        protected void handlePrivateKey(final VersionedChecksummedBytes key) {
            throw new UnsupportedOperationException();
        }

        @Override
        protected void handleDirectTransaction(final Transaction transaction) throws VerificationException {
            throw new UnsupportedOperationException();
        }

        @Override
        protected void error(final int messageResId, final Object... messageArgs) {
            dialog(activity, activityDismissListener, 0, messageResId, messageArgs);
        }
    }.parse();
}
Also used : VersionedChecksummedBytes(org.bitcoinj.core.VersionedChecksummedBytes) Transaction(org.bitcoinj.core.Transaction) StringInputParser(de.schildbach.wallet.ui.InputParser.StringInputParser) VerificationException(org.bitcoinj.core.VerificationException) PaymentIntent(de.schildbach.wallet.data.PaymentIntent)

Example 33 with Transaction

use of org.bitcoinj.core.Transaction in project bitcoin-wallet by bitcoin-wallet.

the class SweepWalletFragment method onActivityResult.

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
    if (requestCode == REQUEST_CODE_SCAN) {
        if (resultCode == Activity.RESULT_OK) {
            final String input = intent.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
            new StringInputParser(input) {

                @Override
                protected void handlePrivateKey(final VersionedChecksummedBytes key) {
                    privateKeyToSweep = key;
                    setState(State.DECODE_KEY);
                    maybeDecodeKey();
                }

                @Override
                protected void handlePaymentIntent(final PaymentIntent paymentIntent) {
                    cannotClassify(input);
                }

                @Override
                protected void handleDirectTransaction(final Transaction transaction) throws VerificationException {
                    cannotClassify(input);
                }

                @Override
                protected void error(final int messageResId, final Object... messageArgs) {
                    dialog(activity, null, R.string.button_scan, messageResId, messageArgs);
                }
            }.parse();
        }
    }
}
Also used : VersionedChecksummedBytes(org.bitcoinj.core.VersionedChecksummedBytes) Transaction(org.bitcoinj.core.Transaction) WalletTransaction(org.bitcoinj.wallet.WalletTransaction) StringInputParser(de.schildbach.wallet.ui.InputParser.StringInputParser) VerificationException(org.bitcoinj.core.VerificationException) PaymentIntent(de.schildbach.wallet.data.PaymentIntent) TransactionOutPoint(org.bitcoinj.core.TransactionOutPoint)

Example 34 with Transaction

use of org.bitcoinj.core.Transaction in project bitcoin-wallet by bitcoin-wallet.

the class SweepWalletFragment method handleSweep.

private void handleSweep() {
    setState(State.PREPARATION);
    final SendRequest sendRequest = SendRequest.emptyWallet(application.getWallet().freshReceiveAddress());
    sendRequest.feePerKb = fees.get(FeeCategory.NORMAL);
    new SendCoinsOfflineTask(walletToSweep, backgroundHandler) {

        @Override
        protected void onSuccess(final Transaction transaction) {
            sentTransaction = transaction;
            setState(State.SENDING);
            sentTransaction.getConfidence().addEventListener(sentTransactionConfidenceListener);
            application.processDirectTransaction(sentTransaction);
        }

        @Override
        protected void onInsufficientMoney(@Nullable final Coin missing) {
            setState(State.FAILED);
            showInsufficientMoneyDialog();
        }

        @Override
        protected void onEmptyWalletFailed() {
            setState(State.FAILED);
            showInsufficientMoneyDialog();
        }

        @Override
        protected void onFailure(final Exception exception) {
            setState(State.FAILED);
            final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_error_msg);
            dialog.setMessage(exception.toString());
            dialog.setNeutralButton(R.string.button_dismiss, null);
            dialog.show();
        }

        @Override
        protected void onInvalidEncryptionKey() {
            // cannot happen
            throw new RuntimeException();
        }

        private void showInsufficientMoneyDialog() {
            final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.sweep_wallet_fragment_insufficient_money_title);
            dialog.setMessage(R.string.sweep_wallet_fragment_insufficient_money_msg);
            dialog.setNeutralButton(R.string.button_dismiss, null);
            dialog.show();
        }
    }.sendCoinsOffline(// send asynchronously
    sendRequest);
}
Also used : Coin(org.bitcoinj.core.Coin) SendRequest(org.bitcoinj.wallet.SendRequest) Transaction(org.bitcoinj.core.Transaction) WalletTransaction(org.bitcoinj.wallet.WalletTransaction) DialogBuilder(de.schildbach.wallet.ui.DialogBuilder) VerificationException(org.bitcoinj.core.VerificationException)

Example 35 with Transaction

use of org.bitcoinj.core.Transaction in project bitcoin-wallet by bitcoin-wallet.

the class BlockListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final BlockViewHolder holder, final int position) {
    final StoredBlock storedBlock = getItem(position);
    final Block header = storedBlock.getHeader();
    holder.miningRewardAdjustmentView.setVisibility(isMiningRewardHalvingPoint(storedBlock) ? View.VISIBLE : View.GONE);
    holder.miningDifficultyAdjustmentView.setVisibility(isDifficultyTransitionPoint(storedBlock) ? View.VISIBLE : View.GONE);
    final int height = storedBlock.getHeight();
    holder.heightView.setText(Integer.toString(height));
    final long timeMs = header.getTimeSeconds() * DateUtils.SECOND_IN_MILLIS;
    if (timeMs < System.currentTimeMillis() - DateUtils.MINUTE_IN_MILLIS)
        holder.timeView.setText(DateUtils.getRelativeDateTimeString(context, timeMs, DateUtils.MINUTE_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0));
    else
        holder.timeView.setText(R.string.block_row_now);
    holder.hashView.setText(WalletUtils.formatHash(null, header.getHashAsString(), 8, 0, ' '));
    final int transactionChildCount = holder.transactionsViewGroup.getChildCount() - ROW_BASE_CHILD_COUNT;
    int iTransactionView = 0;
    final Sha256Hash blockHash = header.getHash();
    for (final Transaction tx : transactions) {
        if (tx.getAppearsInHashes().containsKey(blockHash)) {
            final View view;
            if (iTransactionView < transactionChildCount) {
                view = holder.transactionsViewGroup.getChildAt(ROW_INSERT_INDEX + iTransactionView);
            } else {
                view = inflater.inflate(R.layout.block_row_transaction, null);
                holder.transactionsViewGroup.addView(view, ROW_INSERT_INDEX + iTransactionView);
            }
            bindView(view, tx);
            iTransactionView++;
        }
    }
    final int leftoverTransactionViews = transactionChildCount - iTransactionView;
    if (leftoverTransactionViews > 0)
        holder.transactionsViewGroup.removeViews(ROW_INSERT_INDEX + iTransactionView, leftoverTransactionViews);
    if (onClickListener != null) {
        holder.menuView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(final View v) {
                onClickListener.onBlockMenuClick(v, storedBlock);
            }
        });
    }
}
Also used : StoredBlock(org.bitcoinj.core.StoredBlock) Transaction(org.bitcoinj.core.Transaction) Sha256Hash(org.bitcoinj.core.Sha256Hash) Block(org.bitcoinj.core.Block) StoredBlock(org.bitcoinj.core.StoredBlock) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Aggregations

Transaction (org.bitcoinj.core.Transaction)39 Coin (org.bitcoinj.core.Coin)14 AddressEntry (io.bitsquare.btc.AddressEntry)8 WalletService (io.bitsquare.btc.WalletService)8 Address (org.bitcoinj.core.Address)8 BalanceListener (io.bitsquare.btc.listeners.BalanceListener)7 VerificationException (org.bitcoinj.core.VerificationException)7 PaymentIntent (de.schildbach.wallet.data.PaymentIntent)6 StringInputParser (de.schildbach.wallet.ui.InputParser.StringInputParser)6 Popup (io.bitsquare.gui.main.overlays.popups.Popup)5 Trade (io.bitsquare.trade.Trade)4 VersionedChecksummedBytes (org.bitcoinj.core.VersionedChecksummedBytes)4 DialogInterface (android.content.DialogInterface)3 View (android.view.View)3 TextView (android.widget.TextView)3 DialogBuilder (de.schildbach.wallet.ui.DialogBuilder)3 Arbitrator (io.bitsquare.arbitration.Arbitrator)3 Nullable (javax.annotation.Nullable)3 RecyclerView (android.support.v7.widget.RecyclerView)2 Inject (com.google.inject.Inject)2