Search in sources :

Example 36 with Transaction

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

the class ReportIssueDialogFragment method appendApplicationInfo.

private static void appendApplicationInfo(final Appendable report, final WalletApplication application) throws IOException {
    final PackageInfo pi = application.packageInfo();
    final Configuration configuration = application.getConfiguration();
    final Calendar calendar = new GregorianCalendar(UTC);
    report.append("Version: " + pi.versionName + " (" + pi.versionCode + ")\n");
    report.append("Package: " + pi.packageName + "\n");
    report.append("Installer: " + application.getPackageManager().getInstallerPackageName(pi.packageName) + "\n");
    report.append("Test/Prod: " + (Constants.TEST ? "test" : "prod") + "\n");
    report.append("Timezone: " + TimeZone.getDefault().getID() + "\n");
    calendar.setTimeInMillis(System.currentTimeMillis());
    report.append("Time: " + String.format(Locale.US, "%tF %tT %tZ", calendar, calendar, calendar) + "\n");
    calendar.setTimeInMillis(WalletApplication.TIME_CREATE_APPLICATION);
    report.append("Time of launch: " + String.format(Locale.US, "%tF %tT %tZ", calendar, calendar, calendar) + "\n");
    calendar.setTimeInMillis(pi.lastUpdateTime);
    report.append("Time of last update: " + String.format(Locale.US, "%tF %tT %tZ", calendar, calendar, calendar) + "\n");
    calendar.setTimeInMillis(pi.firstInstallTime);
    report.append("Time of first install: " + String.format(Locale.US, "%tF %tT %tZ", calendar, calendar, calendar) + "\n");
    final long lastBackupTime = configuration.getLastBackupTime();
    calendar.setTimeInMillis(lastBackupTime);
    report.append("Time of backup: " + (lastBackupTime > 0 ? String.format(Locale.US, "%tF %tT %tZ", calendar, calendar, calendar) : "none") + "\n");
    report.append("Network: " + Constants.NETWORK_PARAMETERS.getId() + "\n");
    final Wallet wallet = application.getWallet();
    report.append("Encrypted: " + wallet.isEncrypted() + "\n");
    report.append("Keychain size: " + wallet.getKeyChainGroupSize() + "\n");
    final Set<Transaction> transactions = wallet.getTransactions(true);
    int numInputs = 0;
    int numOutputs = 0;
    int numSpentOutputs = 0;
    for (final Transaction tx : transactions) {
        numInputs += tx.getInputs().size();
        final List<TransactionOutput> outputs = tx.getOutputs();
        numOutputs += outputs.size();
        for (final TransactionOutput txout : outputs) {
            if (!txout.isAvailableForSpending())
                numSpentOutputs++;
        }
    }
    report.append("Transactions: " + transactions.size() + "\n");
    report.append("Inputs: " + numInputs + "\n");
    report.append("Outputs: " + numOutputs + " (spent: " + numSpentOutputs + ")\n");
    report.append("Last block seen: " + wallet.getLastBlockSeenHeight() + " (" + wallet.getLastBlockSeenHash() + ")\n");
    report.append("Databases:");
    for (final String db : application.databaseList()) report.append(" " + db);
    report.append("\n");
    final File filesDir = application.getFilesDir();
    report.append("\nContents of FilesDir " + filesDir + ":\n");
    appendDir(report, filesDir, 0);
}
Also used : TransactionOutput(org.bitcoinj.core.TransactionOutput) Configuration(de.schildbach.wallet.Configuration) PackageInfo(android.content.pm.PackageInfo) Wallet(org.bitcoinj.wallet.Wallet) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Transaction(org.bitcoinj.core.Transaction) File(java.io.File)

Example 37 with Transaction

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

the class SendingAddressesFragment method onActivityResult.

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

            @Override
            protected void handlePaymentIntent(final PaymentIntent paymentIntent) {
                // workaround for "IllegalStateException: Can not perform this action after
                // onSaveInstanceState"
                handler.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        if (paymentIntent.hasAddress()) {
                            final Address address = paymentIntent.getAddress();
                            if (!wallet.isPubKeyHashMine(address.getHash160()))
                                EditAddressBookEntryFragment.edit(getFragmentManager(), address);
                            else
                                dialog(activity, null, R.string.address_book_options_scan_title, R.string.address_book_options_scan_own_address);
                        } else {
                            dialog(activity, null, R.string.address_book_options_scan_title, R.string.address_book_options_scan_invalid);
                        }
                    }
                }, 500);
            }

            @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.address_book_options_scan_title, messageResId, messageArgs);
            }
        }.parse();
    }
}
Also used : Address(org.bitcoinj.core.Address) Transaction(org.bitcoinj.core.Transaction) StringInputParser(de.schildbach.wallet.ui.InputParser.StringInputParser) VerificationException(org.bitcoinj.core.VerificationException) PaymentIntent(de.schildbach.wallet.data.PaymentIntent)

Example 38 with Transaction

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

the class TransactionsAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
    if (holder instanceof TransactionViewHolder) {
        final TransactionViewHolder transactionHolder = (TransactionViewHolder) holder;
        final long itemId = getItemId(position);
        transactionHolder.itemView.setActivated(itemId == selectedItemId);
        final Transaction tx = transactions.get(position - (warning != null ? 1 : 0));
        transactionHolder.bind(tx);
        transactionHolder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(final View v) {
                setSelectedItemId(getItemId(transactionHolder.getAdapterPosition()));
            }
        });
        if (onClickListener != null) {
            transactionHolder.menuView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(final View v) {
                    onClickListener.onTransactionMenuClick(v, tx);
                }
            });
        }
    } else if (holder instanceof WarningViewHolder) {
        final WarningViewHolder warningHolder = (WarningViewHolder) holder;
        if (warning == Warning.BACKUP) {
            if (transactions.size() == 1) {
                warningHolder.messageView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
                warningHolder.messageView.setText(Html.fromHtml(context.getString(R.string.wallet_transactions_row_warning_backup)));
            } else {
                warningHolder.messageView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_warning_grey600_24dp, 0, 0, 0);
                warningHolder.messageView.setText(Html.fromHtml(context.getString(R.string.wallet_disclaimer_fragment_remind_backup)));
            }
        } else if (warning == Warning.STORAGE_ENCRYPTION) {
            warningHolder.messageView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
            warningHolder.messageView.setText(Html.fromHtml(context.getString(R.string.wallet_transactions_row_warning_storage_encryption)));
        } else if (warning == Warning.CHAIN_FORKING) {
            warningHolder.messageView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_warning_grey600_24dp, 0, 0, 0);
            warningHolder.messageView.setText(Html.fromHtml(context.getString(R.string.wallet_transactions_row_warning_chain_forking)));
        }
    }
}
Also used : Transaction(org.bitcoinj.core.Transaction) CircularProgressView(de.schildbach.wallet.util.CircularProgressView) View(android.view.View) CardView(android.support.v7.widget.CardView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Example 39 with Transaction

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

the class WalletTransactionsFragment method onTransactionMenuClick.

@Override
public void onTransactionMenuClick(final View view, final Transaction tx) {
    final boolean txSent = tx.getValue(wallet).signum() < 0;
    final Address txAddress = txSent ? WalletUtils.getToAddressOfSent(tx, wallet) : WalletUtils.getWalletAddressOfReceived(tx, wallet);
    final byte[] txSerialized = tx.unsafeBitcoinSerialize();
    final boolean txRotation = tx.getPurpose() == Purpose.KEY_ROTATION;
    final PopupMenu popupMenu = new PopupMenu(activity, view);
    popupMenu.inflate(R.menu.wallet_transactions_context);
    final MenuItem editAddressMenuItem = popupMenu.getMenu().findItem(R.id.wallet_transactions_context_edit_address);
    if (!txRotation && txAddress != null) {
        editAddressMenuItem.setVisible(true);
        final boolean isAdd = AddressBookProvider.resolveLabel(activity, txAddress.toBase58()) == null;
        final boolean isOwn = wallet.isPubKeyHashMine(txAddress.getHash160());
        if (isOwn)
            editAddressMenuItem.setTitle(isAdd ? R.string.edit_address_book_entry_dialog_title_add_receive : R.string.edit_address_book_entry_dialog_title_edit_receive);
        else
            editAddressMenuItem.setTitle(isAdd ? R.string.edit_address_book_entry_dialog_title_add : R.string.edit_address_book_entry_dialog_title_edit);
    } else {
        editAddressMenuItem.setVisible(false);
    }
    popupMenu.getMenu().findItem(R.id.wallet_transactions_context_show_qr).setVisible(!txRotation && txSerialized.length < SHOW_QR_THRESHOLD_BYTES);
    popupMenu.getMenu().findItem(R.id.wallet_transactions_context_raise_fee).setVisible(RaiseFeeDialogFragment.feeCanLikelyBeRaised(wallet, tx));
    popupMenu.getMenu().findItem(R.id.wallet_transactions_context_browse).setVisible(Constants.ENABLE_BROWSE);
    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(final MenuItem item) {
            switch(item.getItemId()) {
                case R.id.wallet_transactions_context_edit_address:
                    handleEditAddress(tx);
                    return true;
                case R.id.wallet_transactions_context_show_qr:
                    handleShowQr();
                    return true;
                case R.id.wallet_transactions_context_raise_fee:
                    RaiseFeeDialogFragment.show(getFragmentManager(), tx);
                    return true;
                case R.id.wallet_transactions_context_report_issue:
                    handleReportIssue(tx);
                    return true;
                case R.id.wallet_transactions_context_browse:
                    if (!txRotation) {
                        final String txHash = tx.getHashAsString();
                        final Uri blockExplorerUri = config.getBlockExplorer();
                        log.info("Viewing transaction {} on {}", txHash, blockExplorerUri);
                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.withAppendedPath(blockExplorerUri, "tx/" + txHash)));
                    } else {
                        startActivity(new Intent(Intent.ACTION_VIEW, KEY_ROTATION_URI));
                    }
                    return true;
            }
            return false;
        }

        private void handleEditAddress(final Transaction tx) {
            EditAddressBookEntryFragment.edit(getFragmentManager(), txAddress);
        }

        private void handleShowQr() {
            final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(txSerialized));
            BitmapFragment.show(getFragmentManager(), qrCodeBitmap);
        }

        private void handleReportIssue(final Transaction tx) {
            final StringBuilder contextualData = new StringBuilder();
            try {
                contextualData.append(tx.getValue(wallet).toFriendlyString()).append(" total value");
            } catch (final ScriptException x) {
                contextualData.append(x.getMessage());
            }
            contextualData.append('\n');
            if (tx.hasConfidence())
                contextualData.append("  confidence: ").append(tx.getConfidence()).append('\n');
            contextualData.append(tx.toString());
            ReportIssueDialogFragment.show(getFragmentManager(), R.string.report_issue_dialog_title_transaction, R.string.report_issue_dialog_message_issue, Constants.REPORT_SUBJECT_ISSUE, contextualData.toString());
        }
    });
    popupMenu.show();
}
Also used : Address(org.bitcoinj.core.Address) SpannableStringBuilder(android.text.SpannableStringBuilder) OnMenuItemClickListener(android.widget.PopupMenu.OnMenuItemClickListener) MenuItem(android.view.MenuItem) Intent(android.content.Intent) Uri(android.net.Uri) ScriptException(org.bitcoinj.core.ScriptException) Bitmap(android.graphics.Bitmap) Transaction(org.bitcoinj.core.Transaction) PopupMenu(android.widget.PopupMenu)

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