mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 23:18:17 +01:00
first pass at fixing NPE's
This commit is contained in:
parent
1017502035
commit
a18bbc5f39
3 changed files with 33 additions and 11 deletions
|
@ -53,6 +53,7 @@ import java.text.DecimalFormat;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -629,15 +630,11 @@ public final class Offer implements StoragePayload, RequiresOwnerIsOnlinePayload
|
|||
|
||||
@Override
|
||||
public Messages.StoragePayload toProtoBuf() {
|
||||
return Messages.StoragePayload.newBuilder().setOffer(Messages.Offer.newBuilder()
|
||||
Messages.Offer.Builder offerBuilder = Messages.Offer.newBuilder()
|
||||
.setTTL(TTL)
|
||||
.setDirectionValue(direction.ordinal())
|
||||
.setCurrencyCode(currencyCode)
|
||||
.setPaymentMethodName(paymentMethodName)
|
||||
.setCountryCode(countryCode)
|
||||
.addAllAcceptedCountryCodes(acceptedCountryCodes)
|
||||
.setBankId(bankId)
|
||||
.addAllAcceptedBankIds(getAcceptedBankIds())
|
||||
.addAllArbitratorNodeAddresses(arbitratorNodeAddresses.stream()
|
||||
.map(nodeAddress -> nodeAddress.toProtoBuf()).collect(Collectors.toList()))
|
||||
.setId(id)
|
||||
|
@ -663,9 +660,28 @@ public final class Offer implements StoragePayload, RequiresOwnerIsOnlinePayload
|
|||
.setUseReOpenAfterAutoClose(useReOpenAfterAutoClose)
|
||||
.setLowerClosePrice(lowerClosePrice)
|
||||
.setUpperClosePrice(upperClosePrice)
|
||||
.setIsPrivateOffer(isPrivateOffer)
|
||||
.setHashOfChallenge(hashOfChallenge)
|
||||
.putAllExtraDataMap(extraDataMap)).build();
|
||||
.setIsPrivateOffer(isPrivateOffer);
|
||||
if (Objects.nonNull(countryCode)) {
|
||||
offerBuilder.setCountryCode(countryCode);
|
||||
}
|
||||
if (Objects.nonNull(bankId)) {
|
||||
offerBuilder.setBankId(bankId);
|
||||
}
|
||||
if (Objects.nonNull(acceptedCountryCodes)) {
|
||||
offerBuilder.addAllAcceptedCountryCodes(acceptedCountryCodes);
|
||||
}
|
||||
if (Objects.nonNull(getAcceptedBankIds())) {
|
||||
offerBuilder.addAllAcceptedBankIds(getAcceptedBankIds());
|
||||
}
|
||||
|
||||
if (Objects.nonNull(hashOfChallenge)) {
|
||||
offerBuilder.setHashOfChallenge(hashOfChallenge);
|
||||
}
|
||||
if (Objects.nonNull(extraDataMap)) {
|
||||
offerBuilder.putAllExtraDataMap(extraDataMap);
|
||||
}
|
||||
|
||||
return Messages.StoragePayload.newBuilder().setOffer(offerBuilder).build();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -66,6 +66,10 @@ public class ProtoBufferUtilities {
|
|||
|
||||
|
||||
public static Optional<Message> fromProtoBuf(Messages.Envelope envelope) {
|
||||
if(Objects.isNull(envelope)) {
|
||||
log.warn("fromProtoBuf called with empty envelope.");
|
||||
return Optional.empty();
|
||||
}
|
||||
log.info("Convert protobuffer envelope: {},{}", envelope.getMessageCase(), envelope.toString());
|
||||
Message result = null;
|
||||
switch (envelope.getMessageCase()) {
|
||||
|
@ -94,7 +98,6 @@ public class ProtoBufferUtilities {
|
|||
result = getGetPeersResponse(envelope);
|
||||
break;
|
||||
case GET_DATA_RESPONSE:
|
||||
// TODO protectedstorageentry is NULL
|
||||
result = getGetDataResponse(envelope);
|
||||
break;
|
||||
case PREFIXED_SEALED_AND_SIGNED_MESSAGE:
|
||||
|
@ -550,12 +553,11 @@ public class ProtoBufferUtilities {
|
|||
|
||||
@NotNull
|
||||
private static Message getGetDataResponse(Messages.Envelope envelope) {
|
||||
// TODO protectedstorageentry is NULL
|
||||
HashSet<ProtectedStorageEntry> set = new HashSet<ProtectedStorageEntry>(
|
||||
envelope.getGetDataResponse().getDataSetList()
|
||||
.stream()
|
||||
.map(protectedStorageEntry ->
|
||||
new ProtectedStorageEntry(null, new byte[]{}, 0, null)).collect(Collectors.toList()));
|
||||
getProtectedStorageEntry(protectedStorageEntry)).collect(Collectors.toList()));
|
||||
return new GetDataResponse(set, envelope.getGetDataResponse().getRequestNonce(), envelope.getGetDataResponse().getIsGetUpdatedDataResponse());
|
||||
}
|
||||
|
||||
|
|
|
@ -172,6 +172,10 @@ public class RequestDataHandler implements MessageListener {
|
|||
final HashSet<ProtectedStorageEntry> dataSet = getDataResponse.dataSet;
|
||||
dataSet.stream().forEach(e -> {
|
||||
final StoragePayload storagePayload = e.getStoragePayload();
|
||||
if(storagePayload == null) {
|
||||
log.warn("StoragePayload was null: {}", message.toString());
|
||||
return;
|
||||
}
|
||||
String className = storagePayload.getClass().getSimpleName();
|
||||
if (!payloadByClassName.containsKey(className))
|
||||
payloadByClassName.put(className, new HashSet<>());
|
||||
|
|
Loading…
Add table
Reference in a new issue