Search in sources :

Example 1 with InputsAndChangeOutput

use of io.bitsquare.btc.data.InputsAndChangeOutput 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 InputsAndChangeOutput

use of io.bitsquare.btc.data.InputsAndChangeOutput in project bitsquare by bitsquare.

the class TakerCreatesDepositTxInputsAsSeller method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        if (trade.getTradeAmount() != null) {
            Offer offer = trade.getOffer();
            Coin takerInputAmount = FeePolicy.getSecurityDeposit(offer).add(FeePolicy.getFixedTxFeeForTrades(offer)).add(trade.getTradeAmount());
            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();
        } else {
            failed("trade.getTradeAmount() = null");
        }
    } 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)

Aggregations

AddressEntry (io.bitsquare.btc.AddressEntry)2 WalletService (io.bitsquare.btc.WalletService)2 InputsAndChangeOutput (io.bitsquare.btc.data.InputsAndChangeOutput)2 Offer (io.bitsquare.trade.offer.Offer)2 Address (org.bitcoinj.core.Address)2 Coin (org.bitcoinj.core.Coin)2