Search in sources :

Example 1 with SellerAsTakerTrade

use of bisq.core.trade.SellerAsTakerTrade in project bisq-core by bisq-network.

the class TakerVerifyAndSignContract method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        checkNotNull(trade.getTakerFeeTxId(), "TakeOfferFeeTxId must not be null");
        TradingPeer maker = processModel.getTradingPeer();
        PaymentAccountPayload makerPaymentAccountPayload = maker.getPaymentAccountPayload();
        PaymentAccountPayload takerPaymentAccountPayload = processModel.getPaymentAccountPayload(trade);
        boolean isBuyerMakerAndSellerTaker = trade instanceof SellerAsTakerTrade;
        NodeAddress buyerNodeAddress = isBuyerMakerAndSellerTaker ? processModel.getTempTradingPeerNodeAddress() : processModel.getMyNodeAddress();
        NodeAddress sellerNodeAddress = isBuyerMakerAndSellerTaker ? processModel.getMyNodeAddress() : processModel.getTempTradingPeerNodeAddress();
        log.debug("isBuyerMakerAndSellerTaker " + isBuyerMakerAndSellerTaker);
        log.debug("buyerAddress " + buyerNodeAddress);
        log.debug("sellerAddress " + sellerNodeAddress);
        BtcWalletService walletService = processModel.getBtcWalletService();
        String id = processModel.getOffer().getId();
        AddressEntry takerPayoutAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.TRADE_PAYOUT);
        String takerPayoutAddressString = takerPayoutAddressEntry.getAddressString();
        AddressEntry takerMultiSigAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.MULTI_SIG);
        byte[] takerMultiSigPubKey = processModel.getMyMultiSigPubKey();
        checkArgument(Arrays.equals(takerMultiSigPubKey, takerMultiSigAddressEntry.getPubKey()), "takerMultiSigPubKey from AddressEntry must match the one from the trade data. trade id =" + id);
        final Coin tradeAmount = trade.getTradeAmount();
        checkNotNull(tradeAmount, "tradeAmount must not be null");
        Contract contract = new Contract(processModel.getOffer().getOfferPayload(), tradeAmount.value, trade.getTradePrice().getValue(), trade.getTakerFeeTxId(), buyerNodeAddress, sellerNodeAddress, trade.getArbitratorNodeAddress(), trade.getMediatorNodeAddress(), isBuyerMakerAndSellerTaker, maker.getAccountId(), processModel.getAccountId(), makerPaymentAccountPayload, takerPaymentAccountPayload, maker.getPubKeyRing(), processModel.getPubKeyRing(), maker.getPayoutAddressString(), takerPayoutAddressString, maker.getMultiSigPubKey(), takerMultiSigPubKey);
        String contractAsJson = Utilities.objectToJson(contract);
        log.trace("Contract as json:{}", contractAsJson);
        contract.printDiff(processModel.getTradingPeer().getContractAsJson());
        checkArgument(contractAsJson.equals(processModel.getTradingPeer().getContractAsJson()), "Contracts are not matching");
        String signature = Sig.sign(processModel.getKeyRing().getSignatureKeyPair().getPrivate(), contractAsJson);
        trade.setContract(contract);
        trade.setContractAsJson(contractAsJson);
        trade.setTakerContractSignature(signature);
        try {
            checkNotNull(maker.getPubKeyRing(), "maker.getPubKeyRing() must nto be null");
            Sig.verify(maker.getPubKeyRing().getSignaturePubKey(), contractAsJson, maker.getContractSignature());
            complete();
        } catch (Throwable t) {
            failed("Signature verification failed. " + t.getMessage());
        }
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : Coin(org.bitcoinj.core.Coin) TradingPeer(bisq.core.trade.protocol.TradingPeer) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) AddressEntry(bisq.core.btc.AddressEntry) PaymentAccountPayload(bisq.core.payment.payload.PaymentAccountPayload) SellerAsTakerTrade(bisq.core.trade.SellerAsTakerTrade) NodeAddress(bisq.network.p2p.NodeAddress) Contract(bisq.core.trade.Contract)

Aggregations

AddressEntry (bisq.core.btc.AddressEntry)1 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)1 PaymentAccountPayload (bisq.core.payment.payload.PaymentAccountPayload)1 Contract (bisq.core.trade.Contract)1 SellerAsTakerTrade (bisq.core.trade.SellerAsTakerTrade)1 TradingPeer (bisq.core.trade.protocol.TradingPeer)1 NodeAddress (bisq.network.p2p.NodeAddress)1 Coin (org.bitcoinj.core.Coin)1