mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-20 10:22:18 +01:00
first part of the enum fix
This commit is contained in:
parent
70f81789f0
commit
559eb59498
@ -19,12 +19,14 @@ package io.bisq.common.proto;
|
||||
|
||||
import com.google.protobuf.Message;
|
||||
import io.bisq.common.Payload;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ProtoCollectionUtil {
|
||||
@Slf4j
|
||||
public class ProtoUtil {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Convenience
|
||||
@ -39,4 +41,15 @@ public class ProtoCollectionUtil {
|
||||
return extra.apply(o.toProtoMessage());
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static <E extends Enum<E>> E enumLookup(Class<E> e, String id) {
|
||||
E result = null;
|
||||
try {
|
||||
result = Enum.valueOf(e, id);
|
||||
} catch (IllegalArgumentException err) {
|
||||
log.error("Invalid value for enum " + e.getSimpleName() + ": " + id, err);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ package io.bisq.core.dao.vote;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.inject.Inject;
|
||||
import io.bisq.common.app.Version;
|
||||
import io.bisq.common.proto.ProtoCollectionUtil;
|
||||
import io.bisq.common.proto.ProtoUtil;
|
||||
import io.bisq.common.proto.persistable.PersistableList;
|
||||
import io.bisq.common.storage.Storage;
|
||||
import io.bisq.common.util.Utilities;
|
||||
@ -314,7 +314,7 @@ public class VotingManager {
|
||||
PersistableList<VoteItemsList> serializable = new PersistableList<>(voteItemsLists);
|
||||
serializable.setToProto((list) -> PB.PersistableEnvelope.newBuilder()
|
||||
.setVoteItemsList(PB.VoteItemsList.newBuilder()
|
||||
.addAllVoteItem(ProtoCollectionUtil.collectionToProto(voteItemsList.getAllVoteItemList()))).build());
|
||||
.addAllVoteItem(ProtoUtil.collectionToProto(voteItemsList.getAllVoteItemList()))).build());
|
||||
voteItemCollectionsStorage.queueUpForSave(serializable, 500);
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
package io.bisq.core.payment;
|
||||
|
||||
import io.bisq.common.locale.TradeCurrency;
|
||||
import io.bisq.common.proto.ProtoCollectionUtil;
|
||||
import io.bisq.common.proto.ProtoUtil;
|
||||
import io.bisq.common.proto.ProtoResolver;
|
||||
import io.bisq.common.proto.persistable.PersistablePayload;
|
||||
import io.bisq.core.payment.payload.PaymentAccountPayload;
|
||||
@ -77,7 +77,7 @@ public abstract class PaymentAccount implements PersistablePayload {
|
||||
.setCreationDate(creationDate)
|
||||
.setPaymentAccountPayload((PB.PaymentAccountPayload) paymentAccountPayload.toProtoMessage())
|
||||
.setAccountName(accountName)
|
||||
.addAllTradeCurrencies(ProtoCollectionUtil.<PB.TradeCurrency>collectionToProto(tradeCurrencies));
|
||||
.addAllTradeCurrencies(ProtoUtil.<PB.TradeCurrency>collectionToProto(tradeCurrencies));
|
||||
Optional.ofNullable(selectedTradeCurrency).ifPresent(selectedTradeCurrency -> builder.setSelectedTradeCurrency((PB.TradeCurrency) selectedTradeCurrency.toProtoMessage()));
|
||||
return builder.build();
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
package io.bisq.core.trade;
|
||||
|
||||
import com.google.protobuf.Message;
|
||||
import io.bisq.common.proto.ProtoCollectionUtil;
|
||||
import io.bisq.common.proto.ProtoUtil;
|
||||
import io.bisq.common.proto.persistable.PersistableEnvelope;
|
||||
import io.bisq.common.storage.Storage;
|
||||
import io.bisq.core.btc.wallet.BtcWalletService;
|
||||
@ -70,7 +70,7 @@ public final class TradableList<T extends Tradable> implements PersistableEnvelo
|
||||
@Override
|
||||
public Message toProtoMessage() {
|
||||
return PB.PersistableEnvelope.newBuilder().setTradableList(PB.TradableList.newBuilder()
|
||||
.addAllTradable(ProtoCollectionUtil.collectionToProto(list))).build();
|
||||
.addAllTradable(ProtoUtil.collectionToProto(list))).build();
|
||||
}
|
||||
|
||||
public static TradableList fromProto(PB.TradableList proto,
|
||||
|
@ -21,7 +21,7 @@ import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.Message;
|
||||
import io.bisq.common.crypto.KeyRing;
|
||||
import io.bisq.common.crypto.PubKeyRing;
|
||||
import io.bisq.common.proto.ProtoCollectionUtil;
|
||||
import io.bisq.common.proto.ProtoUtil;
|
||||
import io.bisq.common.proto.persistable.PersistablePayload;
|
||||
import io.bisq.common.taskrunner.Model;
|
||||
import io.bisq.core.btc.data.RawTransactionInput;
|
||||
@ -222,10 +222,10 @@ public class ProcessModel implements Model, PersistablePayload {
|
||||
.setPubKeyRing(pubKeyRing.toProtoMessage())
|
||||
.setTakeOfferFeeTxId(takeOfferFeeTxId)
|
||||
.setPayoutTxSignature(ByteString.copyFrom(payoutTxSignature))
|
||||
.addAllTakerAcceptedArbitratorNodeAddresses(ProtoCollectionUtil.collectionToProto(takerAcceptedArbitratorNodeAddresses))
|
||||
.addAllTakerAcceptedMediatorNodeAddresses(ProtoCollectionUtil.collectionToProto(takerAcceptedMediatorNodeAddresses))
|
||||
.addAllTakerAcceptedArbitratorNodeAddresses(ProtoUtil.collectionToProto(takerAcceptedArbitratorNodeAddresses))
|
||||
.addAllTakerAcceptedMediatorNodeAddresses(ProtoUtil.collectionToProto(takerAcceptedMediatorNodeAddresses))
|
||||
.setPreparedDepositTx(ByteString.copyFrom(preparedDepositTx))
|
||||
.addAllRawTransactionInputs(ProtoCollectionUtil.collectionToProto(rawTransactionInputs))
|
||||
.addAllRawTransactionInputs(ProtoUtil.collectionToProto(rawTransactionInputs))
|
||||
.setChangeOutputValue(changeOutputValue)
|
||||
.setChangeOutputAddress(changeOutputAddress)
|
||||
.setUseSavingsWallet(useSavingsWallet)
|
||||
|
@ -18,7 +18,7 @@
|
||||
package io.bisq.core.user;
|
||||
|
||||
import com.google.protobuf.Message;
|
||||
import io.bisq.common.proto.ProtoCollectionUtil;
|
||||
import io.bisq.common.proto.ProtoUtil;
|
||||
import io.bisq.common.proto.ProtoResolver;
|
||||
import io.bisq.common.proto.persistable.PersistableEnvelope;
|
||||
import io.bisq.core.alert.Alert;
|
||||
@ -66,10 +66,10 @@ public class UserPayload implements PersistableEnvelope {
|
||||
public PB.PersistableEnvelope toProtoMessage() {
|
||||
PB.UserPayload.Builder builder = PB.UserPayload.newBuilder()
|
||||
.setAccountId(accountID)
|
||||
.addAllPaymentAccounts(ProtoCollectionUtil.collectionToProto(paymentAccounts))
|
||||
.addAllPaymentAccounts(ProtoUtil.collectionToProto(paymentAccounts))
|
||||
.addAllAcceptedLanguageLocaleCodes(acceptedLanguageLocaleCodes)
|
||||
.addAllAcceptedArbitrators(ProtoCollectionUtil.collectionToProto(acceptedArbitrators, (Message storage) -> ((PB.StoragePayload) storage).getArbitrator()))
|
||||
.addAllAcceptedMediators(ProtoCollectionUtil.collectionToProto(acceptedMediators, (Message storage) -> ((PB.StoragePayload) storage).getMediator()));
|
||||
.addAllAcceptedArbitrators(ProtoUtil.collectionToProto(acceptedArbitrators, (Message storage) -> ((PB.StoragePayload) storage).getArbitrator()))
|
||||
.addAllAcceptedMediators(ProtoUtil.collectionToProto(acceptedMediators, (Message storage) -> ((PB.StoragePayload) storage).getMediator()));
|
||||
|
||||
Optional.ofNullable(currentPaymentAccount)
|
||||
.ifPresent(paymentAccount -> builder.setCurrentPaymentAccount(paymentAccount.toProtoMessage()));
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
package io.bisq.core.util;
|
||||
|
||||
import io.bisq.common.proto.ProtoUtil;
|
||||
import io.bisq.core.offer.AvailabilityResult;
|
||||
import io.bisq.core.offer.OpenOffer;
|
||||
import io.bisq.generated.protobuffer.PB;
|
||||
@ -48,7 +49,18 @@ public class ProtoBufferUtilitiesTest {
|
||||
try {
|
||||
OpenOffer.State finalResult = OpenOffer.State.valueOf(result.name());
|
||||
fail();
|
||||
} catch(IllegalArgumentException e) {
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnknownEnumFix() {
|
||||
PB.OpenOffer.State result = PB.OpenOffer.State.UNKNOWN_FAILURE;
|
||||
try {
|
||||
OpenOffer.State finalResult = ProtoUtil.enumLookup(OpenOffer.State.class, result.name());
|
||||
assertEquals(OpenOffer.State.AVAILABLE, ProtoUtil.enumLookup(OpenOffer.State.class, "AVAILABLE"));
|
||||
} catch (IllegalArgumentException e) {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user