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));
});
}
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());
}
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"));
}
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;
}
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;
}
Aggregations