Search in sources :

Example 6 with Coin

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

the class RestrictionsTest method testIsMinSpendableAmount.

@Test
public void testIsMinSpendableAmount() {
    Coin amount = null;
    assertFalse("tx unfunded, pending", Restrictions.isAboveFixedTxFeeForTradesAndDust(amount));
    amount = Coin.ZERO;
    assertFalse("tx unfunded, pending", Restrictions.isAboveFixedTxFeeForTradesAndDust(amount));
    amount = FeePolicy.getFixedTxFeeForTrades();
    assertFalse("tx unfunded, pending", Restrictions.isAboveFixedTxFeeForTradesAndDust(amount));
    amount = Transaction.MIN_NONDUST_OUTPUT;
    assertFalse("tx unfunded, pending", Restrictions.isAboveFixedTxFeeForTradesAndDust(amount));
    amount = FeePolicy.getFixedTxFeeForTrades().add(Transaction.MIN_NONDUST_OUTPUT);
    assertFalse("tx unfunded, pending", Restrictions.isAboveFixedTxFeeForTradesAndDust(amount));
    amount = FeePolicy.getFixedTxFeeForTrades().add(Transaction.MIN_NONDUST_OUTPUT).add(Coin.valueOf(1));
    assertTrue("tx unfunded, pending", Restrictions.isAboveFixedTxFeeForTradesAndDust(amount));
}
Also used : Coin(org.bitcoinj.core.Coin) Test(org.junit.Test)

Example 7 with Coin

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

the class BalanceWithConfirmationTextField method setup.

public void setup(Address address, BSFormatter formatter) {
    this.formatter = formatter;
    confidenceListener = new AddressConfidenceListener(address) {

        @Override
        public void onTransactionConfidenceChanged(TransactionConfidence confidence) {
            updateConfidence(confidence);
        }
    };
    walletService.addAddressConfidenceListener(confidenceListener);
    updateConfidence(walletService.getConfidenceForAddress(address));
    balanceListener = new BalanceListener(address) {

        @Override
        public void onBalanceChanged(Coin balance, Transaction tx) {
            updateBalance(balance);
        }
    };
    walletService.addBalanceListener(balanceListener);
    updateBalance(walletService.getBalanceForAddress(address));
}
Also used : Coin(org.bitcoinj.core.Coin) AddressConfidenceListener(io.bitsquare.btc.listeners.AddressConfidenceListener) BalanceListener(io.bitsquare.btc.listeners.BalanceListener) Transaction(org.bitcoinj.core.Transaction) TransactionConfidence(org.bitcoinj.core.TransactionConfidence)

Example 8 with Coin

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

the class SignAndFinalizePayoutTx method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        checkNotNull(trade.getTradeAmount(), "trade.getTradeAmount() must not be null");
        Coin sellerPayoutAmount = FeePolicy.getSecurityDeposit(trade.getOffer());
        Coin buyerPayoutAmount = sellerPayoutAmount.add(trade.getTradeAmount());
        WalletService walletService = processModel.getWalletService();
        AddressEntry buyerAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.TRADE_PAYOUT);
        AddressEntry multiSigAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.MULTI_SIG);
        Transaction transaction = processModel.getTradeWalletService().buyerSignsAndFinalizesPayoutTx(trade.getDepositTx(), processModel.tradingPeer.getSignature(), buyerPayoutAmount, sellerPayoutAmount, buyerAddressEntry.getAddressString(), processModel.tradingPeer.getPayoutAddressString(), multiSigAddressEntry.getKeyPair(), trade.getLockTimeAsBlockHeight(), multiSigAddressEntry.getPubKey(), processModel.tradingPeer.getMultiSigPubKey(), trade.getArbitratorPubKey());
        trade.setPayoutTx(transaction);
        trade.setState(Trade.State.BUYER_COMMITTED_PAYOUT_TX);
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : Coin(org.bitcoinj.core.Coin) Transaction(org.bitcoinj.core.Transaction) AddressEntry(io.bitsquare.btc.AddressEntry) WalletService(io.bitsquare.btc.WalletService)

Example 9 with Coin

use of org.bitcoinj.core.Coin 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 10 with Coin

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

the class SignPayoutTx method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        checkNotNull(trade.getTradeAmount(), "trade.getTradeAmount() must not be null");
        checkNotNull(trade.getDepositTx(), "trade.getDepositTx() must not be null");
        Coin sellerPayoutAmount = FeePolicy.getSecurityDeposit(trade.getOffer());
        Coin buyerPayoutAmount = sellerPayoutAmount.add(trade.getTradeAmount());
        // We use the sellers LastBlockSeenHeight, which might be different to the buyers one.
        // If lock time is 0 we set lockTimeAsBlockHeight to 0 to mark it as "not set". 
        // In the tradeWallet we apply the lockTime only if it is set, otherwise we use the default values for 
        // transaction lockTime and sequence number
        long lockTime = trade.getOffer().getPaymentMethod().getLockTime();
        long lockTimeAsBlockHeight = 0;
        if (lockTime > 0)
            lockTimeAsBlockHeight = processModel.getTradeWalletService().getLastBlockSeenHeight() + lockTime;
        trade.setLockTimeAsBlockHeight(lockTimeAsBlockHeight);
        String id = processModel.getOffer().getId();
        WalletService walletService = processModel.getWalletService();
        AddressEntry sellerPayoutAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.TRADE_PAYOUT);
        AddressEntry multiSigAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.MULTI_SIG);
        byte[] payoutTxSignature = processModel.getTradeWalletService().sellerSignsPayoutTx(trade.getDepositTx(), buyerPayoutAmount, sellerPayoutAmount, processModel.tradingPeer.getPayoutAddressString(), sellerPayoutAddressEntry.getAddressString(), multiSigAddressEntry.getKeyPair(), lockTimeAsBlockHeight, processModel.tradingPeer.getMultiSigPubKey(), multiSigAddressEntry.getPubKey(), trade.getArbitratorPubKey());
        processModel.setPayoutTxSignature(payoutTxSignature);
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : Coin(org.bitcoinj.core.Coin) AddressEntry(io.bitsquare.btc.AddressEntry) WalletService(io.bitsquare.btc.WalletService)

Aggregations

Coin (org.bitcoinj.core.Coin)35 AddressEntry (io.bitsquare.btc.AddressEntry)13 WalletService (io.bitsquare.btc.WalletService)13 Transaction (org.bitcoinj.core.Transaction)11 Popup (io.bitsquare.gui.main.overlays.popups.Popup)9 BalanceListener (io.bitsquare.btc.listeners.BalanceListener)8 Offer (io.bitsquare.trade.offer.Offer)7 Address (org.bitcoinj.core.Address)6 BSFormatter (io.bitsquare.gui.util.BSFormatter)5 Trade (io.bitsquare.trade.Trade)5 Inject (com.google.inject.Inject)4 Log (io.bitsquare.app.Log)4 UserThread (io.bitsquare.common.UserThread)4 DevFlags (io.bitsquare.app.DevFlags)3 Dispute (io.bitsquare.arbitration.Dispute)3 DisputeManager (io.bitsquare.arbitration.DisputeManager)3 TradeWalletService (io.bitsquare.btc.TradeWalletService)3 MarketPrice (io.bitsquare.btc.pricefeed.MarketPrice)3 PriceFeedService (io.bitsquare.btc.pricefeed.PriceFeedService)3 CurrencyUtil (io.bitsquare.locale.CurrencyUtil)3