Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New trade protocol #3333

Merged
merged 46 commits into from Sep 27, 2019
Merged
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
2c89c5d
Remove arbitration key, cleanup
chimp1984 Sep 21, 2019
edf71f2
Add BuyerAsMakerProcessDepositTxAndDelayedPayoutTxMessage
chimp1984 Sep 21, 2019
32ec5f6
Adopt trade protocol
chimp1984 Sep 21, 2019
13fda96
Remove arbitratorKey
chimp1984 Sep 21, 2019
7393262
Add new classes
chimp1984 Sep 21, 2019
5610c0e
Add new message classes
chimp1984 Sep 21, 2019
7774abe
Add new task classes
chimp1984 Sep 21, 2019
59a47d0
Renamed classed (no functional change yet)
chimp1984 Sep 21, 2019
0401045
Add lockTime
chimp1984 Sep 21, 2019
6b40c5d
Add delayedPayoutTxSignature field
chimp1984 Sep 21, 2019
db5884c
Add useReimbursementModel field
chimp1984 Sep 21, 2019
e937869
Add new classes
chimp1984 Sep 21, 2019
d8d7f34
Add setting.preferences.useReimbursementModel
chimp1984 Sep 21, 2019
2a3ba2b
Apply renamed classes (new classes not added yet)
chimp1984 Sep 21, 2019
0232ac9
Add useReimbursementModel
chimp1984 Sep 21, 2019
24761d9
Add preferences param
chimp1984 Sep 21, 2019
16a8dac
Add new methods, cleanup
chimp1984 Sep 21, 2019
1cc4205
Add daoFacade param, apply renaming
chimp1984 Sep 21, 2019
90bc4d5
Add delayedPayoutTx, lockTime and delayedPayoutTxId
chimp1984 Sep 21, 2019
d9ccf94
Remove DirectMessage interface
chimp1984 Sep 21, 2019
e75f2a5
Rename emergencySignAndPublishPayoutTx method, add new one for 2of2 MS
chimp1984 Sep 21, 2019
0b8e2e9
Apply new protocol
chimp1984 Sep 21, 2019
57f8f16
Apply new protocol
chimp1984 Sep 21, 2019
ff78aa5
Add renaming (no functional change yet)
chimp1984 Sep 21, 2019
44975be
Add new messages, apply renaming
chimp1984 Sep 21, 2019
82736de
Remove unneeded P2SHMultiSigOutputScript
chimp1984 Sep 21, 2019
3f7dfc6
Remove PREFERRED_PROJECT_CODE_STYLE
chimp1984 Sep 21, 2019
4b94412
Refactor: Rename class
chimp1984 Sep 21, 2019
5bd5d0c
Use InputsForDepositTxRequest instead of TradeMessage in handleTakeOf…
chimp1984 Sep 21, 2019
05a9703
Do not sign deposit tx if maker is seller
chimp1984 Sep 21, 2019
5aa185c
Apply new trade protocol to seller as maker version
chimp1984 Sep 21, 2019
c41b811
Apply new trade protocol
chimp1984 Sep 22, 2019
4de69a6
Set TRADE_PROTOCOL_VERSION to 2
chimp1984 Sep 22, 2019
ab63cad
Add PeerPublishedDelayedPayoutTxMessage
chimp1984 Sep 22, 2019
7988a97
Add refund agent domain
chimp1984 Sep 23, 2019
160c135
Add refundAgentNodeAddress
chimp1984 Sep 23, 2019
f12bf51
Apply refund domain
chimp1984 Sep 23, 2019
68bb842
Add refund views
chimp1984 Sep 23, 2019
912bb07
Apply refundAgent domain
chimp1984 Sep 23, 2019
8a17cc5
Support refundAgent
chimp1984 Sep 24, 2019
172330a
Remove useReimbursementModel field
chimp1984 Sep 24, 2019
1c5d9ef
Apply refundAgent payout
chimp1984 Sep 26, 2019
0300836
Handle tx info and balances
chimp1984 Sep 26, 2019
038347a
Remove mediation activation
chimp1984 Sep 26, 2019
d388d9a
Add new tac accepted flag for v1.2.0 and adjust text
chimp1984 Sep 26, 2019
a30a07e
Fix params for test classes
chimp1984 Sep 26, 2019
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Add refund agent domain

  • Loading branch information
chimp1984 committed Sep 23, 2019
commit 7988a97663d062e5cb6146f2ad90f253fa4bb307
@@ -84,6 +84,7 @@ private static int getSubVersion(String version, int index) {
// A taker will check the version of the offers to see if his version is compatible.
// Offers created with the old version will become invalid and have to be canceled.
// VERSION = 0.5.0 -> TRADE_PROTOCOL_VERSION = 1
// Version 1.2.0 -> TRADE_PROTOCOL_VERSION = 2
public static final int TRADE_PROTOCOL_VERSION = 2;
private static int p2pMessageVersion;

@@ -491,6 +491,7 @@ message StoragePayload {
MailboxStoragePayload mailbox_storage_payload = 6;
OfferPayload offer_payload = 7;
TempProposalPayload temp_proposal_payload = 8;
RefundAgent refund_agent = 9;
}
}

@@ -584,6 +585,18 @@ message Mediator {
map<string, string> extra_data = 9;
}

message RefundAgent {
NodeAddress node_address = 1;
repeated string language_codes = 2;
int64 registration_date = 3;
string registration_signature = 4;
bytes registration_pub_key = 5;
PubKeyRing pub_key_ring = 6;
string email_address = 7;
string info = 8;
map<string, string> extra_data = 9;
}

message Filter {
repeated string banned_node_address = 1;
repeated string banned_offer_ids = 2;
@@ -602,6 +615,7 @@ message Filter {
string disable_dao_below_version = 15;
string disable_trade_below_version = 16;
repeated string mediators = 17;
repeated string refundAgents = 18;
}

// not used anymore from v0.6 on. But leave it for receiving TradeStatistics objects from older
@@ -1512,6 +1526,8 @@ message UserPayload {
Mediator registered_mediator = 11;
PriceAlertFilter price_alert_filter = 12;
repeated MarketAlertFilter market_alert_filters = 13;
repeated RefundAgent accepted_refund_agents = 14;
RefundAgent registered_refund_agent = 15;
}

///////////////////////////////////////////////////////////////////////////////////////////
@@ -98,6 +98,10 @@
@Nullable
private final List<String> mediators;

// added in v1.2.0
@Nullable
private final List<String> refundAgents;

public Filter(List<String> bannedOfferIds,
List<String> bannedNodeAddress,
List<PaymentAccountFilter> bannedPaymentAccounts,
@@ -111,7 +115,8 @@ public Filter(List<String> bannedOfferIds,
boolean disableDao,
@Nullable String disableDaoBelowVersion,
@Nullable String disableTradeBelowVersion,
@Nullable List<String> mediators) {
@Nullable List<String> mediators,
@Nullable List<String> refundAgents) {
this.bannedOfferIds = bannedOfferIds;
this.bannedNodeAddress = bannedNodeAddress;
this.bannedPaymentAccounts = bannedPaymentAccounts;
@@ -126,6 +131,7 @@ public Filter(List<String> bannedOfferIds,
this.disableDaoBelowVersion = disableDaoBelowVersion;
this.disableTradeBelowVersion = disableTradeBelowVersion;
this.mediators = mediators;
this.refundAgents = refundAgents;
}


@@ -150,7 +156,8 @@ public Filter(List<String> bannedOfferIds,
String signatureAsBase64,
byte[] ownerPubKeyBytes,
@Nullable Map<String, String> extraDataMap,
@Nullable List<String> mediators) {
@Nullable List<String> mediators,
@Nullable List<String> refundAgents) {
this(bannedOfferIds,
bannedNodeAddress,
bannedPaymentAccounts,
@@ -164,7 +171,8 @@ public Filter(List<String> bannedOfferIds,
disableDao,
disableDaoBelowVersion,
disableTradeBelowVersion,
mediators);
mediators,
refundAgents);
this.signatureAsBase64 = signatureAsBase64;
this.ownerPubKeyBytes = ownerPubKeyBytes;
this.extraDataMap = ExtraDataMapValidator.getValidatedExtraDataMap(extraDataMap);
@@ -198,6 +206,7 @@ public Filter(List<String> bannedOfferIds,
Optional.ofNullable(disableTradeBelowVersion).ifPresent(builder::setDisableTradeBelowVersion);
Optional.ofNullable(extraDataMap).ifPresent(builder::putAllExtraData);
Optional.ofNullable(mediators).ifPresent(builder::addAllMediators);
Optional.ofNullable(refundAgents).ifPresent(builder::addAllRefundAgents);

return protobuf.StoragePayload.newBuilder().setFilter(builder).build();
}
@@ -221,7 +230,8 @@ public static Filter fromProto(protobuf.Filter proto) {
proto.getSignatureAsBase64(),
proto.getOwnerPubKeyBytes().toByteArray(),
CollectionUtils.isEmpty(proto.getExtraDataMap()) ? null : proto.getExtraDataMap(),
CollectionUtils.isEmpty(proto.getMediatorsList()) ? null : new ArrayList<>(proto.getMediatorsList()));
CollectionUtils.isEmpty(proto.getMediatorsList()) ? null : new ArrayList<>(proto.getMediatorsList()),
CollectionUtils.isEmpty(proto.getRefundAgentsList()) ? null : new ArrayList<>(proto.getRefundAgentsList()));
}


@@ -44,6 +44,7 @@
import bisq.core.support.dispute.messages.DisputeResultMessage;
import bisq.core.support.dispute.messages.OpenNewDisputeMessage;
import bisq.core.support.dispute.messages.PeerOpenedDisputeMessage;
import bisq.core.support.dispute.refund.refundagent.RefundAgent;
import bisq.core.support.messages.ChatMessage;
import bisq.core.trade.messages.CounterCurrencyTransferStartedMessage;
import bisq.core.trade.messages.DelayedPayoutTxSignatureRequest;
@@ -247,6 +248,8 @@ public NetworkPayload fromProto(protobuf.StoragePayload proto) {
return Arbitrator.fromProto(proto.getArbitrator());
case MEDIATOR:
return Mediator.fromProto(proto.getMediator());
case REFUND_AGENT:
return RefundAgent.fromProto(proto.getRefundAgent());
case FILTER:
return Filter.fromProto(proto.getFilter());
case TRADE_STATISTICS:
@@ -0,0 +1,109 @@
/*
* 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.support.dispute.refund.refundagent;

import bisq.core.support.dispute.agent.DisputeAgent;

import bisq.network.p2p.NodeAddress;

import bisq.common.crypto.PubKeyRing;
import bisq.common.proto.ProtoUtil;

import com.google.protobuf.ByteString;

import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Nullable;

@EqualsAndHashCode(callSuper = true)
@Slf4j
@Getter
public final class RefundAgent extends DisputeAgent {

public RefundAgent(NodeAddress nodeAddress,
PubKeyRing pubKeyRing,
List<String> languageCodes,
long registrationDate,
byte[] registrationPubKey,
String registrationSignature,
@Nullable String emailAddress,
@Nullable String info,
@Nullable Map<String, String> extraDataMap) {

super(nodeAddress,
pubKeyRing,
languageCodes,
registrationDate,
registrationPubKey,
registrationSignature,
emailAddress,
info,
extraDataMap);
}

///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////

@Override
public protobuf.StoragePayload toProtoMessage() {
protobuf.RefundAgent.Builder builder = protobuf.RefundAgent.newBuilder()
.setNodeAddress(nodeAddress.toProtoMessage())
.setPubKeyRing(pubKeyRing.toProtoMessage())
.addAllLanguageCodes(languageCodes)
.setRegistrationDate(registrationDate)
.setRegistrationPubKey(ByteString.copyFrom(registrationPubKey))
.setRegistrationSignature(registrationSignature);
Optional.ofNullable(emailAddress).ifPresent(builder::setEmailAddress);
Optional.ofNullable(info).ifPresent(builder::setInfo);
Optional.ofNullable(extraDataMap).ifPresent(builder::putAllExtraData);
return protobuf.StoragePayload.newBuilder().setRefundAgent(builder).build();
}

public static RefundAgent fromProto(protobuf.RefundAgent proto) {
return new RefundAgent(NodeAddress.fromProto(proto.getNodeAddress()),
PubKeyRing.fromProto(proto.getPubKeyRing()),
new ArrayList<>(proto.getLanguageCodesList()),
proto.getRegistrationDate(),
proto.getRegistrationPubKey().toByteArray(),
proto.getRegistrationSignature(),
ProtoUtil.stringOrNullFromProto(proto.getEmailAddress()),
ProtoUtil.stringOrNullFromProto(proto.getInfo()),
CollectionUtils.isEmpty(proto.getExtraDataMap()) ? null : proto.getExtraDataMap());
}


///////////////////////////////////////////////////////////////////////////////////////////
// API
///////////////////////////////////////////////////////////////////////////////////////////


@Override
public String toString() {
return "RefundAgent{} " + super.toString();
}
}
@@ -0,0 +1,103 @@
/*
* 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.support.dispute.refund.refundagent;

import bisq.core.app.AppOptionKeys;
import bisq.core.filter.FilterManager;
import bisq.core.support.dispute.agent.DisputeAgentManager;
import bisq.core.user.User;

import bisq.network.p2p.storage.payload.ProtectedStorageEntry;

import bisq.common.crypto.KeyRing;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.inject.name.Named;

import java.util.List;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Singleton
public class RefundAgentManager extends DisputeAgentManager<RefundAgent> {

@Inject
public RefundAgentManager(KeyRing keyRing,
RefundAgentService refundAgentService,
User user,
FilterManager filterManager,
@Named(AppOptionKeys.USE_DEV_PRIVILEGE_KEYS) boolean useDevPrivilegeKeys) {
super(keyRing, refundAgentService, user, filterManager, useDevPrivilegeKeys);
}

@Override
protected List<String> getPubKeyList() {
return List.of("0365c6af94681dbee69de1851f98d4684063bf5c2d64b1c73ed5d90434f375a054",
"031c502a60f9dbdb5ae5e438a79819e4e1f417211dd537ac12c9bc23246534c4bd",
"02c1e5a242387b6d5319ce27246cea6edaaf51c3550591b528d2578a4753c56c2c",
"025c319faf7067d9299590dd6c97fe7e56cd4dac61205ccee1cd1fc390142390a2",
"038f6e24c2bfe5d51d0a290f20a9a657c270b94ef2b9c12cd15ca3725fa798fc55",
"0255256ff7fb615278c4544a9bbd3f5298b903b8a011cd7889be19b6b1c45cbefe",
"024a3a37289f08c910fbd925ebc72b946f33feaeff451a4738ee82037b4cda2e95",
"02a88b75e9f0f8afba1467ab26799dcc38fd7a6468fb2795444b425eb43e2c10bd",
"02349a51512c1c04c67118386f4d27d768c5195a83247c150a4b722d161722ba81",
"03f718a2e0dc672c7cdec0113e72c3322efc70412bb95870750d25c32cd98de17d",
"028ff47ee2c56e66313928975c58fa4f1b19a0f81f3a96c4e9c9c3c6768075509e",
"02b517c0cbc3a49548f448ddf004ed695c5a1c52ec110be1bfd65fa0ca0761c94b",
"03df837a3a0f3d858e82f3356b71d1285327f101f7c10b404abed2abc1c94e7169",
"0203a90fb2ab698e524a5286f317a183a84327b8f8c3f7fa4a98fec9e1cefd6b72",
"023c99cc073b851c892d8c43329ca3beb5d2213ee87111af49884e3ce66cbd5ba5");
}

@Override
protected boolean isExpectedInstance(ProtectedStorageEntry data) {
return data.getProtectedStoragePayload() instanceof RefundAgent;
}

@Override
protected void addAcceptedDisputeAgentToUser(RefundAgent disputeAgent) {
user.addAcceptedRefundAgent(disputeAgent);
}

@Override
protected void removeAcceptedDisputeAgentFromUser(ProtectedStorageEntry data) {
user.removeAcceptedRefundAgent((RefundAgent) data.getProtectedStoragePayload());
}

@Override
protected List<RefundAgent> getAcceptedDisputeAgentsFromUser() {
return user.getAcceptedRefundAgents();
}

@Override
protected void clearAcceptedDisputeAgentsAtUser() {
user.clearAcceptedRefundAgents();
}

@Override
protected RefundAgent getRegisteredDisputeAgentFromUser() {
return user.getRegisteredRefundAgent();
}

@Override
protected void setRegisteredDisputeAgentAtUser(RefundAgent disputeAgent) {
user.setRegisteredRefundAgent(disputeAgent);
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.