Delete TradeStatistics (version 1)

This commit is contained in:
chimp1984 2020-10-05 17:53:13 -05:00
parent b2665bdd2c
commit 6d43c09b33
No known key found for this signature in database
GPG key ID: 9801B4EC591F90E3
3 changed files with 2 additions and 264 deletions

View file

@ -59,7 +59,6 @@ import bisq.core.trade.messages.PayoutTxPublishedMessage;
import bisq.core.trade.messages.PeerPublishedDelayedPayoutTxMessage;
import bisq.core.trade.messages.RefreshTradeStateRequest;
import bisq.core.trade.messages.TraderSignedWitnessMessage;
import bisq.core.trade.statistics.TradeStatistics;
import bisq.network.p2p.AckMessage;
import bisq.network.p2p.BundleOfEnvelopes;
@ -265,9 +264,6 @@ public class CoreNetworkProtoResolver extends CoreProtoResolver implements Netwo
return RefundAgent.fromProto(proto.getRefundAgent());
case FILTER:
return Filter.fromProto(proto.getFilter());
case TRADE_STATISTICS:
// Still used to convert TradeStatistics data from pre v0.6 versions
return TradeStatistics.fromProto(proto.getTradeStatistics());
case MAILBOX_STORAGE_PAYLOAD:
return MailboxStoragePayload.fromProto(proto.getMailboxStoragePayload());
case OFFER_PAYLOAD:

View file

@ -1,236 +0,0 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/
package bisq.core.trade.statistics;
import bisq.core.monetary.Altcoin;
import bisq.core.monetary.AltcoinExchangeRate;
import bisq.core.monetary.Price;
import bisq.core.monetary.Volume;
import bisq.core.offer.OfferPayload;
import bisq.network.p2p.storage.payload.ExpirablePayload;
import bisq.network.p2p.storage.payload.ProcessOncePersistableNetworkPayload;
import bisq.network.p2p.storage.payload.ProtectedStoragePayload;
import bisq.common.crypto.Sig;
import bisq.common.proto.persistable.PersistablePayload;
import bisq.common.util.CollectionUtils;
import bisq.common.util.ExtraDataMapValidator;
import bisq.common.util.JsonExclude;
import com.google.protobuf.ByteString;
import org.bitcoinj.core.Coin;
import org.bitcoinj.utils.ExchangeRate;
import org.bitcoinj.utils.Fiat;
import java.security.PublicKey;
import java.util.Date;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import lombok.EqualsAndHashCode;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Nullable;
/**
* @deprecated Was used in pre v0.6.0 version
*/
@Deprecated
@Slf4j
@EqualsAndHashCode(exclude = {"signaturePubKeyBytes"})
@Value
public final class TradeStatistics implements ProcessOncePersistableNetworkPayload, ProtectedStoragePayload, ExpirablePayload, PersistablePayload {
private final OfferPayload.Direction direction;
private final String baseCurrency;
private final String counterCurrency;
private final String offerPaymentMethod;
private final long offerDate;
private final boolean offerUseMarketBasedPrice;
private final double offerMarketPriceMargin;
private final long offerAmount;
private final long offerMinAmount;
private final String offerId;
private final long tradePrice;
private final long tradeAmount;
private final long tradeDate;
private final String depositTxId;
@JsonExclude
private final byte[] signaturePubKeyBytes;
@JsonExclude
transient private final PublicKey signaturePubKey;
// Should be only used in emergency case if we need to add data but do not want to break backward compatibility
// at the P2P network storage checks. The hash of the object will be used to verify if the data is valid. Any new
// field in a class would break that hash and therefore break the storage mechanism.
@Nullable
private Map<String, String> extraDataMap;
public TradeStatistics(OfferPayload offerPayload,
Price tradePrice,
Coin tradeAmount,
Date tradeDate,
String depositTxId,
byte[] signaturePubKeyBytes) {
this(offerPayload.getDirection(),
offerPayload.getBaseCurrencyCode(),
offerPayload.getCounterCurrencyCode(),
offerPayload.getPaymentMethodId(),
offerPayload.getDate(),
offerPayload.isUseMarketBasedPrice(),
offerPayload.getMarketPriceMargin(),
offerPayload.getAmount(),
offerPayload.getMinAmount(),
offerPayload.getId(),
tradePrice.getValue(),
tradeAmount.value,
tradeDate.getTime(),
depositTxId,
signaturePubKeyBytes,
null);
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
TradeStatistics(OfferPayload.Direction direction,
String baseCurrency,
String counterCurrency,
String offerPaymentMethod,
long offerDate,
boolean offerUseMarketBasedPrice,
double offerMarketPriceMargin,
long offerAmount,
long offerMinAmount,
String offerId,
long tradePrice,
long tradeAmount,
long tradeDate,
String depositTxId,
byte[] signaturePubKeyBytes,
@Nullable Map<String, String> extraDataMap) {
this.direction = direction;
this.baseCurrency = baseCurrency;
this.counterCurrency = counterCurrency;
this.offerPaymentMethod = offerPaymentMethod;
this.offerDate = offerDate;
this.offerUseMarketBasedPrice = offerUseMarketBasedPrice;
this.offerMarketPriceMargin = offerMarketPriceMargin;
this.offerAmount = offerAmount;
this.offerMinAmount = offerMinAmount;
this.offerId = offerId;
this.tradePrice = tradePrice;
this.tradeAmount = tradeAmount;
this.tradeDate = tradeDate;
this.depositTxId = depositTxId;
this.signaturePubKeyBytes = signaturePubKeyBytes;
this.extraDataMap = ExtraDataMapValidator.getValidatedExtraDataMap(extraDataMap);
signaturePubKey = Sig.getPublicKeyFromBytes(signaturePubKeyBytes);
}
@Override
public protobuf.StoragePayload toProtoMessage() {
final protobuf.TradeStatistics.Builder builder = protobuf.TradeStatistics.newBuilder()
.setDirection(OfferPayload.Direction.toProtoMessage(direction))
.setBaseCurrency(baseCurrency)
.setCounterCurrency(counterCurrency)
.setPaymentMethodId(offerPaymentMethod)
.setOfferDate(offerDate)
.setOfferUseMarketBasedPrice(offerUseMarketBasedPrice)
.setOfferMarketPriceMargin(offerMarketPriceMargin)
.setOfferAmount(offerAmount)
.setOfferMinAmount(offerMinAmount)
.setOfferId(offerId)
.setTradePrice(tradePrice)
.setTradeAmount(tradeAmount)
.setTradeDate(tradeDate)
.setDepositTxId(depositTxId)
.setSignaturePubKeyBytes(ByteString.copyFrom(signaturePubKeyBytes));
Optional.ofNullable(extraDataMap).ifPresent(builder::putAllExtraData);
return protobuf.StoragePayload.newBuilder().setTradeStatistics(builder).build();
}
public protobuf.TradeStatistics toProtoTradeStatistics() {
return toProtoMessage().getTradeStatistics();
}
public static TradeStatistics fromProto(protobuf.TradeStatistics proto) {
return new TradeStatistics(
OfferPayload.Direction.fromProto(proto.getDirection()),
proto.getBaseCurrency(),
proto.getCounterCurrency(),
proto.getPaymentMethodId(),
proto.getOfferDate(),
proto.getOfferUseMarketBasedPrice(),
proto.getOfferMarketPriceMargin(),
proto.getOfferAmount(),
proto.getOfferMinAmount(),
proto.getOfferId(),
proto.getTradePrice(),
proto.getTradeAmount(),
proto.getTradeDate(),
proto.getDepositTxId(),
proto.getSignaturePubKeyBytes().toByteArray(),
CollectionUtils.isEmpty(proto.getExtraDataMap()) ? null : proto.getExtraDataMap());
}
///////////////////////////////////////////////////////////////////////////////////////////
// Getters
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public long getTTL() {
return TimeUnit.DAYS.toMillis(30);
}
@Override
public PublicKey getOwnerPubKey() {
return signaturePubKey;
}
public Date getTradeDate() {
return new Date(tradeDate);
}
public Price getTradePrice() {
return Price.valueOf(getCurrencyCode(), tradePrice);
}
public String getCurrencyCode() {
return baseCurrency.equals("BTC") ? counterCurrency : baseCurrency;
}
public Coin getTradeAmount() {
return Coin.valueOf(tradeAmount);
}
public Volume getTradeVolume() {
if (getTradePrice().getMonetary() instanceof Altcoin)
return new Volume(new AltcoinExchangeRate((Altcoin) getTradePrice().getMonetary()).coinToAltcoin(getTradeAmount()));
else
return new Volume(new ExchangeRate((Fiat) getTradePrice().getMonetary()).coinToFiat(getTradeAmount()));
}
}

View file

@ -510,9 +510,7 @@ message StoragePayload {
Mediator mediator = 3;
Filter filter = 4;
// not used anymore from v0.6 on. But leave it for receiving TradeStatistics objects from older
// versions and convert it to TradeStatistics2 objects.
TradeStatistics trade_statistics = 5 [deprecated = true];
// TradeStatistics trade_statistics = 5 [deprecated = true]; Removed in v.1.4.0
MailboxStoragePayload mailbox_storage_payload = 6;
OfferPayload offer_payload = 7;
@ -651,27 +649,7 @@ message Filter {
bool disable_auto_conf = 24;
}
// not used anymore from v0.6 on. But leave it for receiving TradeStatistics objects from older
// versions and convert it to TradeStatistics2 objects.
message TradeStatistics {
string base_currency = 1;
string counter_currency = 2;
OfferPayload.Direction direction = 3;
int64 trade_price = 4;
int64 trade_amount = 5;
int64 trade_date = 6;
string payment_method_id = 7;
int64 offer_date = 8;
bool offer_use_market_based_price = 9;
double offer_market_price_margin = 10;
int64 offer_amount = 11;
int64 offer_min_amount = 12;
string offer_id = 13;
string deposit_tx_id = 14;
bytes signature_pub_key_bytes = 15;
map<string, string> extra_data = 16;
}
// Deprecated
message TradeStatistics2 {
string base_currency = 1 [deprecated = true];
string counter_currency = 2 [deprecated = true];