use of bisq.core.trade.Contract in project bisq-desktop by bisq-network.
the class PendingTradesViewModel method getMyRole.
//
String getMyRole(PendingTradesListItem item) {
Trade trade = item.getTrade();
Contract contract = trade.getContract();
if (contract != null) {
Offer offer = trade.getOffer();
return btcFormatter.getRole(contract.isBuyerMakerAndSellerTaker(), dataModel.isMaker(offer), offer.getCurrencyCode());
} else {
return "";
}
}
use of bisq.core.trade.Contract 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);
}
}
Aggregations