Search in sources :

Example 21 with Wallet

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

the class WalletBalanceLiveData method load.

@Override
protected void load() {
    final Wallet wallet = getWallet();
    AsyncTask.execute(() -> {
        org.bitcoinj.core.Context.propagate(Constants.CONTEXT);
        postValue(wallet.getBalance(balanceType));
    });
}
Also used : Wallet(org.bitcoinj.wallet.Wallet)

Example 22 with Wallet

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

the class WalletApplication method replaceWallet.

public void replaceWallet(final Wallet newWallet) {
    newWallet.cleanup();
    if (newWallet.isDeterministicUpgradeRequired(Constants.UPGRADE_OUTPUT_SCRIPT_TYPE) && !newWallet.isEncrypted())
        newWallet.upgradeToDeterministic(Constants.UPGRADE_OUTPUT_SCRIPT_TYPE, null);
    BlockchainService.resetBlockchain(this);
    final Wallet oldWallet = getWallet();
    synchronized (getWalletLock) {
        // this will also prevent BlockchainService to save
        oldWallet.shutdownAutosaveAndWait();
        walletFiles = newWallet.autosaveToFile(walletFile, Constants.Files.WALLET_AUTOSAVE_DELAY_MS, TimeUnit.MILLISECONDS, null);
    }
    config.maybeIncrementBestChainHeightEver(newWallet.getLastBlockSeenHeight());
    WalletUtils.autoBackupWallet(this, newWallet);
    walletChanged.setValue(Event.simple());
}
Also used : Wallet(org.bitcoinj.wallet.Wallet)

Example 23 with Wallet

use of org.bitcoinj.wallet.Wallet in project bisq-desktop by bisq-network.

the class TransactionsView method initialize.

@Override
public void initialize() {
    dateColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.dateTime")));
    detailsColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.details")));
    addressColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.address")));
    transactionColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.txId", Res.getBaseCurrencyCode())));
    amountColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.amountWithCur", Res.getBaseCurrencyCode())));
    confidenceColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.confirmations", Res.getBaseCurrencyCode())));
    revertTxColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.revert", Res.getBaseCurrencyCode())));
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    tableView.setPlaceholder(new AutoTooltipLabel(Res.get("funds.tx.noTxAvailable")));
    setDateColumnCellFactory();
    setDetailsColumnCellFactory();
    setAddressColumnCellFactory();
    setTransactionColumnCellFactory();
    setAmountColumnCellFactory();
    setConfidenceColumnCellFactory();
    setRevertTxColumnCellFactory();
    dateColumn.setComparator(Comparator.comparing(TransactionsListItem::getDate));
    detailsColumn.setComparator((o1, o2) -> {
        String id1 = o1.getTradable() != null ? o1.getTradable().getId() : o1.getDetails();
        String id2 = o2.getTradable() != null ? o2.getTradable().getId() : o2.getDetails();
        return id1.compareTo(id2);
    });
    addressColumn.setComparator(Comparator.comparing(TransactionsListItem::getAddressString));
    transactionColumn.setComparator(Comparator.comparing(TransactionsListItem::getTxId));
    amountColumn.setComparator(Comparator.comparing(TransactionsListItem::getAmountAsCoin));
    confidenceColumn.setComparator(Comparator.comparingDouble(item -> item.getTxConfidenceIndicator().getProgress()));
    dateColumn.setSortType(TableColumn.SortType.DESCENDING);
    tableView.getSortOrder().add(dateColumn);
    // noinspection deprecation
    walletEventListener = new WalletEventListener() {

        @Override
        public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
            displayedTransactions.update();
        }

        @Override
        public void onCoinsSent(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
            displayedTransactions.update();
        }

        @Override
        public void onReorganize(Wallet wallet) {
            displayedTransactions.update();
        }

        @Override
        public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx) {
        }

        @Override
        public void onWalletChanged(Wallet wallet) {
            displayedTransactions.update();
        }

        @Override
        public void onScriptsChanged(Wallet wallet, List<Script> scripts, boolean isAddingScripts) {
            displayedTransactions.update();
        }

        @Override
        public void onKeysAdded(List<ECKey> keys) {
            displayedTransactions.update();
        }
    };
    keyEventEventHandler = event -> {
        if (Utilities.isAltOrCtrlPressed(KeyCode.R, event))
            revertTxColumn.setVisible(!revertTxColumn.isVisible());
        else if (Utilities.isAltOrCtrlPressed(KeyCode.A, event))
            showStatisticsPopup();
    };
    exportButton.setText(Res.get("shared.exportCSV"));
}
Also used : Button(javafx.scene.control.Button) EventHandler(javafx.event.EventHandler) Transaction(org.bitcoinj.core.Transaction) OpenOffer(bisq.core.offer.OpenOffer) Utilities(bisq.common.util.Utilities) HyperlinkWithIcon(bisq.desktop.components.HyperlinkWithIcon) Coin(org.bitcoinj.core.Coin) Date(java.util.Date) CSVEntryConverter(com.googlecode.jcsv.writer.CSVEntryConverter) VBox(javafx.scene.layout.VBox) BSFormatter(bisq.desktop.util.BSFormatter) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) Res(bisq.core.locale.Res) Locale(java.util.Locale) Map(java.util.Map) TableView(javafx.scene.control.TableView) DateFormat(java.text.DateFormat) SortedList(javafx.collections.transformation.SortedList) Popup(bisq.desktop.main.overlays.popups.Popup) P2PService(bisq.network.p2p.P2PService) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) KeyEvent(javafx.scene.input.KeyEvent) Collectors(java.util.stream.Collectors) ECKey(org.bitcoinj.core.ECKey) FXML(javafx.fxml.FXML) List(java.util.List) Script(org.bitcoinj.script.Script) WalletsSetup(bisq.core.btc.wallet.WalletsSetup) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) Preferences(bisq.core.user.Preferences) ObservableList(javafx.collections.ObservableList) AwesomeIcon(de.jensd.fx.fontawesome.AwesomeIcon) GUIUtil(bisq.desktop.util.GUIUtil) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) Scene(javafx.scene.Scene) WalletEventListener(org.bitcoinj.wallet.listeners.WalletEventListener) ActivatableView(bisq.desktop.common.view.ActivatableView) TransactionConfidence(org.bitcoinj.core.TransactionConfidence) OfferDetailsWindow(bisq.desktop.main.overlays.windows.OfferDetailsWindow) Wallet(org.bitcoinj.wallet.Wallet) HashMap(java.util.HashMap) Tradable(bisq.core.trade.Tradable) FxmlView(bisq.desktop.common.view.FxmlView) TableColumn(javafx.scene.control.TableColumn) ArrayList(java.util.ArrayList) Tuple4(bisq.common.util.Tuple4) Inject(javax.inject.Inject) Tuple2(bisq.common.util.Tuple2) TableCell(javafx.scene.control.TableCell) AddressWithIconAndDirection(bisq.desktop.components.AddressWithIconAndDirection) Callback(javafx.util.Callback) Tooltip(javafx.scene.control.Tooltip) Nullable(javax.annotation.Nullable) KeyCode(javafx.scene.input.KeyCode) TradeDetailsWindow(bisq.desktop.main.overlays.windows.TradeDetailsWindow) Trade(bisq.core.trade.Trade) Stage(javafx.stage.Stage) Comparator(java.util.Comparator) Script(org.bitcoinj.script.Script) Wallet(org.bitcoinj.wallet.Wallet) ECKey(org.bitcoinj.core.ECKey) Coin(org.bitcoinj.core.Coin) WalletEventListener(org.bitcoinj.wallet.listeners.WalletEventListener) Transaction(org.bitcoinj.core.Transaction) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel)

Example 24 with Wallet

use of org.bitcoinj.wallet.Wallet in project bisq-api by mrosseel.

the class BisqProxy method getWalletTransactions.

public WalletTransactionList getWalletTransactions() {
    final Wallet wallet = walletsSetup.getBtcWallet();
    WalletTransactionList walletTransactions = new WalletTransactionList();
    walletTransactions.transactions.addAll(btcWalletService.getTransactions(true).stream().map(transaction -> toWalletTransaction(wallet, transaction)).collect(Collectors.toList()));
    walletTransactions.total = walletTransactions.transactions.size();
    return walletTransactions;
}
Also used : Wallet(org.bitcoinj.wallet.Wallet) WalletTransactionList(network.bisq.api.model.WalletTransactionList)

Example 25 with Wallet

use of org.bitcoinj.wallet.Wallet in project bisq-core by bisq-network.

the class BtcWalletService method getSendRequestForMultipleAddresses.

private SendRequest getSendRequestForMultipleAddresses(Set<String> fromAddresses, String toAddress, Coin amount, Coin fee, @Nullable String changeAddress, @Nullable KeyParameter aesKey) throws AddressFormatException, AddressEntryException, InsufficientMoneyException {
    Transaction tx = new Transaction(params);
    checkArgument(Restrictions.isAboveDust(amount), "The amount is too low (dust limit).");
    final Coin netValue = amount.subtract(fee);
    if (netValue.isNegative())
        throw new InsufficientMoneyException(netValue.multiply(-1), "The mining fee for that transaction exceed the available amount.");
    tx.addOutput(netValue, Address.fromBase58(params, toAddress));
    SendRequest sendRequest = SendRequest.forTx(tx);
    sendRequest.fee = fee;
    sendRequest.feePerKb = Coin.ZERO;
    sendRequest.ensureMinRequiredFee = false;
    sendRequest.aesKey = aesKey;
    sendRequest.shuffleOutputs = false;
    Set<AddressEntry> addressEntries = fromAddresses.stream().map(address -> {
        Optional<AddressEntry> addressEntryOptional = findAddressEntry(address, AddressEntry.Context.AVAILABLE);
        if (!addressEntryOptional.isPresent())
            addressEntryOptional = findAddressEntry(address, AddressEntry.Context.OFFER_FUNDING);
        if (!addressEntryOptional.isPresent())
            addressEntryOptional = findAddressEntry(address, AddressEntry.Context.TRADE_PAYOUT);
        if (!addressEntryOptional.isPresent())
            addressEntryOptional = findAddressEntry(address, AddressEntry.Context.ARBITRATOR);
        return addressEntryOptional;
    }).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toSet());
    if (addressEntries.isEmpty())
        throw new AddressEntryException("No Addresses for withdraw found in our wallet");
    sendRequest.coinSelector = new BtcCoinSelector(walletsSetup.getAddressesFromAddressEntries(addressEntries));
    Optional<AddressEntry> addressEntryOptional = Optional.<AddressEntry>empty();
    AddressEntry changeAddressAddressEntry = null;
    if (changeAddress != null)
        addressEntryOptional = findAddressEntry(changeAddress, AddressEntry.Context.AVAILABLE);
    changeAddressAddressEntry = addressEntryOptional.orElseGet(() -> getFreshAddressEntry());
    checkNotNull(changeAddressAddressEntry, "change address must not be null");
    sendRequest.changeAddress = changeAddressAddressEntry.getAddress();
    return sendRequest;
}
Also used : Arrays(java.util.Arrays) Transaction(org.bitcoinj.core.Transaction) TransactionConfidence(org.bitcoinj.core.TransactionConfidence) Coin(org.bitcoinj.core.Coin) Wallet(org.bitcoinj.wallet.Wallet) LoggerFactory(org.slf4j.LoggerFactory) Inject(javax.inject.Inject) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) TransactionVerificationException(bisq.core.btc.exceptions.TransactionVerificationException) ImmutableList(com.google.common.collect.ImmutableList) AddressEntryList(bisq.core.btc.AddressEntryList) SendRequest(org.bitcoinj.wallet.SendRequest) ErrorMessageHandler(bisq.common.handlers.ErrorMessageHandler) KeyCrypterScrypt(org.bitcoinj.crypto.KeyCrypterScrypt) KeyParameter(org.spongycastle.crypto.params.KeyParameter) DeterministicKey(org.bitcoinj.crypto.DeterministicKey) Nullable(javax.annotation.Nullable) ScriptBuilder(org.bitcoinj.script.ScriptBuilder) AddressFormatException(org.bitcoinj.core.AddressFormatException) AddressEntryException(bisq.core.btc.AddressEntryException) WalletException(bisq.core.btc.exceptions.WalletException) TransactionOutPoint(org.bitcoinj.core.TransactionOutPoint) Logger(org.slf4j.Logger) InsufficientFundsException(bisq.core.btc.InsufficientFundsException) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) InsufficientMoneyException(org.bitcoinj.core.InsufficientMoneyException) Collectors(java.util.stream.Collectors) FutureCallback(com.google.common.util.concurrent.FutureCallback) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) AddressEntry(bisq.core.btc.AddressEntry) TransactionInput(org.bitcoinj.core.TransactionInput) Preferences(bisq.core.user.Preferences) TransactionOutput(org.bitcoinj.core.TransactionOutput) Optional(java.util.Optional) FeeService(bisq.core.provider.fee.FeeService) Address(org.bitcoinj.core.Address) Preconditions(com.google.common.base.Preconditions) NotNull(org.jetbrains.annotations.NotNull) Restrictions(bisq.core.btc.Restrictions) Coin(org.bitcoinj.core.Coin) SendRequest(org.bitcoinj.wallet.SendRequest) AddressEntryException(bisq.core.btc.AddressEntryException) Transaction(org.bitcoinj.core.Transaction) Optional(java.util.Optional) AddressEntry(bisq.core.btc.AddressEntry) InsufficientMoneyException(org.bitcoinj.core.InsufficientMoneyException)

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