fix bug where the DisputeResult was not correctly deserialized.

Added ctor with all transmitted data.
This commit is contained in:
Mike Rosseel 2017-03-13 10:23:44 +01:00
parent d68b3e4862
commit c6e51fdeca
4 changed files with 67 additions and 6 deletions

View file

@ -421,7 +421,7 @@ message DisputeResult {
int64 buyer_payout_amount = 12;
int64 seller_payout_amount = 13;
int64 arbitrator_payout_amount = 14;
string arbitrator_address_asstring = 15;
string arbitrator_address_as_string = 15;
bytes arbitrator_pub_key = 16;
int64 close_date = 17;
bool is_loser_publisher = 18;

View file

@ -89,8 +89,34 @@ public final class DisputeResult implements Payload {
public DisputeResult(String tradeId, int traderId) {
this.tradeId = tradeId;
this.traderId = traderId;
this.disputeFeePolicy = DisputeFeePolicy.LOSER;
init();
}
disputeFeePolicy = DisputeFeePolicy.LOSER;
public DisputeResult(String tradeId, int traderId, DisputeFeePolicy disputeFeePolicy, Winner winner,
int reasonOrdinal, boolean tamperProofEvidence, boolean idVerification, boolean screenCast,
String summaryNotes, DisputeCommunicationMessage disputeCommunicationMessage,
byte[] arbitratorSignature, long buyerPayoutAmount, long sellerPayoutAmount,
long arbitratorPayoutAmount, String arbitratorAddressAsString, byte[] arbitratorPubKey,
long closeDate, boolean isLoserPublisher) {
this.tradeId = tradeId;
this.traderId = traderId;
this.disputeFeePolicy = disputeFeePolicy;
this.winner = winner;
this.reasonOrdinal = reasonOrdinal;
this.tamperProofEvidence = tamperProofEvidence;
this.idVerification = idVerification;
this.screenCast = screenCast;
this.summaryNotes = summaryNotes;
this.disputeCommunicationMessage = disputeCommunicationMessage;
this.arbitratorSignature = arbitratorSignature;
this.buyerPayoutAmount = buyerPayoutAmount;
this.sellerPayoutAmount = sellerPayoutAmount;
this.arbitratorPayoutAmount = arbitratorPayoutAmount;
this.arbitratorAddressAsString = arbitratorAddressAsString;
this.arbitratorPubKey = arbitratorPubKey;
this.closeDate = closeDate;
this.isLoserPublisher = isLoserPublisher;
init();
}
@ -268,7 +294,7 @@ public final class DisputeResult implements Payload {
.setBuyerPayoutAmount(buyerPayoutAmount)
.setSellerPayoutAmount(sellerPayoutAmount)
.setArbitratorPayoutAmount(arbitratorPayoutAmount)
.setArbitratorAddressAsstring(arbitratorAddressAsString)
.setArbitratorAddressAsString(arbitratorAddressAsString)
.setArbitratorPubKey(ByteString.copyFrom(arbitratorPubKey))
.setCloseDate(closeDate)
.setIsLoserPublisher(isLoserPublisher).build();

View file

@ -247,8 +247,20 @@ public class ProtoBufferUtilities {
}
private static Message getDisputeResultMessage(Messages.DisputeResultMessage disputeResultMessage) {
DisputeResult disputeResult = new DisputeResult(disputeResultMessage.getDisputeResult().getTradeId(),
disputeResultMessage.getDisputeResult().getTraderId());
Messages.DisputeResult disputeResultproto = disputeResultMessage.getDisputeResult();
DisputeResult disputeResult = new DisputeResult(disputeResultproto.getTradeId(),
disputeResultproto.getTraderId(), DisputeResult.DisputeFeePolicy.valueOf(disputeResultproto.getDisputeFeePolicy().name()),
DisputeResult.Winner.valueOf(disputeResultproto.getWinner().name()), disputeResultproto.getReasonOrdinal(),
disputeResultproto.getTamperProofEvidence(), disputeResultproto.getIdVerification(), disputeResultproto.getScreenCast(),
disputeResultproto.getSummaryNotes(),
(DisputeCommunicationMessage) getDisputeCommunicationMessage(disputeResultproto.getDisputeCommunicationMessage()),
disputeResultproto.getArbitratorSignature().toByteArray(), disputeResultproto.getBuyerPayoutAmount(),
disputeResultproto.getSellerPayoutAmount(), disputeResultproto.getArbitratorPayoutAmount(),
disputeResultproto.getArbitratorAddressAsString(),
disputeResultproto.getArbitratorPubKey().toByteArray(), disputeResultproto.getCloseDate(),
disputeResultproto.getIsLoserPublisher());
disputeResult.setArbitratorAddressAsString(disputeResultproto.getArbitratorAddressAsString());
return new DisputeResultMessage(disputeResult, getNodeAddress(disputeResultMessage.getMyNodeAddress()));
}
@ -560,7 +572,7 @@ public class ProtoBufferUtilities {
// TODO UNIT TEST THIS !!!
@NotNull
private static Offer.Direction getDirection(Messages.Offer.Direction direction) {
public static Offer.Direction getDirection(Messages.Offer.Direction direction) {
return Offer.Direction.valueOf(direction.name());
}

View file

@ -0,0 +1,23 @@
package io.bisq.p2p.network;
import io.bisq.common.wire.proto.Messages;
import io.bisq.messages.trade.offer.payload.Offer;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Created by mike on 13/03/2017.
*/
public class ProtoBufferUtilitiesTest {
@Test
public void testEnum() {
Messages.Offer.Direction direction = Messages.Offer.Direction.SELL;
Messages.Offer.Direction direction2 = Messages.Offer.Direction.BUY;
Offer.Direction realDirection = ProtoBufferUtilities.getDirection(direction);
Offer.Direction realDirection2 = ProtoBufferUtilities.getDirection(direction2);
assertEquals("SELL", realDirection.name());
assertEquals("BUY", realDirection2.name());
}
}