Search in sources :

Example 11 with Wallet

use of org.bitcoinj.wallet.Wallet in project bitcoin-wallet by bitcoin-wallet.

the class WalletAddressesFragment method maybeSubmitList.

private void maybeSubmitList() {
    final List<Address> derivedAddresses = viewModel.issuedReceiveAddresses.getValue();
    final List<Address> randomAddresses = viewModel.importedAddresses.getValue();
    final Wallet wallet = walletActivityViewModel.wallet.getValue();
    if (derivedAddresses != null && randomAddresses != null) {
        viewGroup.setDisplayedChild(1);
        adapter.submitList(AddressBookAdapter.buildListItems(activity, derivedAddresses, randomAddresses, wallet, AddressBookEntry.asMap(viewModel.addressBook.getValue())));
    }
}
Also used : LegacyAddress(org.bitcoinj.core.LegacyAddress) Address(org.bitcoinj.core.Address) Wallet(org.bitcoinj.wallet.Wallet)

Example 12 with Wallet

use of org.bitcoinj.wallet.Wallet in project bitcoin-wallet by bitcoin-wallet.

the class WalletTransactionsFragment method onInflateTransactionContextMenu.

@Override
public void onInflateTransactionContextMenu(final MenuInflater inflater, final Menu menu, final Sha256Hash transactionId) {
    final Wallet wallet = viewModel.wallet.getValue();
    final Transaction tx = wallet.getTransaction(transactionId);
    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();
    inflater.inflate(R.menu.wallet_transactions_context, menu);
    final MenuItem editAddressMenuItem = menu.findItem(R.id.wallet_transactions_context_edit_address);
    if (txAddress != null) {
        editAddressMenuItem.setVisible(true);
        final boolean isAdd = addressBookDao.resolveLabel(txAddress.toString()) == null;
        final boolean isOwn = wallet.isAddressMine(txAddress);
        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);
    }
    menu.findItem(R.id.wallet_transactions_context_show_qr).setVisible(txSerialized.length < SHOW_QR_THRESHOLD_BYTES);
    menu.findItem(R.id.wallet_transactions_context_raise_fee).setVisible(RaiseFeeDialogFragment.feeCanLikelyBeRaised(wallet, tx));
    menu.findItem(R.id.wallet_transactions_context_browse).setVisible(Constants.ENABLE_BROWSE);
}
Also used : Transaction(org.bitcoinj.core.Transaction) Address(org.bitcoinj.core.Address) Wallet(org.bitcoinj.wallet.Wallet) MenuItem(android.view.MenuItem)

Example 13 with Wallet

use of org.bitcoinj.wallet.Wallet in project bitcoin-wallet by bitcoin-wallet.

the class AcceptBluetoothService method handleTx.

private boolean handleTx(final Transaction tx) {
    log.info("tx {} arrived via blueooth", tx.getTxId());
    final Wallet wallet = this.wallet.getValue();
    try {
        if (wallet.isTransactionRelevant(tx)) {
            wallet.receivePending(tx, null);
            new BlockchainServiceLiveData(this).observe(this, blockchainService -> blockchainService.broadcastTransaction(tx));
        } else {
            log.info("tx {} irrelevant", tx.getTxId());
        }
        return true;
    } catch (final VerificationException x) {
        log.info("cannot verify tx " + tx.getTxId() + " received via bluetooth", x);
    }
    return false;
}
Also used : BlockchainServiceLiveData(de.schildbach.wallet.data.BlockchainServiceLiveData) Wallet(org.bitcoinj.wallet.Wallet) VerificationException(org.bitcoinj.core.VerificationException)

Example 14 with Wallet

use of org.bitcoinj.wallet.Wallet in project bitcoin-wallet by bitcoin-wallet.

the class AbstractWalletActivityViewModel method broadcastTransaction.

public ListenableFuture<Transaction> broadcastTransaction(final Transaction tx) throws VerificationException {
    final SettableFuture<Transaction> future = SettableFuture.create();
    wallet.observeForever(new Observer<Wallet>() {

        @Override
        public void onChanged(final Wallet wallet) {
            blockchainService.observeForever(new Observer<BlockchainService>() {

                @Override
                public void onChanged(final BlockchainService blockchainService) {
                    if (wallet.isTransactionRelevant(tx)) {
                        wallet.receivePending(tx, null);
                        final TransactionBroadcast broadcast = blockchainService.broadcastTransaction(tx);
                        if (broadcast != null) {
                            broadcast.future().addListener(() -> {
                                log.info("broadcasting transaction {} complete, dropping all peers", tx.getTxId());
                                blockchainService.dropAllPeers();
                            }, Threading.SAME_THREAD);
                            future.setFuture(broadcast.future());
                        } else {
                            log.info("impediments; will send {} later", tx.getTxId());
                            future.cancel(false);
                        }
                    } else {
                        log.info("tx {} irrelevant", tx.getTxId());
                        future.cancel(false);
                    }
                    AbstractWalletActivityViewModel.this.blockchainService.removeObserver(this);
                }
            });
            AbstractWalletActivityViewModel.this.wallet.removeObserver(this);
        }
    });
    return future;
}
Also used : Transaction(org.bitcoinj.core.Transaction) Wallet(org.bitcoinj.wallet.Wallet) Observer(androidx.lifecycle.Observer) TransactionBroadcast(org.bitcoinj.core.TransactionBroadcast) BlockchainService(de.schildbach.wallet.service.BlockchainService)

Example 15 with Wallet

use of org.bitcoinj.wallet.Wallet in project bitcoin-wallet by bitcoin-wallet.

the class ReportIssueDialogFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final Bundle args = getArguments();
    final int titleResId = args.getInt(KEY_TITLE);
    final int messageResId = args.getInt(KEY_MESSAGE);
    final String subject = args.getString(KEY_SUBJECT);
    final Sha256Hash contextualTransactionHash = args.containsKey(KEY_CONTEXTUAL_TRANSACTION_HASH) ? Sha256Hash.wrap(args.getByteArray(KEY_CONTEXTUAL_TRANSACTION_HASH)) : null;
    final ReportIssueDialogBuilder builder = new ReportIssueDialogBuilder(activity, titleResId, messageResId) {

        @Override
        protected String subject() {
            final StringBuilder builder = new StringBuilder(subject).append(": ");
            final PackageInfo pi = application.packageInfo();
            builder.append(WalletApplication.versionLine(pi));
            final String installer = Installer.installerPackageName(application);
            if (installer != null)
                builder.append(", installer ").append(installer);
            builder.append(", android ").append(Build.VERSION.RELEASE);
            builder.append(" (").append(Build.VERSION.SECURITY_PATCH).append(")");
            builder.append(", ").append(Build.MANUFACTURER);
            if (!Build.BRAND.equalsIgnoreCase(Build.MANUFACTURER))
                builder.append(' ').append(Build.BRAND);
            builder.append(' ').append(Build.MODEL);
            return builder.toString();
        }

        @Override
        protected CharSequence collectApplicationInfo() throws IOException {
            final StringBuilder applicationInfo = new StringBuilder();
            appendApplicationInfo(applicationInfo, application);
            return applicationInfo;
        }

        @Override
        protected CharSequence collectStackTrace() throws IOException {
            final StringBuilder stackTrace = new StringBuilder();
            CrashReporter.appendSavedCrashTrace(stackTrace);
            return stackTrace.length() > 0 ? stackTrace : null;
        }

        @Override
        protected CharSequence collectDeviceInfo() throws IOException {
            final StringBuilder deviceInfo = new StringBuilder();
            appendDeviceInfo(deviceInfo, activity);
            return deviceInfo;
        }

        @Override
        protected CharSequence collectContextualData() {
            if (contextualTransactionHash == null)
                return null;
            final Wallet wallet = walletActivityViewModel.wallet.getValue();
            final Transaction tx = wallet.getTransaction(contextualTransactionHash);
            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');
            final String[] blockExplorers = activity.getResources().getStringArray(R.array.preferences_block_explorer_values);
            for (final String blockExplorer : blockExplorers) contextualData.append(Uri.withAppendedPath(Uri.parse(blockExplorer), "tx/" + tx.getTxId().toString())).append('\n');
            contextualData.append(tx.toString()).append('\n');
            contextualData.append(Constants.HEX.encode(tx.unsafeBitcoinSerialize())).append('\n');
            return contextualData;
        }

        @Override
        protected CharSequence collectWalletDump() {
            return walletActivityViewModel.wallet.getValue().toString(false, false, null, true, true, null);
        }
    };
    final AlertDialog dialog = builder.create();
    dialog.setOnShowListener(d -> {
        positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
        positiveButton.setEnabled(false);
        walletActivityViewModel.wallet.observe(ReportIssueDialogFragment.this, wallet -> positiveButton.setEnabled(true));
    });
    return dialog;
}
Also used : AlertDialog(android.app.AlertDialog) ScriptException(org.bitcoinj.script.ScriptException) Transaction(org.bitcoinj.core.Transaction) Bundle(android.os.Bundle) PackageInfo(android.content.pm.PackageInfo) Wallet(org.bitcoinj.wallet.Wallet) Sha256Hash(org.bitcoinj.core.Sha256Hash)

Aggregations

Wallet (org.bitcoinj.wallet.Wallet)120 Transaction (org.bitcoinj.core.Transaction)34 Test (org.junit.Test)24 Coin (org.bitcoinj.core.Coin)23 SendRequest (org.bitcoinj.wallet.SendRequest)18 IOException (java.io.IOException)17 WalletProtobufSerializer (org.bitcoinj.wallet.WalletProtobufSerializer)17 Address (org.bitcoinj.core.Address)16 BlockTest (org.bitcoinj.core.BlockTest)16 ECKey (org.bitcoinj.core.ECKey)15 WalletTransaction (org.bitcoinj.wallet.WalletTransaction)13 List (java.util.List)12 Set (java.util.Set)12 TransactionOutput (org.bitcoinj.core.TransactionOutput)12 TransactionConfidence (org.bitcoinj.core.TransactionConfidence)11 Preferences (bisq.core.user.Preferences)10 Collectors (java.util.stream.Collectors)10 InsufficientMoneyException (org.bitcoinj.core.InsufficientMoneyException)10 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)9 Inject (javax.inject.Inject)9