Search in sources :

Example 1 with Address

use of org.bitcoinj.core.Address in project bitsquare by bitsquare.

the class TakerCreatesDepositTxInputsAsBuyer method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        Offer offer = trade.getOffer();
        Coin takerInputAmount = FeePolicy.getSecurityDeposit(offer).add(FeePolicy.getFixedTxFeeForTrades(offer));
        WalletService walletService = processModel.getWalletService();
        AddressEntry takersAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.RESERVED_FOR_TRADE);
        Address changeAddress = walletService.getOrCreateAddressEntry(AddressEntry.Context.AVAILABLE).getAddress();
        InputsAndChangeOutput result = processModel.getTradeWalletService().takerCreatesDepositsTxInputs(takerInputAmount, takersAddressEntry.getAddress(), changeAddress);
        processModel.setRawTransactionInputs(result.rawTransactionInputs);
        processModel.setChangeOutputValue(result.changeOutputValue);
        processModel.setChangeOutputAddress(result.changeOutputAddress);
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : Coin(org.bitcoinj.core.Coin) Address(org.bitcoinj.core.Address) Offer(io.bitsquare.trade.offer.Offer) AddressEntry(io.bitsquare.btc.AddressEntry) InputsAndChangeOutput(io.bitsquare.btc.data.InputsAndChangeOutput) WalletService(io.bitsquare.btc.WalletService)

Example 2 with Address

use of org.bitcoinj.core.Address in project bitsquare by bitsquare.

the class CreateOfferFeeTx method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        NodeAddress selectedArbitratorNodeAddress = ArbitrationSelectionRule.select(model.user.getAcceptedArbitratorAddresses(), model.offer);
        log.debug("selectedArbitratorAddress " + selectedArbitratorNodeAddress);
        Arbitrator selectedArbitrator = model.user.getAcceptedArbitratorByAddress(selectedArbitratorNodeAddress);
        checkNotNull(selectedArbitrator, "selectedArbitrator must not be null at CreateOfferFeeTx");
        WalletService walletService = model.walletService;
        String id = model.offer.getId();
        Address fundingAddress = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.OFFER_FUNDING).getAddress();
        Address reservedForTradeAddress = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.RESERVED_FOR_TRADE).getAddress();
        Address changeAddress = walletService.getOrCreateAddressEntry(AddressEntry.Context.AVAILABLE).getAddress();
        Transaction transaction = model.tradeWalletService.createTradingFeeTx(fundingAddress, reservedForTradeAddress, changeAddress, model.reservedFundsForOffer, model.useSavingsWallet, FeePolicy.getCreateOfferFee(), selectedArbitrator.getBtcAddress());
        // We assume there will be no tx malleability. We add a check later in case the published offer has a different hash.
        // As the txId is part of the offer and therefore change the hash data we need to be sure to have no
        // tx malleability
        model.offer.setOfferFeePaymentTxID(transaction.getHashAsString());
        model.setTransaction(transaction);
        complete();
    } catch (Throwable t) {
        model.offer.setErrorMessage("An error occurred.\n" + "Error message:\n" + t.getMessage());
        failed(t);
    }
}
Also used : NodeAddress(io.bitsquare.p2p.NodeAddress) Address(org.bitcoinj.core.Address) Transaction(org.bitcoinj.core.Transaction) NodeAddress(io.bitsquare.p2p.NodeAddress) Arbitrator(io.bitsquare.arbitration.Arbitrator) WalletService(io.bitsquare.btc.WalletService)

Example 3 with Address

use of org.bitcoinj.core.Address in project bitsquare by bitsquare.

the class SavingsWalletCoinSelector method matchesRequirement.

protected boolean matchesRequirement(TransactionOutput transactionOutput) {
    if (transactionOutput.getScriptPubKey().isSentToAddress() || transactionOutput.getScriptPubKey().isPayToScriptHash()) {
        Address address = transactionOutput.getScriptPubKey().getToAddress(params);
        log.trace("only lookup in savings wallet address entries");
        log.trace(address.toString());
        boolean matches = savingsWalletAddressSet.contains(address);
        if (!matches)
            log.trace("No match found at matchesRequiredAddress address / addressEntry " + address.toString() + " / " + address.toString());
        return matches;
    } else {
        log.warn("transactionOutput.getScriptPubKey() not isSentToAddress or isPayToScriptHash");
        return false;
    }
}
Also used : Address(org.bitcoinj.core.Address)

Example 4 with Address

use of org.bitcoinj.core.Address in project bisq-api by mrosseel.

the class MainViewModelHeadless method updateReservedBalance.

private void updateReservedBalance() {
    Coin sum = Coin.valueOf(openOfferManager.getObservableList().stream().map(openOffer -> {
        final Optional<AddressEntry> addressEntryOptional = btcWalletService.getAddressEntry(openOffer.getId(), AddressEntry.Context.RESERVED_FOR_TRADE);
        if (addressEntryOptional.isPresent()) {
            Address address = addressEntryOptional.get().getAddress();
            return btcWalletService.getBalanceForAddress(address);
        } else {
            return null;
        }
    }).filter(e -> e != null).mapToLong(Coin::getValue).sum());
    reservedBalance.set(formatter.formatCoinWithCode(sum));
}
Also used : Alert(io.bisq.core.alert.Alert) AccountAgeWitnessService(io.bisq.core.payment.AccountAgeWitnessService) Transaction(org.bitcoinj.core.Transaction) NotificationCenter(io.bisq.gui.main.overlays.notifications.NotificationCenter) Coin(org.bitcoinj.core.Coin) Inject(com.google.inject.Inject) User(io.bisq.core.user.User) UserThread(io.bisq.common.UserThread) Security(java.security.Security) TimeoutException(java.util.concurrent.TimeoutException) PrivateNotificationPayload(io.bisq.core.alert.PrivateNotificationPayload) ChainFileLockedException(org.bitcoinj.store.ChainFileLockedException) ListChangeListener(javafx.collections.ListChangeListener) FeeService(io.bisq.core.provider.fee.FeeService) ClosedTradableManager(io.bisq.core.trade.closed.ClosedTradableManager) DecryptedDataTuple(io.bisq.network.crypto.DecryptedDataTuple) DisputeManager(io.bisq.core.arbitration.DisputeManager) CurrencyUtil(io.bisq.common.locale.CurrencyUtil) BlockStoreException(org.bitcoinj.store.BlockStoreException) PaymentMethod(io.bisq.core.payment.payload.PaymentMethod) MonadicBinding(org.fxmisc.easybind.monadic.MonadicBinding) BootstrapListener(io.bisq.network.p2p.BootstrapListener) GUIUtil(io.bisq.gui.util.GUIUtil) PrivateNotificationManager(io.bisq.core.alert.PrivateNotificationManager) Ping(io.bisq.network.p2p.peers.keepalive.messages.Ping) DaoManager(io.bisq.core.dao.DaoManager) BSFormatter(io.bisq.gui.util.BSFormatter) PriceFeedComboBoxItem(io.bisq.gui.main.PriceFeedComboBoxItem) GlobalSettings(io.bisq.common.GlobalSettings) Res(io.bisq.common.locale.Res) WalletsManager(io.bisq.core.btc.wallet.WalletsManager) Subscription(org.fxmisc.easybind.Subscription) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) BtcWalletService(io.bisq.core.btc.wallet.BtcWalletService) EncryptionService(io.bisq.network.crypto.EncryptionService) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) OpenOfferManager(io.bisq.core.offer.OpenOfferManager) Address(org.bitcoinj.core.Address) KeyRing(io.bisq.common.crypto.KeyRing) ObservableList(javafx.collections.ObservableList) PriceFeedService(io.bisq.core.provider.price.PriceFeedService) CryptoCurrencyAccount(io.bisq.core.payment.CryptoCurrencyAccount) TradeManager(io.bisq.core.trade.TradeManager) Socket(java.net.Socket) java.util(java.util) Dispute(io.bisq.core.arbitration.Dispute) ArbitratorManager(io.bisq.core.arbitration.ArbitratorManager) TradeCurrency(io.bisq.common.locale.TradeCurrency) Clock(io.bisq.common.Clock) Preferences(io.bisq.core.user.Preferences) FXCollections(javafx.collections.FXCollections) PerfectMoneyAccount(io.bisq.core.payment.PerfectMoneyAccount) TradeStatisticsManager(io.bisq.core.trade.statistics.TradeStatisticsManager) DontShowAgainLookup(io.bisq.core.user.DontShowAgainLookup) AlertManager(io.bisq.core.alert.AlertManager) FilterManager(io.bisq.core.filter.FilterManager) ConnectionListener(io.bisq.network.p2p.network.ConnectionListener) Trade(io.bisq.core.trade.Trade) FailedTradesManager(io.bisq.core.trade.failed.FailedTradesManager) MarketPrice(io.bisq.core.provider.price.MarketPrice) P2PServiceListener(io.bisq.network.p2p.P2PServiceListener) OpenOffer(io.bisq.core.offer.OpenOffer) Connection(io.bisq.network.p2p.network.Connection) Nullable(javax.annotation.Nullable) javafx.beans.property(javafx.beans.property) BisqEnvironment(io.bisq.core.app.BisqEnvironment) AddressEntry(io.bisq.core.btc.AddressEntry) SealedAndSigned(io.bisq.common.crypto.SealedAndSigned) SetupUtils(io.bisq.core.app.SetupUtils) AppOptionKeys(io.bisq.core.app.AppOptionKeys) IOException(java.io.IOException) CryptoException(io.bisq.common.crypto.CryptoException) TimeUnit(java.util.concurrent.TimeUnit) WalletsSetup(io.bisq.core.btc.wallet.WalletsSetup) CloseConnectionReason(io.bisq.network.p2p.network.CloseConnectionReason) BalanceListener(io.bisq.core.btc.listeners.BalanceListener) P2PService(io.bisq.network.p2p.P2PService) EasyBind(org.fxmisc.easybind.EasyBind) DevEnv(io.bisq.common.app.DevEnv) Timer(io.bisq.common.Timer) InetAddresses(com.google.common.net.InetAddresses) ChangeListener(javafx.beans.value.ChangeListener) Coin(org.bitcoinj.core.Coin) InetSocketAddress(java.net.InetSocketAddress) Address(org.bitcoinj.core.Address) AddressEntry(io.bisq.core.btc.AddressEntry)

Example 5 with Address

use of org.bitcoinj.core.Address in project bitsquare by bitsquare.

the class CreateTakeOfferFeeTx method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        User user = processModel.getUser();
        NodeAddress selectedArbitratorNodeAddress = ArbitrationSelectionRule.select(user.getAcceptedArbitratorAddresses(), processModel.getOffer());
        log.debug("selectedArbitratorAddress " + selectedArbitratorNodeAddress);
        Arbitrator selectedArbitrator = user.getAcceptedArbitratorByAddress(selectedArbitratorNodeAddress);
        checkNotNull(selectedArbitrator, "selectedArbitrator must not be null at CreateTakeOfferFeeTx");
        WalletService walletService = processModel.getWalletService();
        String id = model.getOffer().getId();
        AddressEntry addressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.OFFER_FUNDING);
        AddressEntry reservedForTradeAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.RESERVED_FOR_TRADE);
        AddressEntry changeAddressEntry = walletService.getOrCreateAddressEntry(AddressEntry.Context.AVAILABLE);
        Address fundingAddress = addressEntry.getAddress();
        Address reservedForTradeAddress = reservedForTradeAddressEntry.getAddress();
        Address changeAddress = changeAddressEntry.getAddress();
        Transaction createTakeOfferFeeTx = processModel.getTradeWalletService().createTradingFeeTx(fundingAddress, reservedForTradeAddress, changeAddress, processModel.getFundsNeededForTrade(), processModel.getUseSavingsWallet(), FeePolicy.getTakeOfferFee(), selectedArbitrator.getBtcAddress());
        processModel.setTakeOfferFeeTx(createTakeOfferFeeTx);
        trade.setTakeOfferFeeTxId(createTakeOfferFeeTx.getHashAsString());
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : User(io.bitsquare.user.User) NodeAddress(io.bitsquare.p2p.NodeAddress) Address(org.bitcoinj.core.Address) Transaction(org.bitcoinj.core.Transaction) AddressEntry(io.bitsquare.btc.AddressEntry) NodeAddress(io.bitsquare.p2p.NodeAddress) Arbitrator(io.bitsquare.arbitration.Arbitrator) WalletService(io.bitsquare.btc.WalletService)

Aggregations

Address (org.bitcoinj.core.Address)75 Transaction (org.bitcoinj.core.Transaction)30 Coin (org.bitcoinj.core.Coin)28 TransactionOutput (org.bitcoinj.core.TransactionOutput)14 AddressEntry (bisq.core.btc.AddressEntry)11 TransactionInput (org.bitcoinj.core.TransactionInput)11 Wallet (org.bitcoinj.wallet.Wallet)11 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)10 ArrayList (java.util.ArrayList)10 AddressFormatException (org.bitcoinj.core.AddressFormatException)10 TransactionConfidence (org.bitcoinj.core.TransactionConfidence)10 SendRequest (org.bitcoinj.wallet.SendRequest)9 TextView (android.widget.TextView)8 WalletService (io.bitsquare.btc.WalletService)8 Collectors (java.util.stream.Collectors)8 Nullable (javax.annotation.Nullable)8 TransactionOutPoint (org.bitcoinj.core.TransactionOutPoint)8 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)7 FutureCallback (com.google.common.util.concurrent.FutureCallback)7 List (java.util.List)7