Cleanup PB definitions and methods

This commit is contained in:
Manfred Karrer 2017-06-05 23:13:51 +02:00
parent 3f756d4923
commit e5b775d07c
33 changed files with 280 additions and 328 deletions

View File

@ -38,8 +38,8 @@ message NetworkEnvelope {
PrefixedSealedAndSignedMessage prefixed_sealed_and_signed_message = 16;
PayDepositRequest pay_deposit_request = 17;
DepositTxPublishedMessage deposit_tx_published_message = 18;
PublishDepositTxRequest publish_deposit_tx_request = 19;
PublishDepositTxRequest publish_deposit_tx_request = 18;
DepositTxPublishedMessage deposit_tx_published_message = 19;
FiatTransferStartedMessage fiat_transfer_started_message = 20;
FinalizePayoutTxRequest finalize_payout_tx_request = 21;
PayoutTxPublishedMessage payout_tx_published_message = 22;
@ -48,7 +48,7 @@ message NetworkEnvelope {
PeerOpenedDisputeMessage peer_opened_dispute_message = 24;
DisputeCommunicationMessage dispute_communication_message = 25;
DisputeResultMessage dispute_result_message = 26;
PeerPublishedPayoutTxMessage peer_published_payout_tx_message = 27;
PeerPublishedDisputePayoutTxMessage peer_published_dispute_payout_tx_message = 27;
PrivateNotificationMessage private_notification_message = 28;
@ -185,64 +185,52 @@ message PayDepositRequest {
repeated NodeAddress accepted_mediator_node_addresses = 18;
NodeAddress arbitrator_node_address = 19;
NodeAddress mediator_node_address = 20;
}
message DepositTxPublishedMessage {
int32 message_version = 1;
string trade_id = 2;
bytes deposit_tx = 3;
NodeAddress sender_node_address = 4;
string uid = 5;
string uid = 21;
}
message PublishDepositTxRequest {
int32 message_version = 1;
string trade_id = 2;
PaymentAccountPayload maker_payment_account_payload = 3;
string maker_account_id = 4;
string maker_contract_as_json = 5;
string maker_contract_signature = 6;
string maker_payout_address_string = 7;
bytes prepared_deposit_tx = 8;
repeated RawTransactionInput maker_inputs = 9;
bytes maker_multi_sig_pub_key = 10;
NodeAddress sender_node_address = 11;
string uid = 12;
string trade_id = 1;
PaymentAccountPayload maker_payment_account_payload = 2;
string maker_account_id = 3;
string maker_contract_as_json = 4;
string maker_contract_signature = 5;
string maker_payout_address_string = 6;
bytes prepared_deposit_tx = 7;
repeated RawTransactionInput maker_inputs = 8;
bytes maker_multi_sig_pub_key = 9;
NodeAddress sender_node_address = 10;
string uid = 11;
}
message FiatTransferStartedMessage {
int32 message_version = 1;
string trade_id = 2;
string buyer_payout_address = 3;
NodeAddress sender_node_address = 4;
bytes buyer_signature = 5;
string uid = 6;
}
message FinalizePayoutTxRequest {
int32 message_version = 1;
string trade_id = 2;
bytes seller_signature = 3;
string seller_payout_address = 4;
NodeAddress sender_node_address = 5;
string uid = 6;
}
message PayoutTxPublishedMessage {
string uid = 1;
int32 message_version = 2;
string trade_id = 3;
bytes payout_tx = 4;
NodeAddress sender_node_address = 5;
}
message PeerPublishedPayoutTxMessage {
bytes transaction = 1;
string trade_id = 2;
message DepositTxPublishedMessage {
string trade_id = 1;
bytes deposit_tx = 2;
NodeAddress sender_node_address = 3;
string uid = 4;
}
message FiatTransferStartedMessage {
string trade_id = 1;
string buyer_payout_address = 2;
NodeAddress sender_node_address = 3;
bytes buyer_signature = 4;
string uid = 5;
}
message FinalizePayoutTxRequest {
string trade_id = 1;
bytes seller_signature = 2;
string seller_payout_address = 3;
NodeAddress sender_node_address = 4;
string uid = 5;
}
message PayoutTxPublishedMessage {
string trade_id = 1;
bytes payout_tx = 2;
NodeAddress sender_node_address = 3;
string uid = 4;
}
// dispute
@ -278,12 +266,18 @@ message DisputeResultMessage {
NodeAddress sender_node_address = 3;
}
message PeerPublishedDisputePayoutTxMessage {
string uid = 1;
bytes transaction = 2;
string trade_id = 3;
NodeAddress sender_node_address = 4;
}
message PrivateNotificationMessage {
int32 message_version = 1;
string uid = 2;
NodeAddress sender_node_address = 3;
PrivateNotificationPayload private_notification_payload = 4;
string uid = 1;
NodeAddress sender_node_address = 2;
PrivateNotificationPayload private_notification_payload = 3;
}
@ -293,10 +287,12 @@ message GetBsqBlocksRequest {
int32 from_block_height = 1;
}
// TODO not fully impl. yet, serialized data used atm
message GetBsqBlocksResponse {
bytes bsq_blocks_bytes = 1;
}
// TODO not fully impl. yet, serialized data used atm
message NewBsqBlockBroadcastMessage {
bytes bsq_block_bytes = 1;
}
@ -342,10 +338,10 @@ message StoragePayload {
Arbitrator arbitrator = 2;
Mediator mediator = 3;
Filter filter = 4;
CompensationRequestPayload compensation_request_payload = 5;
TradeStatistics trade_statistics = 6;
MailboxStoragePayload mailbox_storage_payload = 7;
OfferPayload offer_payload = 8;
TradeStatistics trade_statistics = 5;
MailboxStoragePayload mailbox_storage_payload = 6;
OfferPayload offer_payload = 7;
CompensationRequestPayload compensation_request_payload = 8;
}
}
@ -378,6 +374,22 @@ message DataAndSeqNrPair {
}
// misc
message PrivateNotificationPayload {
string message = 1;
string signature_as_base64 = 2;
bytes sig_public_key_bytes = 3;
}
message PaymentAccountFilter {
string payment_method_id = 1;
string get_method_name = 2;
string value = 3;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Storage payload
///////////////////////////////////////////////////////////////////////////////////////////
@ -426,33 +438,6 @@ message Filter {
map<string, string> extra_data = 6;
}
message PaymentAccountFilter {
string payment_method_id = 1;
string get_method_name = 2;
string value = 3;
}
message CompensationRequestPayload {
uint32 version = 1;
int64 creation_date = 2;
string uid = 3;
string name = 4;
string title = 5;
string category = 6;
string description = 7;
string link = 8;
int64 start_date = 9;
int64 end_date = 10;
int64 requested_btc = 11;
string btc_address = 12;
string node_address = 13;
bytes owner_pub_key_bytes = 14;
string owner_pub_key_as_hex = 15;
string signature = 16;
string fee_tx_id = 17;
map<string, string> extra_data = 18;
}
message TradeStatistics {
string base_currency = 1;
string counter_currency = 2;
@ -527,6 +512,28 @@ message OfferPayload {
bool is_currency_for_maker_fee_btc = 38;
}
// TODO not fully verified as impl. is not completed
message CompensationRequestPayload {
uint32 version = 1;
int64 creation_date = 2;
string uid = 3;
string name = 4;
string title = 5;
string category = 6;
string description = 7;
string link = 8;
int64 start_date = 9;
int64 end_date = 10;
int64 requested_btc = 11;
string btc_address = 12;
string node_address = 13;
bytes owner_pub_key_bytes = 14;
string owner_pub_key_as_hex = 15;
string signature = 16;
string fee_tx_id = 17;
map<string, string> extra_data = 18;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Dispute payload
@ -560,8 +567,8 @@ message Dispute {
}
message Attachment {
bytes bytes = 1;
string file_name = 2;
string file_name = 1;
bytes bytes = 2;
}
message DisputeResult {
@ -586,7 +593,6 @@ message DisputeResult {
int32 trader_id = 2;
Winner winner = 3;
int32 reason_ordinal = 4;
bool tamper_proof_evidence = 5;
bool id_verification = 6;
bool screen_cast = 7;
@ -772,18 +778,6 @@ message USPostalMoneyOrderAccountPayload {
}
///////////////////////////////////////////////////////////////////////////////////////////
// Misc
///////////////////////////////////////////////////////////////////////////////////////////
message PrivateNotificationPayload {
string message = 1;
string signature_as_base64 = 2;
bytes sig_public_key_bytes = 3;
}
///////////////////////////////////////////////////////////////////////////////////////////
// PersistableEnvelope
@ -1278,10 +1272,9 @@ message Region {
///////////////////////////////////////////////////////////////////////////////////////////
message MockMailboxPayload {
int32 message_version = 1;
string message = 2;
NodeAddress sender_node_address = 3;
string uid = 4;
string message = 1;
NodeAddress sender_node_address = 2;
string uid = 3;
}
message MockPayload {

View File

@ -43,14 +43,14 @@ import static com.google.common.base.Preconditions.checkNotNull;
public final class Alert implements StoragePayload {
private final long TTL = TimeUnit.DAYS.toMillis(30);
private final String message;
private final String version;
private final boolean isUpdateInfo;
private final String version;
@Nullable
private String signatureAsBase64;
@Nullable
private byte[] ownerPubKeyBytes;
@Nullable
private String signatureAsBase64;
@Nullable
private PublicKey ownerPubKey;
// Should be only used in emergency case if we need to add data but do not want to break backward compatibility

View File

@ -8,15 +8,15 @@ import lombok.Value;
@Value
public class PrivateNotificationMessage implements MailboxMessage {
private final NodeAddress senderNodeAddress;
private final PrivateNotificationPayload privateNotificationPayload;
private final NodeAddress senderNodeAddress;
private final String uid;
public PrivateNotificationMessage(PrivateNotificationPayload privateNotificationPayload,
NodeAddress senderNodeAddress,
String uid) {
this.senderNodeAddress = senderNodeAddress;
this.privateNotificationPayload = privateNotificationPayload;
this.senderNodeAddress = senderNodeAddress;
this.uid = uid;
}

View File

@ -40,7 +40,7 @@ public final class PrivateNotificationPayload implements NetworkPayload {
@Nullable
private byte[] sigPublicKeyBytes;
@Nullable
private PublicKey publicKey;
private PublicKey sigPublicKey;
public PrivateNotificationPayload(String message) {
this.message = message;
@ -55,7 +55,7 @@ public final class PrivateNotificationPayload implements NetworkPayload {
this(message);
this.signatureAsBase64 = signatureAsBase64;
this.sigPublicKeyBytes = sigPublicKeyBytes;
publicKey = Sig.getPublicKeyFromBytes(sigPublicKeyBytes);
sigPublicKey = Sig.getPublicKeyFromBytes(sigPublicKeyBytes);
}
public static PrivateNotificationPayload fromProto(PB.PrivateNotificationPayload proto) {
@ -66,7 +66,8 @@ public final class PrivateNotificationPayload implements NetworkPayload {
@Override
public PB.PrivateNotificationPayload toProtoMessage() {
checkNotNull(sigPublicKeyBytes, "sigPublicKeyBytes must nto be null");
checkNotNull(sigPublicKeyBytes, "sigPublicKeyBytes must not be null");
checkNotNull(signatureAsBase64, "signatureAsBase64 must not be null");
return PB.PrivateNotificationPayload.newBuilder()
.setMessage(message)
.setSignatureAsBase64(signatureAsBase64)
@ -78,10 +79,10 @@ public final class PrivateNotificationPayload implements NetworkPayload {
// API
///////////////////////////////////////////////////////////////////////////////////////////
public void setSigAndPubKey(String signatureAsBase64, PublicKey storagePublicKey) {
public void setSigAndPubKey(String signatureAsBase64, PublicKey sigPublicKey) {
this.signatureAsBase64 = signatureAsBase64;
this.publicKey = storagePublicKey;
sigPublicKeyBytes = Sig.getPublicKeyBytes(publicKey);
this.sigPublicKey = sigPublicKey;
sigPublicKeyBytes = Sig.getPublicKeyBytes(sigPublicKey);
}
// Hex

View File

@ -30,7 +30,6 @@ import org.springframework.util.CollectionUtils;
import javax.annotation.Nullable;
import java.security.PublicKey;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@ -67,7 +66,7 @@ public final class Arbitrator implements StoragePayload {
String btcAddress,
PubKeyRing pubKeyRing,
List<String> languageCodes,
Date registrationDate,
long registrationDate,
byte[] registrationPubKey,
String registrationSignature,
@Nullable String emailAddress,
@ -78,7 +77,7 @@ public final class Arbitrator implements StoragePayload {
this.btcAddress = btcAddress;
this.pubKeyRing = pubKeyRing;
this.languageCodes = languageCodes;
this.registrationDate = registrationDate.getTime();
this.registrationDate = registrationDate;
this.registrationPubKey = registrationPubKey;
this.registrationSignature = registrationSignature;
this.emailAddress = emailAddress;
@ -113,7 +112,7 @@ public final class Arbitrator implements StoragePayload {
proto.getBtcAddress(),
PubKeyRing.fromProto(proto.getPubKeyRing()),
proto.getLanguageCodesList().stream().collect(Collectors.toList()),
new Date(proto.getRegistrationDate()),
proto.getRegistrationDate(),
proto.getRegistrationPubKey().toByteArray(),
proto.getRegistrationSignature(),
proto.getEmailAddress().isEmpty() ? null : proto.getEmailAddress(),
@ -121,6 +120,11 @@ public final class Arbitrator implements StoragePayload {
CollectionUtils.isEmpty(proto.getExtraDataMap()) ? null : proto.getExtraDataMap());
}
///////////////////////////////////////////////////////////////////////////////////////////
// API
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public PublicKey getOwnerPubKey() {
return pubKeyRing.getSignaturePubKey();

View File

@ -211,7 +211,7 @@ public class ArbitratorManager {
return new Mediator(arbitrator.getNodeAddress(),
arbitrator.getPubKeyRing(),
arbitrator.getLanguageCodes(),
new Date(arbitrator.getRegistrationDate()),
arbitrator.getRegistrationDate(),
arbitrator.getRegistrationPubKey(),
arbitrator.getRegistrationSignature(),
arbitrator.getEmailAddress(),

View File

@ -7,8 +7,8 @@ import lombok.Value;
@Value
public final class Attachment implements NetworkPayload {
private final byte[] bytes;
private final String fileName;
private final byte[] bytes;
public Attachment(String fileName, byte[] bytes) {
this.fileName = fileName;
@ -18,8 +18,8 @@ public final class Attachment implements NetworkPayload {
@Override
public PB.Attachment toProtoMessage() {
return PB.Attachment.newBuilder()
.setBytes(ByteString.copyFrom(bytes))
.setFileName(fileName)
.setBytes(ByteString.copyFrom(bytes))
.build();
}

View File

@ -34,7 +34,6 @@ import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Date;
import java.util.Optional;
import java.util.stream.Collectors;
@ -68,20 +67,16 @@ public final class Dispute implements NetworkPayload {
private final String takerContractSignature;
private final PubKeyRing arbitratorPubKeyRing;
private final boolean isSupportTicket;
private final ArrayList<DisputeCommunicationMessage> disputeCommunicationMessages = new ArrayList<>();
private boolean isClosed;
@Nullable
private DisputeResult disputeResult;
private final ObservableList<DisputeCommunicationMessage> disputeCommunicationMessages = FXCollections.observableArrayList();
private BooleanProperty isClosedProperty = new SimpleBooleanProperty();
// disputeResultProperty.get is Nullable!
private ObjectProperty<DisputeResult> disputeResultProperty = new SimpleObjectProperty<>();
@Nullable
private String disputePayoutTxId;
private long openingDate;
transient private Storage<DisputeList> storage;
transient private ObservableList<DisputeCommunicationMessage> observableList;
transient private BooleanProperty isClosedProperty;
transient private ObjectProperty<DisputeResult> disputeResultProperty;
///////////////////////////////////////////////////////////////////////////////////////////
@ -123,10 +118,8 @@ public final class Dispute implements NetworkPayload {
takerContractSignature,
arbitratorPubKeyRing,
isSupportTicket);
openingDate = new Date().getTime();
this.storage = storage;
openingDate = new Date().getTime();
}
@ -170,8 +163,6 @@ public final class Dispute implements NetworkPayload {
this.isSupportTicket = isSupportTicket;
id = tradeId + "_" + traderId;
init();
}
@Override
@ -190,19 +181,19 @@ public final class Dispute implements NetworkPayload {
.addAllDisputeCommunicationMessages(disputeCommunicationMessages.stream()
.map(msg -> msg.toProtoNetworkEnvelope().getDisputeCommunicationMessage())
.collect(Collectors.toList()))
.setIsClosed(isClosed)
.setIsClosed(isClosedProperty.get())
.setOpeningDate(openingDate)
.setId(id);
Optional.ofNullable(contractHash).ifPresent(tx -> builder.setContractHash(ByteString.copyFrom(contractHash)));
Optional.ofNullable(depositTxSerialized).ifPresent(tx -> builder.setDepositTxSerialized(ByteString.copyFrom(tx)));
Optional.ofNullable(payoutTxSerialized).ifPresent(tx -> builder.setPayoutTxSerialized(ByteString.copyFrom(tx)));
Optional.ofNullable(contractHash).ifPresent(e -> builder.setContractHash(ByteString.copyFrom(e)));
Optional.ofNullable(depositTxSerialized).ifPresent(e -> builder.setDepositTxSerialized(ByteString.copyFrom(e)));
Optional.ofNullable(payoutTxSerialized).ifPresent(e -> builder.setPayoutTxSerialized(ByteString.copyFrom(e)));
Optional.ofNullable(depositTxId).ifPresent(builder::setDepositTxId);
Optional.ofNullable(payoutTxId).ifPresent(builder::setPayoutTxId);
Optional.ofNullable(disputePayoutTxId).ifPresent(builder::setDisputePayoutTxId);
Optional.ofNullable(makerContractSignature).ifPresent(builder::setMakerContractSignature);
Optional.ofNullable(takerContractSignature).ifPresent(builder::setTakerContractSignature);
Optional.ofNullable(disputeResult).ifPresent(result -> builder.setDisputeResult(disputeResult.toProtoMessage()));
Optional.ofNullable(disputeResultProperty.get()).ifPresent(result -> builder.setDisputeResult(disputeResultProperty.get().toProtoMessage()));
return builder.build();
}
@ -230,8 +221,8 @@ public final class Dispute implements NetworkPayload {
.collect(Collectors.toList()));
dispute.openingDate = proto.getOpeningDate();
dispute.isClosed = proto.getIsClosed();
DisputeResult.fromProto(proto.getDisputeResult()).ifPresent(d -> dispute.disputeResult = d);
dispute.isClosedProperty.set(proto.getIsClosed());
DisputeResult.fromProto(proto.getDisputeResult()).ifPresent(dispute.disputeResultProperty::set);
dispute.disputePayoutTxId = proto.getDisputePayoutTxId().isEmpty() ? null : proto.getDisputePayoutTxId();
return dispute;
}
@ -241,16 +232,9 @@ public final class Dispute implements NetworkPayload {
// API
///////////////////////////////////////////////////////////////////////////////////////////
private void init() {
observableList = FXCollections.observableArrayList(disputeCommunicationMessages);
isClosedProperty = new SimpleBooleanProperty(isClosed);
disputeResultProperty = new SimpleObjectProperty<>(disputeResult);
}
public void addDisputeMessage(DisputeCommunicationMessage disputeCommunicationMessage) {
if (!disputeCommunicationMessages.contains(disputeCommunicationMessage)) {
disputeCommunicationMessages.add(disputeCommunicationMessage);
observableList.add(disputeCommunicationMessage);
storage.queueUpForSave();
} else {
log.error("disputeDirectMessage already exists");
@ -268,16 +252,14 @@ public final class Dispute implements NetworkPayload {
}
public void setIsClosed(boolean isClosed) {
boolean changed = this.isClosed != isClosed;
this.isClosed = isClosed;
isClosedProperty.set(isClosed);
boolean changed = this.isClosedProperty.get() != isClosed;
this.isClosedProperty.set(isClosed);
if (changed)
storage.queueUpForSave();
}
public void setDisputeResult(DisputeResult disputeResult) {
boolean changed = this.disputeResult == null || !this.disputeResult.equals(disputeResult);
this.disputeResult = disputeResult;
boolean changed = disputeResultProperty.get() == null || !disputeResultProperty.get().equals(disputeResult);
disputeResultProperty.set(disputeResult);
if (changed)
storage.queueUpForSave();
@ -299,15 +281,11 @@ public final class Dispute implements NetworkPayload {
return Utilities.getShortId(tradeId);
}
public ObservableList<DisputeCommunicationMessage> getDisputeCommunicationMessagesAsObservableList() {
return observableList;
}
public ReadOnlyBooleanProperty isClosedProperty() {
return isClosedProperty;
}
public ObjectProperty<DisputeResult> disputeResultProperty() {
public ReadOnlyObjectProperty<DisputeResult> disputeResultProperty() {
return disputeResultProperty;
}
@ -319,6 +297,10 @@ public final class Dispute implements NetworkPayload {
return new Date(openingDate);
}
public boolean isClosed() {
return isClosedProperty.get();
}
@Override
public String toString() {
return "Dispute{" +
@ -342,10 +324,9 @@ public final class Dispute implements NetworkPayload {
", arbitratorPubKeyRing=" + arbitratorPubKeyRing +
", isSupportTicket=" + isSupportTicket +
", disputeCommunicationMessages=" + disputeCommunicationMessages +
", isClosed=" + isClosed +
", disputeResult=" + disputeResult +
", isClosed=" + isClosedProperty.get() +
", disputeResult=" + disputeResultProperty.get() +
", disputePayoutTxId='" + disputePayoutTxId + '\'' +
", disputeCommunicationMessagesAsObservableList=" + observableList +
", isClosedProperty=" + isClosedProperty +
", disputeResultProperty=" + disputeResultProperty +
'}';

View File

@ -196,8 +196,8 @@ public class DisputeManager {
onDisputeDirectMessage((DisputeCommunicationMessage) message);
else if (message instanceof DisputeResultMessage)
onDisputeResultMessage((DisputeResultMessage) message);
else if (message instanceof PeerPublishedPayoutTxMessage)
onDisputedPayoutTxMessage((PeerPublishedPayoutTxMessage) message);
else if (message instanceof PeerPublishedDisputePayoutTxMessage)
onDisputedPayoutTxMessage((PeerPublishedDisputePayoutTxMessage) message);
else
log.warn("Unsupported message at dispatchMessage.\nmessage=" + message);
}
@ -458,7 +458,7 @@ public class DisputeManager {
log.trace("sendPeerPublishedPayoutTxMessage to peerAddress " + peerNodeAddress);
p2PService.sendEncryptedMailboxMessage(peerNodeAddress,
peersPubKeyRing,
new PeerPublishedPayoutTxMessage(transaction.bitcoinSerialize(),
new PeerPublishedDisputePayoutTxMessage(transaction.bitcoinSerialize(),
dispute.getTradeId(),
p2PService.getAddress(),
UUID.randomUUID().toString()),
@ -543,7 +543,7 @@ public class DisputeManager {
cleanupRetryMap(uid);
Dispute dispute = disputeOptional.get();
if (!dispute.getDisputeCommunicationMessagesAsObservableList().contains(disputeCommunicationMessage))
if (!dispute.getDisputeCommunicationMessages().contains(disputeCommunicationMessage))
dispute.addDisputeMessage(disputeCommunicationMessage);
else
log.warn("We got a disputeCommunicationMessage what we have already stored. TradeId = " + tradeId);
@ -571,7 +571,7 @@ public class DisputeManager {
Dispute dispute = disputeOptional.get();
DisputeCommunicationMessage disputeCommunicationMessage = disputeResult.getDisputeCommunicationMessage();
if (!dispute.getDisputeCommunicationMessagesAsObservableList().contains(disputeCommunicationMessage))
if (!dispute.getDisputeCommunicationMessages().contains(disputeCommunicationMessage))
dispute.addDisputeMessage(disputeCommunicationMessage);
else
log.warn("We got a dispute mail msg what we have already stored. TradeId = " + disputeCommunicationMessage.getTradeId());
@ -703,14 +703,14 @@ public class DisputeManager {
}
// losing trader or in case of 50/50 the seller gets the tx sent from the winner or buyer
private void onDisputedPayoutTxMessage(PeerPublishedPayoutTxMessage peerPublishedPayoutTxMessage) {
final String uid = peerPublishedPayoutTxMessage.getUid();
final String tradeId = peerPublishedPayoutTxMessage.getTradeId();
private void onDisputedPayoutTxMessage(PeerPublishedDisputePayoutTxMessage peerPublishedDisputePayoutTxMessage) {
final String uid = peerPublishedDisputePayoutTxMessage.getUid();
final String tradeId = peerPublishedDisputePayoutTxMessage.getTradeId();
Optional<Dispute> disputeOptional = findOwnDispute(tradeId);
if (disputeOptional.isPresent()) {
cleanupRetryMap(uid);
Transaction walletTx = tradeWalletService.addTxToWallet(peerPublishedPayoutTxMessage.getTransaction());
Transaction walletTx = tradeWalletService.addTxToWallet(peerPublishedDisputePayoutTxMessage.getTransaction());
disputeOptional.get().setDisputePayoutTxId(walletTx.getHashAsString());
BtcWalletService.printTx("Disputed payoutTx received from peer", walletTx);
tradeManager.closeDisputedTrade(tradeId);
@ -718,7 +718,7 @@ public class DisputeManager {
log.debug("We got a peerPublishedPayoutTxMessage but we don't have a matching dispute. TradeId = " + tradeId);
if (!delayMsgMap.containsKey(uid)) {
// We delay 3 sec. to be sure the close msg gets added first
Timer timer = UserThread.runAfter(() -> onDisputedPayoutTxMessage(peerPublishedPayoutTxMessage), 3);
Timer timer = UserThread.runAfter(() -> onDisputedPayoutTxMessage(peerPublishedDisputePayoutTxMessage), 3);
delayMsgMap.put(uid, timer);
} else {
log.warn("We got a peerPublishedPayoutTxMessage after we already repeated to apply the message after a delay. " +

View File

@ -40,6 +40,7 @@ import java.util.Optional;
@ToString
@Slf4j
public final class DisputeResult implements NetworkPayload {
public enum Winner {
BUYER,
SELLER
@ -59,10 +60,10 @@ public final class DisputeResult implements NetworkPayload {
private final int traderId;
private Winner winner;
private int reasonOrdinal = Reason.OTHER.ordinal();
private boolean tamperProofEvidence;
private boolean idVerification;
private boolean screenCast;
private String summaryNotes;
private final BooleanProperty tamperProofEvidenceProperty = new SimpleBooleanProperty();
private final BooleanProperty idVerificationProperty = new SimpleBooleanProperty();
private final BooleanProperty screenCastProperty = new SimpleBooleanProperty();
private final StringProperty summaryNotesProperty = new SimpleStringProperty();
private DisputeCommunicationMessage disputeCommunicationMessage;
private byte[] arbitratorSignature;
private long buyerPayoutAmount;
@ -71,16 +72,9 @@ public final class DisputeResult implements NetworkPayload {
private long closeDate;
private boolean isLoserPublisher;
transient private BooleanProperty tamperProofEvidenceProperty;
transient private BooleanProperty idVerificationProperty;
transient private BooleanProperty screenCastProperty;
transient private StringProperty summaryNotesProperty;
public DisputeResult(String tradeId, int traderId) {
this.tradeId = tradeId;
this.traderId = traderId;
init();
}
public DisputeResult(String tradeId,
@ -102,10 +96,10 @@ public final class DisputeResult implements NetworkPayload {
this.traderId = traderId;
this.winner = winner;
this.reasonOrdinal = reasonOrdinal;
this.tamperProofEvidence = tamperProofEvidence;
this.idVerification = idVerification;
this.screenCast = screenCast;
this.summaryNotes = summaryNotes;
this.tamperProofEvidenceProperty.set(tamperProofEvidence);
this.idVerificationProperty.set(idVerification);
this.screenCastProperty.set(screenCast);
this.summaryNotesProperty.set(summaryNotes);
this.disputeCommunicationMessage = disputeCommunicationMessage;
this.arbitratorSignature = arbitratorSignature;
this.buyerPayoutAmount = buyerPayoutAmount;
@ -113,8 +107,6 @@ public final class DisputeResult implements NetworkPayload {
this.arbitratorPubKey = arbitratorPubKey;
this.closeDate = closeDate;
this.isLoserPublisher = isLoserPublisher;
init();
}
@ -148,10 +140,10 @@ public final class DisputeResult implements NetworkPayload {
.setTraderId(traderId)
.setWinner(PB.DisputeResult.Winner.valueOf(winner.name()))
.setReasonOrdinal(reasonOrdinal)
.setTamperProofEvidence(tamperProofEvidence)
.setIdVerification(idVerification)
.setScreenCast(screenCast)
.setSummaryNotes(summaryNotes)
.setTamperProofEvidence(tamperProofEvidenceProperty.get())
.setIdVerification(idVerificationProperty.get())
.setScreenCast(screenCastProperty.get())
.setSummaryNotes(summaryNotesProperty.get())
.setDisputeCommunicationMessage(disputeCommunicationMessage.toProtoNetworkEnvelope().getDisputeCommunicationMessage())
.setArbitratorSignature(ByteString.copyFrom(arbitratorSignature))
.setBuyerPayoutAmount(buyerPayoutAmount)
@ -166,26 +158,6 @@ public final class DisputeResult implements NetworkPayload {
// API
///////////////////////////////////////////////////////////////////////////////////////////
private void init() {
tamperProofEvidenceProperty = new SimpleBooleanProperty(tamperProofEvidence);
idVerificationProperty = new SimpleBooleanProperty(idVerification);
screenCastProperty = new SimpleBooleanProperty(screenCast);
summaryNotesProperty = new SimpleStringProperty(summaryNotes);
tamperProofEvidenceProperty.addListener((observable, oldValue, newValue) -> {
tamperProofEvidence = newValue;
});
idVerificationProperty.addListener((observable, oldValue, newValue) -> {
idVerification = newValue;
});
screenCastProperty.addListener((observable, oldValue, newValue) -> {
screenCast = newValue;
});
summaryNotesProperty.addListener((observable, oldValue, newValue) -> {
summaryNotes = newValue;
});
}
public BooleanProperty tamperProofEvidenceProperty() {
return tamperProofEvidenceProperty;
}

View File

@ -30,7 +30,6 @@ import org.springframework.util.CollectionUtils;
import javax.annotation.Nullable;
import java.security.PublicKey;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@ -60,11 +59,10 @@ public final class Mediator implements StoragePayload {
@Nullable
private Map<String, String> extraDataMap;
// Called from domain and PB
public Mediator(NodeAddress nodeAddress,
PubKeyRing pubKeyRing,
List<String> languageCodes,
Date registrationDate,
long registrationDate,
byte[] registrationPubKey,
String registrationSignature,
@Nullable String emailAddress,
@ -73,7 +71,7 @@ public final class Mediator implements StoragePayload {
this.nodeAddress = nodeAddress;
this.pubKeyRing = pubKeyRing;
this.languageCodes = languageCodes;
this.registrationDate = registrationDate.getTime();
this.registrationDate = registrationDate;
this.registrationPubKey = registrationPubKey;
this.registrationSignature = registrationSignature;
this.emailAddress = emailAddress;
@ -81,6 +79,11 @@ public final class Mediator implements StoragePayload {
this.extraDataMap = extraDataMap;
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public PB.StoragePayload toProtoMessage() {
final PB.Mediator.Builder builder = PB.Mediator.newBuilder()
@ -100,15 +103,18 @@ public final class Mediator implements StoragePayload {
return new Mediator(NodeAddress.fromProto(proto.getNodeAddress()),
PubKeyRing.fromProto(proto.getPubKeyRing()),
proto.getLanguageCodesList().stream().collect(Collectors.toList()),
new Date(proto.getRegistrationDate()),
proto.getRegistrationDate(),
proto.getRegistrationPubKey().toByteArray(),
proto.getRegistrationSignature(),
proto.getEmailAddress().isEmpty() ? null : proto.getEmailAddress(),
proto.getInfo().isEmpty() ? null : proto.getInfo(),
CollectionUtils.isEmpty(proto.getExtraDataMap()) ? null : proto.getExtraDataMap());
}
///////////////////////////////////////////////////////////////////////////////////////////
// API
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public PublicKey getOwnerPubKey() {
return pubKeyRing.getSignaturePubKey();

View File

@ -39,21 +39,18 @@ import java.util.stream.Collectors;
@ToString
@Getter
public final class DisputeCommunicationMessage extends DisputeMessage {
private final long date;
private final String tradeId;
private final int traderId;
private final boolean senderIsTrader;
private final String message;
private final NodeAddress senderNodeAddress;
private final ArrayList<Attachment> attachments = new ArrayList<>();
private boolean arrived;
private boolean storedInMailbox;
private final NodeAddress senderNodeAddress;
private final long date;
@Setter
private boolean isSystemMessage;
transient private final BooleanProperty arrivedProperty;
transient private final BooleanProperty storedInMailboxProperty;
private final BooleanProperty arrivedProperty;
private final BooleanProperty storedInMailboxProperty;
public DisputeCommunicationMessage(String tradeId,
int traderId,
@ -73,9 +70,6 @@ public final class DisputeCommunicationMessage extends DisputeMessage {
Optional.ofNullable(attachments).ifPresent(e -> addAllAttachments(attachments));
this.senderNodeAddress = senderNodeAddress;
this.date = date;
this.arrived = arrived;
this.storedInMailbox = storedInMailbox;
arrivedProperty = new SimpleBooleanProperty(arrived);
storedInMailboxProperty = new SimpleBooleanProperty(storedInMailbox);
}
@ -89,7 +83,6 @@ public final class DisputeCommunicationMessage extends DisputeMessage {
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
.setDisputeCommunicationMessage(PB.DisputeCommunicationMessage.newBuilder()
.setUid(uid)
.setTradeId(tradeId)
.setTraderId(traderId)
.setSenderIsTrader(senderIsTrader)
@ -97,15 +90,17 @@ public final class DisputeCommunicationMessage extends DisputeMessage {
.addAllAttachments(attachments.stream().map(Attachment::toProtoMessage).collect(Collectors.toList()))
.setSenderNodeAddress(senderNodeAddress.toProtoMessage())
.setDate(date)
.setArrived(arrived)
.setStoredInMailbox(storedInMailbox)
.setArrived(arrivedProperty.get())
.setStoredInMailbox(storedInMailboxProperty.get())
.setIsSystemMessage(isSystemMessage)
.setUid(uid)
)
.build();
}
public static DisputeCommunicationMessage fromProto(PB.DisputeCommunicationMessage proto) {
final DisputeCommunicationMessage disputeCommunicationMessage = new DisputeCommunicationMessage(proto.getTradeId(),
final DisputeCommunicationMessage disputeCommunicationMessage = new DisputeCommunicationMessage(
proto.getTradeId(),
proto.getTraderId(),
proto.getSenderIsTrader(),
proto.getMessage(),
@ -129,12 +124,10 @@ public final class DisputeCommunicationMessage extends DisputeMessage {
}
public void setArrived(boolean arrived) {
this.arrived = arrived;
this.arrivedProperty.set(arrived);
}
public void setStoredInMailbox(boolean storedInMailbox) {
this.storedInMailbox = storedInMailbox;
this.storedInMailboxProperty.set(storedInMailbox);
}

View File

@ -46,16 +46,16 @@ public final class DisputeResultMessage extends DisputeMessage {
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
.setDisputeResultMessage(PB.DisputeResultMessage.newBuilder()
.setUid(getUid())
.setDisputeResult(disputeResult.toProtoMessage())
.setSenderNodeAddress(senderNodeAddress.toProtoMessage()))
.setSenderNodeAddress(senderNodeAddress.toProtoMessage())
.setUid(uid))
.build();
}
public static DisputeResultMessage fromProto(PB.DisputeResultMessage proto) {
checkArgument(!proto.equals(proto.getDefaultInstanceForType()), "proto must be set (we received default instance)");
checkArgument(!proto.equals(proto.getDefaultInstanceForType()), "PB.DisputeResultMessage must be set (we received default instance)");
final Optional<DisputeResult> disputeResult = DisputeResult.fromProto(proto.getDisputeResult());
checkArgument(disputeResult.isPresent(), "disputeResult i not present");
checkArgument(disputeResult.isPresent(), "DisputeResult is not present");
return new DisputeResultMessage(disputeResult.get(),
NodeAddress.fromProto(proto.getSenderNodeAddress()),
proto.getUid());

View File

@ -43,7 +43,7 @@ public final class OpenNewDisputeMessage extends DisputeMessage {
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
.setOpenNewDisputeMessage(PB.OpenNewDisputeMessage.newBuilder()
.setUid(getUid())
.setUid(uid)
.setDispute(dispute.toProtoMessage())
.setSenderNodeAddress(senderNodeAddress.toProtoMessage()))
.build();

View File

@ -26,15 +26,15 @@ import lombok.Value;
@Value
@EqualsAndHashCode(callSuper = true)
public final class PeerPublishedPayoutTxMessage extends DisputeMessage {
public final class PeerPublishedDisputePayoutTxMessage extends DisputeMessage {
private final byte[] transaction;
private final String tradeId;
private final NodeAddress senderNodeAddress;
public PeerPublishedPayoutTxMessage(byte[] transaction,
String tradeId,
NodeAddress senderNodeAddress,
String uid) {
public PeerPublishedDisputePayoutTxMessage(byte[] transaction,
String tradeId,
NodeAddress senderNodeAddress,
String uid) {
super(uid);
this.transaction = transaction;
this.tradeId = tradeId;
@ -44,7 +44,7 @@ public final class PeerPublishedPayoutTxMessage extends DisputeMessage {
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
.setPeerPublishedPayoutTxMessage(PB.PeerPublishedPayoutTxMessage.newBuilder()
.setPeerPublishedDisputePayoutTxMessage(PB.PeerPublishedDisputePayoutTxMessage.newBuilder()
.setTransaction(ByteString.copyFrom(transaction))
.setTradeId(tradeId)
.setSenderNodeAddress(senderNodeAddress.toProtoMessage())
@ -52,8 +52,8 @@ public final class PeerPublishedPayoutTxMessage extends DisputeMessage {
.build();
}
public static PeerPublishedPayoutTxMessage fromProto(PB.PeerPublishedPayoutTxMessage proto) {
return new PeerPublishedPayoutTxMessage(proto.getTransaction().toByteArray(),
public static PeerPublishedDisputePayoutTxMessage fromProto(PB.PeerPublishedDisputePayoutTxMessage proto) {
return new PeerPublishedDisputePayoutTxMessage(proto.getTransaction().toByteArray(),
proto.getTradeId(),
NodeAddress.fromProto(proto.getSenderNodeAddress()),
proto.getUid());

View File

@ -17,6 +17,7 @@
package io.bisq.core.filter;
import com.google.common.annotations.VisibleForTesting;
import com.google.protobuf.ByteString;
import io.bisq.common.crypto.Sig;
import io.bisq.generated.protobuffer.PB;
@ -69,6 +70,7 @@ public final class Filter implements StoragePayload {
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
@VisibleForTesting
public Filter(List<String> bannedOfferIds,
List<String> bannedNodeAddress,
List<PaymentAccountFilter> bannedPaymentAccounts,
@ -105,8 +107,7 @@ public final class Filter implements StoragePayload {
public static Filter fromProto(PB.Filter proto) {
return new Filter(proto.getBannedOfferIdsList().stream().collect(Collectors.toList()),
proto.getBannedNodeAddressList().stream().collect(Collectors.toList()),
proto.getBannedPaymentAccountsList()
.stream()
proto.getBannedPaymentAccountsList().stream()
.map(PaymentAccountFilter::fromProto)
.collect(Collectors.toList()),
proto.getSignatureAsBase64(),

View File

@ -37,18 +37,23 @@ import javax.annotation.Nullable;
import java.security.PublicKey;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
@ToString
@EqualsAndHashCode
@Getter
@Slf4j
public final class OfferPayload implements StoragePayload, RequiresOwnerIsOnlinePayload {
///////////////////////////////////////////////////////////////////////////////////////////
// Enum
///////////////////////////////////////////////////////////////////////////////////////////
public enum Direction {
BUY, SELL;
@ -61,6 +66,7 @@ public final class OfferPayload implements StoragePayload, RequiresOwnerIsOnline
}
}
///////////////////////////////////////////////////////////////////////////////////////////
// Instance fields
///////////////////////////////////////////////////////////////////////////////////////////
@ -266,11 +272,8 @@ public final class OfferPayload implements StoragePayload, RequiresOwnerIsOnline
.setIsPrivateOffer(isPrivateOffer)
.setProtocolVersion(protocolVersion);
if (Objects.nonNull(offerFeePaymentTxId)) {
builder.setOfferFeePaymentTxId(offerFeePaymentTxId);
} else {
throw new RuntimeException("OfferPayload is in invalid state: offerFeePaymentTxID is not set when adding to P2P network.");
}
checkNotNull(offerFeePaymentTxId, "OfferPayload is in invalid state: offerFeePaymentTxID is not set when adding to P2P network.");
builder.setOfferFeePaymentTxId(offerFeePaymentTxId);
Optional.ofNullable(countryCode).ifPresent(builder::setCountryCode);
Optional.ofNullable(bankId).ifPresent(builder::setBankId);
@ -352,10 +355,6 @@ public final class OfferPayload implements StoragePayload, RequiresOwnerIsOnline
// The rest of the app does not support yet that concept of base currency and counter currencies
// so we map here for convenience
public String getCurrencyCode() {
if (CurrencyUtil.isCryptoCurrency(getBaseCurrencyCode()))
return getBaseCurrencyCode();
else
return getCounterCurrencyCode();
return CurrencyUtil.isCryptoCurrency(getBaseCurrencyCode()) ? getBaseCurrencyCode() : getCounterCurrencyCode();
}
}

View File

@ -108,8 +108,8 @@ public class CoreNetworkProtoResolver extends CoreProtoResolver implements Netwo
return DisputeCommunicationMessage.fromProto(proto.getDisputeCommunicationMessage());
case DISPUTE_RESULT_MESSAGE:
return DisputeResultMessage.fromProto(proto.getDisputeResultMessage());
case PEER_PUBLISHED_PAYOUT_TX_MESSAGE:
return PeerPublishedPayoutTxMessage.fromProto(proto.getPeerPublishedPayoutTxMessage());
case PEER_PUBLISHED_DISPUTE_PAYOUT_TX_MESSAGE:
return PeerPublishedDisputePayoutTxMessage.fromProto(proto.getPeerPublishedDisputePayoutTxMessage());
case PRIVATE_NOTIFICATION_MESSAGE:
return PrivateNotificationMessage.fromProto(proto.getPrivateNotificationMessage());

View File

@ -46,7 +46,7 @@ public final class DepositTxPublishedMessage extends TradeMessage implements Mai
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
.setDepositTxPublishedMessage(PB.DepositTxPublishedMessage.newBuilder()
.setTradeId(getTradeId())
.setTradeId(tradeId)
.setDepositTx(ByteString.copyFrom(depositTx))
.setSenderNodeAddress(senderNodeAddress.toProtoMessage())
.setUid(uid))

View File

@ -49,7 +49,7 @@ public final class FiatTransferStartedMessage extends TradeMessage implements Ma
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
.setFiatTransferStartedMessage(PB.FiatTransferStartedMessage.newBuilder()
.setTradeId(getTradeId())
.setTradeId(tradeId)
.setBuyerPayoutAddress(buyerPayoutAddress)
.setSenderNodeAddress(senderNodeAddress.toProtoMessage())
.setBuyerSignature(ByteString.copyFrom(buyerSignature))

View File

@ -49,7 +49,7 @@ public final class FinalizePayoutTxRequest extends TradeMessage implements Mailb
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
.setFinalizePayoutTxRequest(PB.FinalizePayoutTxRequest.newBuilder()
.setTradeId(getTradeId())
.setTradeId(tradeId)
.setSellerSignature(ByteString.copyFrom(sellerSignature))
.setSellerPayoutAddress(sellerPayoutAddress)
.setSenderNodeAddress(senderNodeAddress.toProtoMessage())

View File

@ -57,6 +57,7 @@ public final class PayDepositRequest extends TradeMessage {
private final List<NodeAddress> acceptedMediatorNodeAddresses;
private final NodeAddress arbitratorNodeAddress;
private final NodeAddress mediatorNodeAddress;
private final String uid;
public PayDepositRequest(String tradeId,
NodeAddress senderNodeAddress,
@ -77,7 +78,8 @@ public final class PayDepositRequest extends TradeMessage {
List<NodeAddress> acceptedArbitratorNodeAddresses,
List<NodeAddress> acceptedMediatorNodeAddresses,
NodeAddress arbitratorNodeAddress,
NodeAddress mediatorNodeAddress) {
NodeAddress mediatorNodeAddress,
String uid) {
super(tradeId);
this.senderNodeAddress = senderNodeAddress;
this.tradeAmount = tradeAmount;
@ -98,12 +100,13 @@ public final class PayDepositRequest extends TradeMessage {
this.acceptedMediatorNodeAddresses = acceptedMediatorNodeAddresses;
this.arbitratorNodeAddress = arbitratorNodeAddress;
this.mediatorNodeAddress = mediatorNodeAddress;
this.uid = uid;
}
@Override
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
PB.PayDepositRequest.Builder builder = PB.PayDepositRequest.newBuilder()
.setTradeId(getTradeId())
.setTradeId(tradeId)
.setSenderNodeAddress(senderNodeAddress.toProtoMessage())
.setTradeAmount(tradeAmount)
.setTradePrice(tradePrice)
@ -124,7 +127,8 @@ public final class PayDepositRequest extends TradeMessage {
.addAllAcceptedMediatorNodeAddresses(acceptedMediatorNodeAddresses.stream()
.map(NodeAddress::toProtoMessage).collect(Collectors.toList()))
.setArbitratorNodeAddress(arbitratorNodeAddress.toProtoMessage())
.setMediatorNodeAddress(mediatorNodeAddress.toProtoMessage());
.setMediatorNodeAddress(mediatorNodeAddress.toProtoMessage())
.setUid(uid);
Optional.ofNullable(changeOutputAddress).ifPresent(builder::setChangeOutputAddress);
return NetworkEnvelope.getDefaultBuilder().setPayDepositRequest(builder).build();
}
@ -158,6 +162,7 @@ public final class PayDepositRequest extends TradeMessage {
acceptedArbitratorNodeAddresses,
acceptedMediatorNodeAddresses,
NodeAddress.fromProto(proto.getArbitratorNodeAddress()),
NodeAddress.fromProto(proto.getMediatorNodeAddress()));
NodeAddress.fromProto(proto.getMediatorNodeAddress()),
proto.getUid());
}
}

View File

@ -46,7 +46,7 @@ public final class PayoutTxPublishedMessage extends TradeMessage implements Mail
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
.setPayoutTxPublishedMessage(PB.PayoutTxPublishedMessage.newBuilder()
.setTradeId(getTradeId())
.setTradeId(tradeId)
.setPayoutTx(ByteString.copyFrom(payoutTx))
.setSenderNodeAddress(senderNodeAddress.toProtoMessage())
.setUid(uid))

View File

@ -40,12 +40,12 @@ import java.util.stream.Collectors;
public final class PublishDepositTxRequest extends TradeMessage implements MailboxMessage {
private final PaymentAccountPayload makerPaymentAccountPayload;
private final String makerAccountId;
private final byte[] makerMultiSigPubKey;
private final String makerContractAsJson;
private final String makerContractSignature;
private final String makerPayoutAddressString;
private final byte[] preparedDepositTx;
private final List<RawTransactionInput> makerInputs;
private final byte[] makerMultiSigPubKey;
private final NodeAddress senderNodeAddress;
private final String uid;
@ -77,7 +77,7 @@ public final class PublishDepositTxRequest extends TradeMessage implements Mailb
public PB.NetworkEnvelope toProtoNetworkEnvelope() {
return NetworkEnvelope.getDefaultBuilder()
.setPublishDepositTxRequest(PB.PublishDepositTxRequest.newBuilder()
.setTradeId(getTradeId())
.setTradeId(tradeId)
.setMakerPaymentAccountPayload((PB.PaymentAccountPayload) makerPaymentAccountPayload.toProtoMessage())
.setMakerAccountId(makerAccountId)
.setMakerMultiSigPubKey(ByteString.copyFrom(makerMultiSigPubKey))
@ -93,9 +93,7 @@ public final class PublishDepositTxRequest extends TradeMessage implements Mailb
public static PublishDepositTxRequest fromProto(PB.PublishDepositTxRequest proto, CoreProtoResolver coreProtoResolver) {
List<RawTransactionInput> makerInputs = proto.getMakerInputsList().stream()
.map(rawTransactionInput -> new RawTransactionInput(rawTransactionInput.getIndex(),
rawTransactionInput.getParentTransaction().toByteArray(),
rawTransactionInput.getValue()))
.map(RawTransactionInput::fromProto)
.collect(Collectors.toList());
return new PublishDepositTxRequest(proto.getTradeId(),

View File

@ -23,10 +23,14 @@ import io.bisq.core.btc.wallet.BtcWalletService;
import io.bisq.core.trade.Trade;
import io.bisq.core.trade.messages.PayDepositRequest;
import io.bisq.core.trade.protocol.tasks.TradeTask;
import io.bisq.core.user.User;
import io.bisq.network.p2p.NodeAddress;
import io.bisq.network.p2p.SendDirectMessageListener;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
@ -44,7 +48,13 @@ public class TakerSendPayDepositRequest extends TradeTask {
runInterceptHook();
checkNotNull(trade.getTradeAmount(), "TradeAmount must not be null");
checkNotNull(trade.getTakerFeeTxId(), "TakeOfferFeeTxId must not be null");
final User user = processModel.getUser();
checkNotNull(user, "User must not be null");
final List<NodeAddress> acceptedArbitratorAddresses = user.getAcceptedArbitratorAddresses();
final List<NodeAddress> acceptedMediatorAddresses = user.getAcceptedMediatorAddresses();
checkNotNull(acceptedArbitratorAddresses, "acceptedArbitratorAddresses must not be null");
checkNotNull(acceptedMediatorAddresses, "acceptedMediatorAddresses must not be null");
BtcWalletService walletService = processModel.getBtcWalletService();
String id = processModel.getOffer().getId();
AddressEntry takerPayoutAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.TRADE_PAYOUT);
@ -53,6 +63,7 @@ public class TakerSendPayDepositRequest extends TradeTask {
AddressEntry addressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.MULTI_SIG);
byte[] takerMultiSigPubKey = addressEntry.getPubKey();
String takerPayoutAddressString = takerPayoutAddressEntry.getAddressString();
PayDepositRequest message = new PayDepositRequest(
processModel.getOfferId(),
processModel.getMyNodeAddress(),
@ -70,11 +81,11 @@ public class TakerSendPayDepositRequest extends TradeTask {
processModel.getPaymentAccountPayload(trade),
processModel.getAccountId(),
trade.getTakerFeeTxId(),
new ArrayList<>(processModel.getUser().getAcceptedArbitratorAddresses()),
new ArrayList<>(processModel.getUser().getAcceptedMediatorAddresses()),
new ArrayList<>(acceptedArbitratorAddresses),
new ArrayList<>(acceptedMediatorAddresses),
trade.getArbitratorNodeAddress(),
trade.getMediatorNodeAddress()
);
trade.getMediatorNodeAddress(),
UUID.randomUUID().toString());
processModel.setMyMultiSigPubKey(takerMultiSigPubKey);
processModel.getP2PService().sendEncryptedDirectMessage(

View File

@ -40,7 +40,7 @@ public class ArbitratorTest {
"btcaddress",
new PubKeyRing(getBytes(100), getBytes(100), "key"),
Lists.newArrayList(),
new Date(),
new Date().getTime(),
getBytes(100),
"registrationSignature",
null, null, null);

View File

@ -39,7 +39,7 @@ public class MediatorTest {
return new Mediator(new NodeAddress("host", 1000),
new PubKeyRing(getBytes(100), getBytes(100), "key"),
Lists.newArrayList(),
new Date(),
new Date().getTime(),
getBytes(100),
"registrationSignature",
"email",

View File

@ -153,7 +153,7 @@ class ArbitratorRegistrationViewModel extends ActivatableViewModel {
arbitratorDepositAddressEntry.getAddressString(),
keyRing.getPubKeyRing(),
new ArrayList<>(languageCodes),
new Date(),
new Date().getTime(),
registrationKey.getPubKey(),
registrationSignature,
emailAddress,

View File

@ -286,7 +286,7 @@ public class TraderDisputeView extends ActivatableView<VBox, Void> {
.append(dispute.getTraderId())
.append("\n*******************************************************************************************\n")
.append("\n");
dispute.getDisputeCommunicationMessagesAsObservableList().stream().forEach(m -> {
dispute.getDisputeCommunicationMessages().stream().forEach(m -> {
String role = m.isSenderIsTrader() ? ">> Trader's msg: " : "<< Arbitrator's msg: ";
stringBuilder.append(role)
.append(m.getMessage())
@ -606,7 +606,7 @@ public class TraderDisputeView extends ActivatableView<VBox, Void> {
AnchorPane.setBottomAnchor(tableGroupHeadline, 0d);
AnchorPane.setLeftAnchor(tableGroupHeadline, 0d);
disputeCommunicationMessages = selectedDispute.getDisputeCommunicationMessagesAsObservableList();
disputeCommunicationMessages = selectedDispute.getDisputeCommunicationMessages();
SortedList<DisputeCommunicationMessage> sortedList = new SortedList<>(disputeCommunicationMessages);
sortedList.setComparator((o1, o2) -> new Date(o1.getDate()).compareTo(new Date(o2.getDate())));
messageListView = new ListView<>(sortedList);

View File

@ -161,10 +161,10 @@ public class DisputeSummaryWindow extends Overlay<DisputeSummaryWindow> {
private void addContent() {
Contract contract = dispute.getContract();
if (dispute.disputeResultProperty().get() == null)
if (dispute.getDisputeResultProperty().get() == null)
disputeResult = new DisputeResult(dispute.getTradeId(), dispute.getTraderId());
else
disputeResult = dispute.disputeResultProperty().get();
disputeResult = dispute.getDisputeResultProperty().get();
peersDisputeOptional = disputeManager.getDisputesAsObservableList().stream()
.filter(d -> dispute.getTradeId().equals(d.getTradeId()) && dispute.getTraderId() != d.getTraderId()).findFirst();
@ -181,7 +181,7 @@ public class DisputeSummaryWindow extends Overlay<DisputeSummaryWindow> {
boolean applyPeersDisputeResult = peersDisputeOptional.isPresent() && peersDisputeOptional.get().isClosed();
if (applyPeersDisputeResult) {
// If the other peers dispute has been closed we apply the result to ourselves
DisputeResult peersDisputeResult = peersDisputeOptional.get().disputeResultProperty().get();
DisputeResult peersDisputeResult = peersDisputeOptional.get().getDisputeResultProperty().get();
disputeResult.setBuyerPayoutAmount(peersDisputeResult.getBuyerPayoutAmount());
disputeResult.setSellerPayoutAmount(peersDisputeResult.getSellerPayoutAmount());
disputeResult.setWinner(peersDisputeResult.getWinner());

View File

@ -4,33 +4,33 @@ import io.bisq.common.proto.network.NetworkPayload;
import io.bisq.common.proto.persistable.PersistablePayload;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.NodeAddress;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.time.Instant;
import java.util.Date;
@Getter
@EqualsAndHashCode(exclude = {"date"})
@ToString
public final class Peer implements NetworkPayload, PersistablePayload {
private static final int MAX_FAILED_CONNECTION_ATTEMPTS = 5;
private final NodeAddress nodeAddress;
private final Date date;
private final long date;
@Setter
private int failedConnectionAttempts = 0;
public Peer(NodeAddress nodeAddress) {
this(nodeAddress, new Date());
this(nodeAddress, new Date().getTime());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private Peer(NodeAddress nodeAddress, Date date) {
private Peer(NodeAddress nodeAddress, long date) {
this.nodeAddress = nodeAddress;
this.date = date;
}
@ -39,13 +39,13 @@ public final class Peer implements NetworkPayload, PersistablePayload {
public PB.Peer toProtoMessage() {
return PB.Peer.newBuilder()
.setNodeAddress(nodeAddress.toProtoMessage())
.setDate(date.getTime())
.setDate(date)
.build();
}
public static Peer fromProto(PB.Peer peer) {
return new Peer(NodeAddress.fromProto(peer.getNodeAddress()),
Date.from(Instant.ofEpochMilli(peer.getDate())));
peer.getDate());
}
@ -61,22 +61,7 @@ public final class Peer implements NetworkPayload, PersistablePayload {
return failedConnectionAttempts >= MAX_FAILED_CONNECTION_ATTEMPTS;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Peer)) return false;
Peer that = (Peer) o;
return !(nodeAddress != null ? !nodeAddress.equals(that.nodeAddress) : that.nodeAddress != null);
public Date getDate() {
return new Date(date);
}
// We don't use the lastActivityDate for identity
@Override
public int hashCode() {
return nodeAddress != null ? nodeAddress.hashCode() : 0;
}
}

View File

@ -715,28 +715,26 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers
* Needs to be Serializable because we convert the object to a byte array via java serialization
* before calculating the hash.
*/
@ToString
public static final class DataAndSeqNrPair implements NetworkPayload {
// data are only used for calculating cryptographic hash from both values so they are kept private
private final StoragePayload data;
private final StoragePayload storagePayload;
private final int sequenceNumber;
public DataAndSeqNrPair(StoragePayload data, int sequenceNumber) {
this.data = data;
public DataAndSeqNrPair(StoragePayload storagePayload, int sequenceNumber) {
this.storagePayload = storagePayload;
this.sequenceNumber = sequenceNumber;
}
@Override
public String toString() {
return "DataAndSeqNr{" +
"data=" + data +
", sequenceNumber=" + sequenceNumber +
'}';
public com.google.protobuf.Message toProtoMessage() {
return PB.DataAndSeqNrPair.newBuilder()
.setPayload((PB.StoragePayload) storagePayload.toProtoMessage())
.setSequenceNumber(sequenceNumber)
.build();
}
@Override
public com.google.protobuf.Message toProtoMessage() {
return PB.DataAndSeqNrPair.newBuilder().setPayload((PB.StoragePayload) data.toProtoMessage()).setSequenceNumber(sequenceNumber).build();
}
//TODO from PB is missing
}

View File

@ -50,6 +50,11 @@ public final class MailboxStoragePayload implements StoragePayload {
ownerPubKeyBytes = Sig.getPublicKeyBytes(ownerPubKey);
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private MailboxStoragePayload(PrefixedSealedAndSignedMessage prefixedSealedAndSignedMessage,
byte[] senderPubKeyForAddOperationBytes,
byte[] ownerPubKeyBytes,