mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 18:03:12 +01:00
Move getRandomOfferId method to OfferUtil
Add more methods to OfferUtil Cleanups
This commit is contained in:
parent
a3b3d561ec
commit
9d106468b0
@ -183,7 +183,7 @@ class CoreOffersService {
|
||||
throw new IllegalArgumentException(format("payment account with id %s not found", paymentAccountId));
|
||||
|
||||
String upperCaseCurrencyCode = currencyCode.toUpperCase();
|
||||
String offerId = createOfferService.getRandomOfferId();
|
||||
String offerId = OfferUtil.getRandomOfferId();
|
||||
OfferDirection direction = OfferDirection.valueOf(directionAsString.toUpperCase());
|
||||
Price price = Price.valueOf(upperCaseCurrencyCode, priceStringToLong(priceAsString, upperCaseCurrencyCode));
|
||||
Coin amount = Coin.valueOf(amountAsLong);
|
||||
|
@ -57,6 +57,7 @@ public class BsqBalanceInfo implements Payload {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PROTO BUFFER
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// TODO rename availableConfirmedBalance in proto if possible
|
||||
@Override
|
||||
public bisq.proto.grpc.BsqBalanceInfo toProtoMessage() {
|
||||
|
@ -34,7 +34,7 @@ import static bisq.core.api.model.PaymentAccountPayloadInfo.toPaymentAccountPayl
|
||||
@Getter
|
||||
public class TradeInfo implements Payload {
|
||||
|
||||
// The client cannot see bisq.core.trade.Trade or its fromProto method. We use the
|
||||
// The client cannot see Trade or its fromProto method. We use the
|
||||
// lighter weight TradeInfo proto wrapper instead, containing just enough fields to
|
||||
// view and interact with trades.
|
||||
|
||||
|
@ -84,7 +84,8 @@ public class P2PNetworkSetup {
|
||||
this.preferences = preferences;
|
||||
}
|
||||
|
||||
BooleanProperty init(Runnable initWalletServiceHandler, @Nullable Consumer<Boolean> displayTorNetworkSettingsHandler) {
|
||||
BooleanProperty init(Runnable initWalletServiceHandler,
|
||||
@Nullable Consumer<Boolean> displayTorNetworkSettingsHandler) {
|
||||
StringProperty bootstrapState = new SimpleStringProperty();
|
||||
StringProperty bootstrapWarning = new SimpleStringProperty();
|
||||
BooleanProperty hiddenServicePublished = new SimpleBooleanProperty();
|
||||
|
@ -45,8 +45,10 @@ import bisq.core.util.coin.CoinUtil;
|
||||
import bisq.network.p2p.P2PService;
|
||||
|
||||
import bisq.common.app.Capabilities;
|
||||
import bisq.common.app.Version;
|
||||
import bisq.common.util.MathUtils;
|
||||
import bisq.common.util.Tuple2;
|
||||
import bisq.common.util.Utilities;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.bitcoinj.core.Transaction;
|
||||
@ -60,6 +62,7 @@ import javax.inject.Singleton;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -115,6 +118,40 @@ public class OfferUtil {
|
||||
this.tradeStatisticsManager = tradeStatisticsManager;
|
||||
}
|
||||
|
||||
public static String getRandomOfferId() {
|
||||
return Utilities.getRandomPrefix(5, 8) + "-" +
|
||||
UUID.randomUUID() + "-" +
|
||||
getStrippedVersion();
|
||||
}
|
||||
|
||||
public static String getStrippedVersion() {
|
||||
return Version.VERSION.replace(".", "");
|
||||
}
|
||||
|
||||
// We add a counter at the end of the offer id signalling the number of times that offer has
|
||||
// been mutated ether due edit or due pow adjustments.
|
||||
public static String getOfferIdWithMutationCounter(String id) {
|
||||
String[] split = id.split("-");
|
||||
String base = id;
|
||||
int counter = 0;
|
||||
if (split.length > 7) {
|
||||
String counterString = split[7];
|
||||
int endIndex = id.length() - counterString.length() - 1;
|
||||
base = id.substring(0, endIndex);
|
||||
try {
|
||||
counter = Integer.parseInt(counterString);
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
counter++;
|
||||
return base + "-" + counter;
|
||||
}
|
||||
|
||||
public static String getVersionFromId(String id) {
|
||||
String[] split = id.split("-");
|
||||
return split[6];
|
||||
}
|
||||
|
||||
public void maybeSetFeePaymentCurrencyPreference(String feeCurrencyCode) {
|
||||
if (!feeCurrencyCode.isEmpty()) {
|
||||
if (!isValidFeePaymentCurrencyCode.test(feeCurrencyCode))
|
||||
|
@ -39,7 +39,6 @@ import bisq.network.p2p.P2PService;
|
||||
import bisq.common.app.Version;
|
||||
import bisq.common.crypto.PubKeyRing;
|
||||
import bisq.common.util.Tuple2;
|
||||
import bisq.common.util.Utilities;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
|
||||
@ -52,7 +51,6 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@ -96,12 +94,6 @@ public class CreateOfferService {
|
||||
// API
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public String getRandomOfferId() {
|
||||
return Utilities.getRandomPrefix(5, 8) + "-" +
|
||||
UUID.randomUUID().toString() + "-" +
|
||||
Version.VERSION.replace(".", "");
|
||||
}
|
||||
|
||||
public Offer createAndGetOffer(String offerId,
|
||||
OfferDirection direction,
|
||||
String currencyCode,
|
||||
|
@ -176,7 +176,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs
|
||||
this.navigation = navigation;
|
||||
this.tradeStatisticsManager = tradeStatisticsManager;
|
||||
|
||||
offerId = createOfferService.getRandomOfferId();
|
||||
offerId = OfferUtil.getRandomOfferId();
|
||||
shortOfferId = Utilities.getShortId(offerId);
|
||||
addressEntry = btcWalletService.getOrCreateAddressEntry(offerId, AddressEntry.Context.OFFER_FUNDING);
|
||||
|
||||
|
@ -24,7 +24,6 @@ import org.bitcoinj.core.Coin;
|
||||
import javafx.collections.FXCollections;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -61,7 +60,6 @@ public class CreateOfferDataModelTest {
|
||||
when(btcWalletService.getOrCreateAddressEntry(anyString(), any())).thenReturn(addressEntry);
|
||||
when(preferences.isUsePercentageBasedPrice()).thenReturn(true);
|
||||
when(preferences.getBuyerSecurityDepositAsPercent(null)).thenReturn(0.01);
|
||||
when(createOfferService.getRandomOfferId()).thenReturn(UUID.randomUUID().toString());
|
||||
when(tradeStats.getObservableTradeStatisticsSet()).thenReturn(FXCollections.observableSet());
|
||||
|
||||
model = new CreateOfferDataModel(createOfferService,
|
||||
|
@ -56,8 +56,6 @@ import javafx.collections.FXCollections;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -118,7 +116,6 @@ public class CreateOfferViewModelTest {
|
||||
when(preferences.getUserCountry()).thenReturn(new Country("ES", "Spain", null));
|
||||
when(bsqFormatter.formatCoin(any())).thenReturn("0");
|
||||
when(bsqWalletService.getAvailableBalance()).thenReturn(Coin.ZERO);
|
||||
when(createOfferService.getRandomOfferId()).thenReturn(UUID.randomUUID().toString());
|
||||
when(tradeStats.getObservableTradeStatisticsSet()).thenReturn(FXCollections.observableSet());
|
||||
|
||||
CreateOfferDataModel dataModel = new CreateOfferDataModel(createOfferService,
|
||||
|
@ -33,8 +33,6 @@ import javafx.collections.FXCollections;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@ -95,7 +93,6 @@ public class EditOfferDataModelTest {
|
||||
when(preferences.getUserCountry()).thenReturn(new Country("US", "United States", null));
|
||||
when(bsqFormatter.formatCoin(any())).thenReturn("0");
|
||||
when(bsqWalletService.getAvailableBalance()).thenReturn(Coin.ZERO);
|
||||
when(createOfferService.getRandomOfferId()).thenReturn(UUID.randomUUID().toString());
|
||||
|
||||
model = new EditOfferDataModel(createOfferService,
|
||||
null,
|
||||
|
Loading…
Reference in New Issue
Block a user