mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-22 22:45:21 +01:00
Add equals check and diff for contractAsJson
This commit is contained in:
parent
86c20682e9
commit
01e0ac3f57
4 changed files with 30 additions and 1 deletions
|
@ -24,6 +24,9 @@ import lombok.Getter;
|
|||
import lombok.ToString;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
// That class is used in the contract for creating the contract json. Any change will break the contract.
|
||||
// If a field gets added it need to be be annotated with @JsonExclude (excluded from contract).
|
||||
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
|
|
|
@ -29,12 +29,15 @@ import io.bisq.core.proto.CoreProtoResolver;
|
|||
import io.bisq.generated.protobuffer.PB;
|
||||
import io.bisq.network.p2p.NodeAddress;
|
||||
import lombok.Value;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bitcoinj.core.Coin;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
@Slf4j
|
||||
@Value
|
||||
public final class Contract implements NetworkPayload {
|
||||
private final OfferPayload offerPayload;
|
||||
|
@ -210,6 +213,25 @@ public final class Contract implements NetworkPayload {
|
|||
return Price.valueOf(offerPayload.getCurrencyCode(), tradePrice);
|
||||
}
|
||||
|
||||
public void printDiff(@Nullable String peersContractAsJson) {
|
||||
final String json = Utilities.objectToJson(this);
|
||||
String diff = StringUtils.difference(json, peersContractAsJson);
|
||||
if (!diff.isEmpty()) {
|
||||
log.warn("Diff of both contracts: \n" + diff);
|
||||
log.warn("\n\n------------------------------------------------------------\n"
|
||||
+ "Contract as json\n"
|
||||
+ json
|
||||
+ "\n------------------------------------------------------------\n");
|
||||
|
||||
log.warn("\n\n------------------------------------------------------------\n"
|
||||
+ "Peers contract as json\n"
|
||||
+ peersContractAsJson
|
||||
+ "\n------------------------------------------------------------\n");
|
||||
} else {
|
||||
log.debug("Both contracts are the same");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Contract{" +
|
||||
|
|
|
@ -124,6 +124,7 @@ public class SellerAsTakerSignAndPublishDepositTx extends TradeTask {
|
|||
});
|
||||
trade.setDepositTx(depositTx);
|
||||
} catch (Throwable t) {
|
||||
trade.getContract().printDiff(processModel.getTradingPeer().getContractAsJson());
|
||||
failed(t);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,11 +97,14 @@ public class TakerVerifyAndSignContract extends TradeTask {
|
|||
);
|
||||
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(),
|
||||
|
|
Loading…
Add table
Reference in a new issue