Search in sources :

Example 1 with AddressEntry

use of io.bitsquare.btc.AddressEntry in project bitsquare by bitsquare.

the class ArbitratorRegistrationViewModel method onRegister.

void onRegister(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
    updateDisableStates();
    if (allDataValid) {
        AddressEntry arbitratorDepositAddressEntry = walletService.getOrCreateAddressEntry(AddressEntry.Context.ARBITRATOR);
        String registrationSignature = arbitratorManager.signStorageSignaturePubKey(registrationKey);
        Arbitrator arbitrator = new Arbitrator(p2PService.getAddress(), arbitratorDepositAddressEntry.getPubKey(), arbitratorDepositAddressEntry.getAddressString(), keyRing.getPubKeyRing(), new ArrayList<>(languageCodes), new Date(), registrationKey.getPubKey(), registrationSignature);
        arbitratorManager.addArbitrator(arbitrator, () -> {
            updateDisableStates();
            resultHandler.handleResult();
        }, (errorMessage) -> {
            updateDisableStates();
            errorMessageHandler.handleErrorMessage(errorMessage);
        });
    }
}
Also used : AddressEntry(io.bitsquare.btc.AddressEntry) Arbitrator(io.bitsquare.arbitration.Arbitrator) Date(java.util.Date)

Example 2 with AddressEntry

use of io.bitsquare.btc.AddressEntry 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 3 with AddressEntry

use of io.bitsquare.btc.AddressEntry 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 4 with AddressEntry

use of io.bitsquare.btc.AddressEntry in project bitsquare by bitsquare.

the class CreateAndSignContract method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        checkNotNull(trade.getTakeOfferFeeTxId(), "trade.getTakeOfferFeeTxId() must not be null");
        TradingPeer taker = processModel.tradingPeer;
        PaymentAccountContractData offererPaymentAccountContractData = processModel.getPaymentAccountContractData(trade);
        checkNotNull(offererPaymentAccountContractData, "offererPaymentAccountContractData must not be null");
        PaymentAccountContractData takerPaymentAccountContractData = taker.getPaymentAccountContractData();
        boolean isBuyerOffererAndSellerTaker = trade instanceof BuyerAsOffererTrade;
        NodeAddress buyerNodeAddress = isBuyerOffererAndSellerTaker ? processModel.getMyNodeAddress() : processModel.getTempTradingPeerNodeAddress();
        NodeAddress sellerNodeAddress = isBuyerOffererAndSellerTaker ? processModel.getTempTradingPeerNodeAddress() : processModel.getMyNodeAddress();
        log.debug("isBuyerOffererAndSellerTaker " + isBuyerOffererAndSellerTaker);
        log.debug("buyerAddress " + buyerNodeAddress);
        log.debug("sellerAddress " + sellerNodeAddress);
        WalletService walletService = processModel.getWalletService();
        AddressEntry takerAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.TRADE_PAYOUT);
        AddressEntry offererAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.MULTI_SIG);
        Contract contract = new Contract(processModel.getOffer(), trade.getTradeAmount(), trade.getTradePrice(), trade.getTakeOfferFeeTxId(), buyerNodeAddress, sellerNodeAddress, trade.getArbitratorNodeAddress(), isBuyerOffererAndSellerTaker, processModel.getAccountId(), taker.getAccountId(), offererPaymentAccountContractData, takerPaymentAccountContractData, processModel.getPubKeyRing(), taker.getPubKeyRing(), takerAddressEntry.getAddressString(), taker.getPayoutAddressString(), offererAddressEntry.getPubKey(), taker.getMultiSigPubKey());
        String contractAsJson = Utilities.objectToJson(contract);
        String signature = Sig.sign(processModel.getKeyRing().getSignatureKeyPair().getPrivate(), contractAsJson);
        trade.setContract(contract);
        trade.setContractAsJson(contractAsJson);
        trade.setOffererContractSignature(signature);
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : PaymentAccountContractData(io.bitsquare.payment.PaymentAccountContractData) TradingPeer(io.bitsquare.trade.protocol.trade.TradingPeer) AddressEntry(io.bitsquare.btc.AddressEntry) NodeAddress(io.bitsquare.p2p.NodeAddress) Contract(io.bitsquare.trade.Contract) BuyerAsOffererTrade(io.bitsquare.trade.BuyerAsOffererTrade) WalletService(io.bitsquare.btc.WalletService)

Example 5 with AddressEntry

use of io.bitsquare.btc.AddressEntry in project bitsquare by bitsquare.

the class SendFinalizePayoutTxRequest method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        if (trade.getTradingPeerNodeAddress() != null) {
            WalletService walletService = processModel.getWalletService();
            AddressEntry sellerPayoutAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.TRADE_PAYOUT);
            FinalizePayoutTxRequest message = new FinalizePayoutTxRequest(processModel.getId(), processModel.getPayoutTxSignature(), sellerPayoutAddressEntry.getAddressString(), trade.getLockTimeAsBlockHeight(), processModel.getMyNodeAddress());
            processModel.getP2PService().sendEncryptedMailboxMessage(trade.getTradingPeerNodeAddress(), processModel.tradingPeer.getPubKeyRing(), message, new SendMailboxMessageListener() {

                @Override
                public void onArrived() {
                    log.trace("Message arrived at peer.");
                    trade.setState(Trade.State.SELLER_SENT_FIAT_PAYMENT_RECEIPT_MSG);
                    complete();
                }

                @Override
                public void onStoredInMailbox() {
                    log.trace("Message stored in mailbox.");
                    trade.setState(Trade.State.SELLER_SENT_FIAT_PAYMENT_RECEIPT_MSG);
                    complete();
                }

                @Override
                public void onFault(String errorMessage) {
                    appendToErrorMessage("FinalizePayoutTxRequest sending failed. errorMessage=" + errorMessage);
                    failed(errorMessage);
                }
            });
        } else {
            log.error("trade.getTradingPeerAddress() = " + trade.getTradingPeerNodeAddress());
            failed("A needed dependency is null");
        }
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : AddressEntry(io.bitsquare.btc.AddressEntry) FinalizePayoutTxRequest(io.bitsquare.trade.protocol.trade.messages.FinalizePayoutTxRequest) SendMailboxMessageListener(io.bitsquare.p2p.messaging.SendMailboxMessageListener) WalletService(io.bitsquare.btc.WalletService)

Aggregations

AddressEntry (io.bitsquare.btc.AddressEntry)20 WalletService (io.bitsquare.btc.WalletService)16 Coin (org.bitcoinj.core.Coin)9 Transaction (org.bitcoinj.core.Transaction)6 Address (org.bitcoinj.core.Address)5 Offer (io.bitsquare.trade.offer.Offer)4 TradingPeer (io.bitsquare.trade.protocol.trade.TradingPeer)4 Popup (io.bitsquare.gui.main.overlays.popups.Popup)3 NodeAddress (io.bitsquare.p2p.NodeAddress)3 SendMailboxMessageListener (io.bitsquare.p2p.messaging.SendMailboxMessageListener)3 Contract (io.bitsquare.trade.Contract)3 AddressFormatException (org.bitcoinj.core.AddressFormatException)3 Arbitrator (io.bitsquare.arbitration.Arbitrator)2 InputsAndChangeOutput (io.bitsquare.btc.data.InputsAndChangeOutput)2 PreparedDepositTxAndOffererInputs (io.bitsquare.btc.data.PreparedDepositTxAndOffererInputs)2 RawTransactionInput (io.bitsquare.btc.data.RawTransactionInput)2 TransactionVerificationException (io.bitsquare.btc.exceptions.TransactionVerificationException)2 PaymentAccountContractData (io.bitsquare.payment.PaymentAccountContractData)2 Date (java.util.Date)2 Dispute (io.bitsquare.arbitration.Dispute)1