refactor node addresses and pub key rings to TradingPeer (#460)
This commit is contained in:
parent
c153afff67
commit
5fbc41946e
@ -116,7 +116,7 @@ public class CoreDisputesService {
|
|||||||
byte[] payoutTxSerialized = null;
|
byte[] payoutTxSerialized = null;
|
||||||
String payoutTxHashAsString = null;
|
String payoutTxHashAsString = null;
|
||||||
|
|
||||||
PubKeyRing arbitratorPubKeyRing = trade.getArbitratorPubKeyRing();
|
PubKeyRing arbitratorPubKeyRing = trade.getArbitrator().getPubKeyRing();
|
||||||
checkNotNull(arbitratorPubKeyRing, "arbitratorPubKeyRing must not be null");
|
checkNotNull(arbitratorPubKeyRing, "arbitratorPubKeyRing must not be null");
|
||||||
byte[] depositTxSerialized = null; // depositTx.bitcoinSerialize(); TODO (woodser)
|
byte[] depositTxSerialized = null; // depositTx.bitcoinSerialize(); TODO (woodser)
|
||||||
String depositTxHashAsString = null; // depositTx.getHashAsString(); TODO (woodser)
|
String depositTxHashAsString = null; // depositTx.getHashAsString(); TODO (woodser)
|
||||||
|
@ -42,14 +42,14 @@ public class TradeInfo implements Payload {
|
|||||||
// view and interact with trades.
|
// view and interact with trades.
|
||||||
|
|
||||||
private static final Function<Trade, String> toPeerNodeAddress = (trade) ->
|
private static final Function<Trade, String> toPeerNodeAddress = (trade) ->
|
||||||
trade.getTradingPeerNodeAddress() == null
|
trade.getTradingPeer() == null || trade.getTradingPeer().getNodeAddress() == null
|
||||||
? ""
|
? ""
|
||||||
: trade.getTradingPeerNodeAddress().getFullAddress();
|
: trade.getTradingPeer().getNodeAddress().getFullAddress();
|
||||||
|
|
||||||
private static final Function<Trade, String> toArbitratorNodeAddress = (trade) ->
|
private static final Function<Trade, String> toArbitratorNodeAddress = (trade) ->
|
||||||
trade.getArbitratorNodeAddress() == null
|
trade.getArbitrator() == null || trade.getArbitrator().getNodeAddress() == null
|
||||||
? ""
|
? ""
|
||||||
: trade.getArbitratorNodeAddress().getFullAddress();
|
: trade.getArbitrator().getNodeAddress().getFullAddress();
|
||||||
|
|
||||||
private static final Function<Trade, String> toRoundedVolume = (trade) ->
|
private static final Function<Trade, String> toRoundedVolume = (trade) ->
|
||||||
trade.getVolume() == null
|
trade.getVolume() == null
|
||||||
|
@ -139,7 +139,7 @@ public class Balances {
|
|||||||
if (trade.getContract() == null) continue;
|
if (trade.getContract() == null) continue;
|
||||||
Long reservedAmt;
|
Long reservedAmt;
|
||||||
OfferPayload offerPayload = trade.getContract().getOfferPayload();
|
OfferPayload offerPayload = trade.getContract().getOfferPayload();
|
||||||
if (trade.getArbitratorNodeAddress().equals(P2PService.getMyNodeAddress())) { // TODO (woodser): this only works if node address does not change
|
if (trade.getArbitrator().getNodeAddress().equals(P2PService.getMyNodeAddress())) { // TODO (woodser): this only works if node address does not change
|
||||||
reservedAmt = offerPayload.getAmount() + offerPayload.getBuyerSecurityDeposit() + offerPayload.getSellerSecurityDeposit(); // arbitrator reserved balance is sum of amounts sent to multisig
|
reservedAmt = offerPayload.getAmount() + offerPayload.getBuyerSecurityDeposit() + offerPayload.getSellerSecurityDeposit(); // arbitrator reserved balance is sum of amounts sent to multisig
|
||||||
} else {
|
} else {
|
||||||
reservedAmt = trade.getContract().isMyRoleBuyer(tradeManager.getKeyRing().getPubKeyRing()) ? offerPayload.getBuyerSecurityDeposit() : offerPayload.getAmount() + offerPayload.getSellerSecurityDeposit();
|
reservedAmt = trade.getContract().isMyRoleBuyer(tradeManager.getKeyRing().getPubKeyRing()) ? offerPayload.getBuyerSecurityDeposit() : offerPayload.getAmount() + offerPayload.getSellerSecurityDeposit();
|
||||||
|
@ -68,9 +68,9 @@ public class ArbitratorTrade extends Trade {
|
|||||||
xmrWalletService,
|
xmrWalletService,
|
||||||
processModel,
|
processModel,
|
||||||
uid,
|
uid,
|
||||||
proto.hasMakerNodeAddress() ? NodeAddress.fromProto(proto.getMakerNodeAddress()) : null,
|
proto.getProcessModel().getMaker().hasNodeAddress() ? NodeAddress.fromProto(proto.getProcessModel().getMaker().getNodeAddress()) : null,
|
||||||
proto.hasTakerNodeAddress() ? NodeAddress.fromProto(proto.getTakerNodeAddress()) : null,
|
proto.getProcessModel().getTaker().hasNodeAddress() ? NodeAddress.fromProto(proto.getProcessModel().getTaker().getNodeAddress()) : null,
|
||||||
proto.hasArbitratorNodeAddress() ? NodeAddress.fromProto(proto.getArbitratorNodeAddress()) : null),
|
proto.getProcessModel().getArbitrator().hasNodeAddress() ? NodeAddress.fromProto(proto.getProcessModel().getArbitrator().getNodeAddress()) : null),
|
||||||
proto,
|
proto,
|
||||||
coreProtoResolver);
|
coreProtoResolver);
|
||||||
}
|
}
|
||||||
|
@ -92,17 +92,13 @@ public final class BuyerAsMakerTrade extends BuyerTrade implements MakerTrade {
|
|||||||
xmrWalletService,
|
xmrWalletService,
|
||||||
processModel,
|
processModel,
|
||||||
uid,
|
uid,
|
||||||
proto.hasMakerNodeAddress() ? NodeAddress.fromProto(proto.getMakerNodeAddress()) : null,
|
proto.getProcessModel().getMaker().hasNodeAddress() ? NodeAddress.fromProto(proto.getProcessModel().getMaker().getNodeAddress()) : null,
|
||||||
proto.hasTakerNodeAddress() ? NodeAddress.fromProto(proto.getTakerNodeAddress()) : null,
|
proto.getProcessModel().getTaker().hasNodeAddress() ? NodeAddress.fromProto(proto.getProcessModel().getTaker().getNodeAddress()) : null,
|
||||||
proto.hasArbitratorNodeAddress() ? NodeAddress.fromProto(proto.getArbitratorNodeAddress()) : null);
|
proto.getProcessModel().getArbitrator().hasNodeAddress() ? NodeAddress.fromProto(proto.getProcessModel().getArbitrator().getNodeAddress()) : null);
|
||||||
|
|
||||||
trade.setAmountAsLong(proto.getAmountAsLong());
|
trade.setAmountAsLong(proto.getAmountAsLong());
|
||||||
trade.setPrice(proto.getPrice());
|
trade.setPrice(proto.getPrice());
|
||||||
|
|
||||||
trade.setMakerNodeAddress(proto.hasMakerNodeAddress() ? NodeAddress.fromProto(proto.getMakerNodeAddress()) : null);
|
|
||||||
trade.setTakerNodeAddress(proto.hasTakerNodeAddress() ? NodeAddress.fromProto(proto.getTakerNodeAddress()) : null);
|
|
||||||
trade.setArbitratorNodeAddress(proto.hasArbitratorNodeAddress() ? NodeAddress.fromProto(proto.getArbitratorNodeAddress()) : null);
|
|
||||||
|
|
||||||
return fromProto(trade,
|
return fromProto(trade,
|
||||||
proto,
|
proto,
|
||||||
coreProtoResolver);
|
coreProtoResolver);
|
||||||
|
@ -93,9 +93,9 @@ public final class BuyerAsTakerTrade extends BuyerTrade implements TakerTrade {
|
|||||||
xmrWalletService,
|
xmrWalletService,
|
||||||
processModel,
|
processModel,
|
||||||
uid,
|
uid,
|
||||||
proto.hasMakerNodeAddress() ? NodeAddress.fromProto(proto.getMakerNodeAddress()) : null,
|
proto.getProcessModel().getMaker().hasNodeAddress() ? NodeAddress.fromProto(proto.getProcessModel().getMaker().getNodeAddress()) : null,
|
||||||
proto.hasTakerNodeAddress() ? NodeAddress.fromProto(proto.getTakerNodeAddress()) : null,
|
proto.getProcessModel().getTaker().hasNodeAddress() ? NodeAddress.fromProto(proto.getProcessModel().getTaker().getNodeAddress()) : null,
|
||||||
proto.hasArbitratorNodeAddress() ? NodeAddress.fromProto(proto.getArbitratorNodeAddress()) : null),
|
proto.getProcessModel().getArbitrator().hasNodeAddress() ? NodeAddress.fromProto(proto.getProcessModel().getArbitrator().getNodeAddress()) : null),
|
||||||
proto,
|
proto,
|
||||||
coreProtoResolver);
|
coreProtoResolver);
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import bisq.core.monetary.Volume;
|
|||||||
import bisq.core.offer.Offer;
|
import bisq.core.offer.Offer;
|
||||||
import bisq.core.offer.OpenOffer;
|
import bisq.core.offer.OpenOffer;
|
||||||
import bisq.core.provider.price.PriceFeedService;
|
import bisq.core.provider.price.PriceFeedService;
|
||||||
|
import bisq.core.trade.protocol.TradingPeer;
|
||||||
import bisq.core.trade.statistics.TradeStatisticsManager;
|
import bisq.core.trade.statistics.TradeStatisticsManager;
|
||||||
import bisq.core.user.Preferences;
|
import bisq.core.user.Preferences;
|
||||||
|
|
||||||
@ -191,9 +192,10 @@ public class ClosedTradableManager implements PersistedDataHost {
|
|||||||
if (isOpenOffer(tradable)) {
|
if (isOpenOffer(tradable)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
NodeAddress addressInTrade = castToTradeModel(tradable).getTradingPeerNodeAddress();
|
NodeAddress addressInTrade = castToTradeModel(tradable).getTradingPeer().getNodeAddress();
|
||||||
return (int) getTradeModelStream()
|
return (int) getTradeModelStream()
|
||||||
.map(Trade::getTradingPeerNodeAddress)
|
.map(Trade::getTradingPeer)
|
||||||
|
.map(TradingPeer::getNodeAddress)
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.filter(address -> address.equals(addressInTrade))
|
.filter(address -> address.equals(addressInTrade))
|
||||||
.count();
|
.count();
|
||||||
|
@ -93,9 +93,9 @@ public final class SellerAsMakerTrade extends SellerTrade implements MakerTrade
|
|||||||
xmrWalletService,
|
xmrWalletService,
|
||||||
processModel,
|
processModel,
|
||||||
uid,
|
uid,
|
||||||
proto.hasMakerNodeAddress() ? NodeAddress.fromProto(proto.getMakerNodeAddress()) : null,
|
proto.getProcessModel().getMaker().hasNodeAddress() ? NodeAddress.fromProto(proto.getProcessModel().getMaker().getNodeAddress()) : null,
|
||||||
proto.hasTakerNodeAddress() ? NodeAddress.fromProto(proto.getTakerNodeAddress()) : null,
|
proto.getProcessModel().getTaker().hasNodeAddress() ? NodeAddress.fromProto(proto.getProcessModel().getTaker().getNodeAddress()) : null,
|
||||||
proto.hasArbitratorNodeAddress() ? NodeAddress.fromProto(proto.getArbitratorNodeAddress()) : null);
|
proto.getProcessModel().getArbitrator().hasNodeAddress() ? NodeAddress.fromProto(proto.getProcessModel().getArbitrator().getNodeAddress()) : null);
|
||||||
|
|
||||||
trade.setAmountAsLong(proto.getAmountAsLong());
|
trade.setAmountAsLong(proto.getAmountAsLong());
|
||||||
trade.setPrice(proto.getPrice());
|
trade.setPrice(proto.getPrice());
|
||||||
|
@ -93,9 +93,9 @@ public final class SellerAsTakerTrade extends SellerTrade implements TakerTrade
|
|||||||
xmrWalletService,
|
xmrWalletService,
|
||||||
processModel,
|
processModel,
|
||||||
uid,
|
uid,
|
||||||
proto.hasMakerNodeAddress() ? NodeAddress.fromProto(proto.getMakerNodeAddress()) : null,
|
proto.getProcessModel().getMaker().hasNodeAddress() ? NodeAddress.fromProto(proto.getProcessModel().getMaker().getNodeAddress()) : null,
|
||||||
proto.hasTakerNodeAddress() ? NodeAddress.fromProto(proto.getTakerNodeAddress()) : null,
|
proto.getProcessModel().getTaker().hasNodeAddress() ? NodeAddress.fromProto(proto.getProcessModel().getTaker().getNodeAddress()) : null,
|
||||||
proto.hasArbitratorNodeAddress() ? NodeAddress.fromProto(proto.getArbitratorNodeAddress()) : null),
|
proto.getProcessModel().getArbitrator().hasNodeAddress() ? NodeAddress.fromProto(proto.getProcessModel().getArbitrator().getNodeAddress()) : null),
|
||||||
proto,
|
proto,
|
||||||
coreProtoResolver);
|
coreProtoResolver);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ package bisq.core.trade;
|
|||||||
import bisq.core.monetary.Price;
|
import bisq.core.monetary.Price;
|
||||||
import bisq.core.monetary.Volume;
|
import bisq.core.monetary.Volume;
|
||||||
import bisq.core.offer.Offer;
|
import bisq.core.offer.Offer;
|
||||||
|
import bisq.core.trade.protocol.TradingPeer;
|
||||||
import bisq.network.p2p.NodeAddress;
|
import bisq.network.p2p.NodeAddress;
|
||||||
|
|
||||||
import bisq.common.proto.persistable.PersistablePayload;
|
import bisq.common.proto.persistable.PersistablePayload;
|
||||||
@ -76,6 +76,6 @@ public interface Tradable extends PersistablePayload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default Optional<NodeAddress> getOptionalTradingPeerNodeAddress() {
|
default Optional<NodeAddress> getOptionalTradingPeerNodeAddress() {
|
||||||
return asTradeModel().map(Trade::getTradingPeerNodeAddress);
|
return asTradeModel().map(Trade::getTradingPeer).map(TradingPeer::getNodeAddress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,6 @@ import bisq.network.p2p.NodeAddress;
|
|||||||
import bisq.network.p2p.P2PService;
|
import bisq.network.p2p.P2PService;
|
||||||
import bisq.common.UserThread;
|
import bisq.common.UserThread;
|
||||||
import bisq.common.crypto.Encryption;
|
import bisq.common.crypto.Encryption;
|
||||||
import bisq.common.crypto.PubKeyRing;
|
|
||||||
import bisq.common.proto.ProtoUtil;
|
import bisq.common.proto.ProtoUtil;
|
||||||
import bisq.common.taskrunner.Model;
|
import bisq.common.taskrunner.Model;
|
||||||
import bisq.common.util.Utilities;
|
import bisq.common.util.Utilities;
|
||||||
@ -337,18 +336,6 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
@Setter
|
@Setter
|
||||||
private byte[] contractHash;
|
private byte[] contractHash;
|
||||||
@Nullable
|
@Nullable
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private NodeAddress arbitratorNodeAddress;
|
|
||||||
@Nullable
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private PubKeyRing arbitratorPubKeyRing;
|
|
||||||
@Nullable
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private String takerPaymentAccountId;
|
|
||||||
@Nullable
|
|
||||||
private String errorMessage;
|
private String errorMessage;
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@ -402,14 +389,6 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
private byte[] delayedPayoutTxBytes;
|
private byte[] delayedPayoutTxBytes;
|
||||||
@Nullable
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private NodeAddress refundAgentNodeAddress;
|
|
||||||
@Nullable
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private PubKeyRing refundAgentPubKeyRing;
|
|
||||||
@Getter
|
@Getter
|
||||||
@Nullable
|
@Nullable
|
||||||
private RefundResultState refundResultState = RefundResultState.UNDEFINED_REFUND_RESULT;
|
private RefundResultState refundResultState = RefundResultState.UNDEFINED_REFUND_RESULT;
|
||||||
@ -436,23 +415,9 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
|
|
||||||
// Added in XMR integration
|
// Added in XMR integration
|
||||||
private transient List<TradeListener> tradeListeners; // notified on fully validated trade messages
|
private transient List<TradeListener> tradeListeners; // notified on fully validated trade messages
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private NodeAddress makerNodeAddress;
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private NodeAddress takerNodeAddress;
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private PubKeyRing makerPubKeyRing;
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private PubKeyRing takerPubKeyRing;
|
|
||||||
transient MoneroWalletListener depositTxListener;
|
transient MoneroWalletListener depositTxListener;
|
||||||
transient Boolean makerDepositLocked; // null when unknown, true while locked, false when unlocked
|
transient Boolean makerDepositLocked; // null when unknown, true while locked, false when unlocked
|
||||||
transient Boolean takerDepositLocked;
|
transient Boolean takerDepositLocked;
|
||||||
transient private MoneroTx makerDepositTx;
|
|
||||||
transient private MoneroTx takerDepositTx;
|
|
||||||
private Long startTime; // cache
|
private Long startTime; // cache
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -484,9 +449,9 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
this.takeOfferDate = new Date().getTime();
|
this.takeOfferDate = new Date().getTime();
|
||||||
this.tradeListeners = new ArrayList<TradeListener>();
|
this.tradeListeners = new ArrayList<TradeListener>();
|
||||||
|
|
||||||
this.makerNodeAddress = makerNodeAddress;
|
getMaker().setNodeAddress(makerNodeAddress);
|
||||||
this.takerNodeAddress = takerNodeAddress;
|
getTaker().setNodeAddress(takerNodeAddress);
|
||||||
this.arbitratorNodeAddress = arbitratorNodeAddress;
|
getArbitrator().setNodeAddress(arbitratorNodeAddress);
|
||||||
|
|
||||||
setAmount(tradeAmount);
|
setAmount(tradeAmount);
|
||||||
}
|
}
|
||||||
@ -578,22 +543,13 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
Optional.ofNullable(contract).ifPresent(e -> builder.setContract(contract.toProtoMessage()));
|
Optional.ofNullable(contract).ifPresent(e -> builder.setContract(contract.toProtoMessage()));
|
||||||
Optional.ofNullable(contractAsJson).ifPresent(builder::setContractAsJson);
|
Optional.ofNullable(contractAsJson).ifPresent(builder::setContractAsJson);
|
||||||
Optional.ofNullable(contractHash).ifPresent(e -> builder.setContractHash(ByteString.copyFrom(contractHash)));
|
Optional.ofNullable(contractHash).ifPresent(e -> builder.setContractHash(ByteString.copyFrom(contractHash)));
|
||||||
Optional.ofNullable(arbitratorNodeAddress).ifPresent(e -> builder.setArbitratorNodeAddress(arbitratorNodeAddress.toProtoMessage()));
|
|
||||||
Optional.ofNullable(refundAgentNodeAddress).ifPresent(e -> builder.setRefundAgentNodeAddress(refundAgentNodeAddress.toProtoMessage()));
|
|
||||||
Optional.ofNullable(takerPaymentAccountId).ifPresent(builder::setTakerPaymentAccountId);
|
|
||||||
Optional.ofNullable(errorMessage).ifPresent(builder::setErrorMessage);
|
Optional.ofNullable(errorMessage).ifPresent(builder::setErrorMessage);
|
||||||
Optional.ofNullable(arbitratorPubKeyRing).ifPresent(e -> builder.setArbitratorPubKeyRing(arbitratorPubKeyRing.toProtoMessage()));
|
|
||||||
Optional.ofNullable(refundAgentPubKeyRing).ifPresent(e -> builder.setRefundAgentPubKeyRing(refundAgentPubKeyRing.toProtoMessage()));
|
|
||||||
Optional.ofNullable(counterCurrencyTxId).ifPresent(e -> builder.setCounterCurrencyTxId(counterCurrencyTxId));
|
Optional.ofNullable(counterCurrencyTxId).ifPresent(e -> builder.setCounterCurrencyTxId(counterCurrencyTxId));
|
||||||
Optional.ofNullable(mediationResultState).ifPresent(e -> builder.setMediationResultState(MediationResultState.toProtoMessage(mediationResultState)));
|
Optional.ofNullable(mediationResultState).ifPresent(e -> builder.setMediationResultState(MediationResultState.toProtoMessage(mediationResultState)));
|
||||||
Optional.ofNullable(refundResultState).ifPresent(e -> builder.setRefundResultState(RefundResultState.toProtoMessage(refundResultState)));
|
Optional.ofNullable(refundResultState).ifPresent(e -> builder.setRefundResultState(RefundResultState.toProtoMessage(refundResultState)));
|
||||||
Optional.ofNullable(delayedPayoutTxBytes).ifPresent(e -> builder.setDelayedPayoutTxBytes(ByteString.copyFrom(delayedPayoutTxBytes)));
|
Optional.ofNullable(delayedPayoutTxBytes).ifPresent(e -> builder.setDelayedPayoutTxBytes(ByteString.copyFrom(delayedPayoutTxBytes)));
|
||||||
Optional.ofNullable(counterCurrencyExtraData).ifPresent(e -> builder.setCounterCurrencyExtraData(counterCurrencyExtraData));
|
Optional.ofNullable(counterCurrencyExtraData).ifPresent(e -> builder.setCounterCurrencyExtraData(counterCurrencyExtraData));
|
||||||
Optional.ofNullable(assetTxProofResult).ifPresent(e -> builder.setAssetTxProofResult(assetTxProofResult.name()));
|
Optional.ofNullable(assetTxProofResult).ifPresent(e -> builder.setAssetTxProofResult(assetTxProofResult.name()));
|
||||||
Optional.ofNullable(makerNodeAddress).ifPresent(e -> builder.setMakerNodeAddress(makerNodeAddress.toProtoMessage()));
|
|
||||||
Optional.ofNullable(makerPubKeyRing).ifPresent(e -> builder.setMakerPubKeyRing(makerPubKeyRing.toProtoMessage()));
|
|
||||||
Optional.ofNullable(takerNodeAddress).ifPresent(e -> builder.setTakerNodeAddress(takerNodeAddress.toProtoMessage()));
|
|
||||||
Optional.ofNullable(takerPubKeyRing).ifPresent(e -> builder.setTakerPubKeyRing(takerPubKeyRing.toProtoMessage()));
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -607,12 +563,7 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
trade.setContract(proto.hasContract() ? Contract.fromProto(proto.getContract(), coreProtoResolver) : null);
|
trade.setContract(proto.hasContract() ? Contract.fromProto(proto.getContract(), coreProtoResolver) : null);
|
||||||
trade.setContractAsJson(ProtoUtil.stringOrNullFromProto(proto.getContractAsJson()));
|
trade.setContractAsJson(ProtoUtil.stringOrNullFromProto(proto.getContractAsJson()));
|
||||||
trade.setContractHash(ProtoUtil.byteArrayOrNullFromProto(proto.getContractHash()));
|
trade.setContractHash(ProtoUtil.byteArrayOrNullFromProto(proto.getContractHash()));
|
||||||
trade.setArbitratorNodeAddress(proto.hasArbitratorNodeAddress() ? NodeAddress.fromProto(proto.getArbitratorNodeAddress()) : null);
|
|
||||||
trade.setRefundAgentNodeAddress(proto.hasRefundAgentNodeAddress() ? NodeAddress.fromProto(proto.getRefundAgentNodeAddress()) : null);
|
|
||||||
trade.setTakerPaymentAccountId(ProtoUtil.stringOrNullFromProto(proto.getTakerPaymentAccountId()));
|
|
||||||
trade.setErrorMessage(ProtoUtil.stringOrNullFromProto(proto.getErrorMessage()));
|
trade.setErrorMessage(ProtoUtil.stringOrNullFromProto(proto.getErrorMessage()));
|
||||||
trade.setArbitratorPubKeyRing(proto.hasArbitratorPubKeyRing() ? PubKeyRing.fromProto(proto.getArbitratorPubKeyRing()) : null);
|
|
||||||
trade.setRefundAgentPubKeyRing(proto.hasRefundAgentPubKeyRing() ? PubKeyRing.fromProto(proto.getRefundAgentPubKeyRing()) : null);
|
|
||||||
trade.setCounterCurrencyTxId(proto.getCounterCurrencyTxId().isEmpty() ? null : proto.getCounterCurrencyTxId());
|
trade.setCounterCurrencyTxId(proto.getCounterCurrencyTxId().isEmpty() ? null : proto.getCounterCurrencyTxId());
|
||||||
trade.setMediationResultState(MediationResultState.fromProto(proto.getMediationResultState()));
|
trade.setMediationResultState(MediationResultState.fromProto(proto.getMediationResultState()));
|
||||||
trade.setRefundResultState(RefundResultState.fromProto(proto.getRefundResultState()));
|
trade.setRefundResultState(RefundResultState.fromProto(proto.getRefundResultState()));
|
||||||
@ -626,10 +577,6 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
persistedAssetTxProofResult = null;
|
persistedAssetTxProofResult = null;
|
||||||
}
|
}
|
||||||
trade.setAssetTxProofResult(persistedAssetTxProofResult);
|
trade.setAssetTxProofResult(persistedAssetTxProofResult);
|
||||||
trade.setMakerNodeAddress(NodeAddress.fromProto(proto.getMakerNodeAddress()));
|
|
||||||
trade.setMakerPubKeyRing(proto.hasMakerPubKeyRing() ? PubKeyRing.fromProto(proto.getMakerPubKeyRing()) : null);
|
|
||||||
trade.setTakerNodeAddress(NodeAddress.fromProto(proto.getTakerNodeAddress()));
|
|
||||||
trade.setTakerPubKeyRing(proto.hasTakerPubKeyRing() ? PubKeyRing.fromProto(proto.getTakerPubKeyRing()) : null);
|
|
||||||
|
|
||||||
trade.chatMessages.addAll(proto.getChatMessageList().stream()
|
trade.chatMessages.addAll(proto.getChatMessageList().stream()
|
||||||
.map(ChatMessage::fromPayloadProto)
|
.map(ChatMessage::fromPayloadProto)
|
||||||
@ -639,8 +586,8 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void initialize(ProcessModelServiceProvider serviceProvider) {
|
public void initialize(ProcessModelServiceProvider serviceProvider) {
|
||||||
serviceProvider.getArbitratorManager().getDisputeAgentByNodeAddress(arbitratorNodeAddress).ifPresent(arbitrator -> {
|
serviceProvider.getArbitratorManager().getDisputeAgentByNodeAddress(getArbitrator().getNodeAddress()).ifPresent(arbitrator -> {
|
||||||
arbitratorPubKeyRing = arbitrator.getPubKeyRing();
|
getArbitrator().setPubKeyRing(arbitrator.getPubKeyRing());
|
||||||
});
|
});
|
||||||
|
|
||||||
isInitialized = true;
|
isInitialized = true;
|
||||||
@ -652,36 +599,7 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setMyNodeAddress() {
|
public void setMyNodeAddress() {
|
||||||
if (this instanceof MakerTrade) makerNodeAddress = P2PService.getMyNodeAddress();
|
getSelf().setNodeAddress(P2PService.getMyNodeAddress());
|
||||||
else if (this instanceof TakerTrade) takerNodeAddress = P2PService.getMyNodeAddress();
|
|
||||||
else if (this instanceof ArbitratorTrade) arbitratorNodeAddress = P2PService.getMyNodeAddress();
|
|
||||||
else throw new RuntimeException("Must be maker, taker, or arbitrator to set own address");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTradingPeerNodeAddress(NodeAddress peerAddress) {
|
|
||||||
if (this instanceof MakerTrade) takerNodeAddress = peerAddress;
|
|
||||||
else if (this instanceof TakerTrade) makerNodeAddress = peerAddress;
|
|
||||||
else throw new RuntimeException("Must be maker or taker to set peer address");
|
|
||||||
}
|
|
||||||
|
|
||||||
public NodeAddress getTradingPeerNodeAddress() {
|
|
||||||
if (this instanceof MakerTrade) return takerNodeAddress;
|
|
||||||
else if (this instanceof TakerTrade) return makerNodeAddress;
|
|
||||||
else if (this instanceof ArbitratorTrade) return null;
|
|
||||||
else throw new RuntimeException("Unknown trade type: " + this.getClass().getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTradingPeerPubKeyRing(PubKeyRing peerPubKeyRing) {
|
|
||||||
if (this instanceof MakerTrade) takerPubKeyRing = peerPubKeyRing;
|
|
||||||
else if (this instanceof TakerTrade) makerPubKeyRing = peerPubKeyRing;
|
|
||||||
else throw new RuntimeException("Must be maker or taker to set peer address");
|
|
||||||
}
|
|
||||||
|
|
||||||
public PubKeyRing getTradingPeerPubKeyRing() {
|
|
||||||
if (this instanceof MakerTrade) return takerPubKeyRing;
|
|
||||||
else if (this instanceof TakerTrade) return makerPubKeyRing;
|
|
||||||
else if (this instanceof ArbitratorTrade) return null;
|
|
||||||
else throw new RuntimeException("Unknown trade type: " + this.getClass().getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -696,9 +614,9 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
getOffer().getOfferPayload(),
|
getOffer().getOfferPayload(),
|
||||||
checkNotNull(getAmount()).value,
|
checkNotNull(getAmount()).value,
|
||||||
getPrice().getValue(),
|
getPrice().getValue(),
|
||||||
isBuyerMakerAndSellerTaker ? getMakerNodeAddress() : getTakerNodeAddress(), // buyer node address // TODO (woodser): use maker and taker node address instead of buyer and seller node address for consistency
|
(isBuyerMakerAndSellerTaker ? getMaker() : getTaker()).getNodeAddress(), // buyer node address // TODO (woodser): use maker and taker node address instead of buyer and seller node address for consistency
|
||||||
isBuyerMakerAndSellerTaker ? getTakerNodeAddress() : getMakerNodeAddress(), // seller node address
|
(isBuyerMakerAndSellerTaker ? getTaker() : getMaker()).getNodeAddress(), // seller node address
|
||||||
getArbitratorNodeAddress(),
|
getArbitrator().getNodeAddress(),
|
||||||
isBuyerMakerAndSellerTaker,
|
isBuyerMakerAndSellerTaker,
|
||||||
this instanceof MakerTrade ? processModel.getAccountId() : getMaker().getAccountId(), // maker account id
|
this instanceof MakerTrade ? processModel.getAccountId() : getMaker().getAccountId(), // maker account id
|
||||||
this instanceof TakerTrade ? processModel.getAccountId() : getTaker().getAccountId(), // taker account id
|
this instanceof TakerTrade ? processModel.getAccountId() : getTaker().getAccountId(), // taker account id
|
||||||
@ -706,8 +624,8 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
checkNotNull(this instanceof TakerTrade ? processModel.getPaymentAccountPayload(this).getPaymentMethodId() : getTaker().getPaymentMethodId()), // taker payment method id
|
checkNotNull(this instanceof TakerTrade ? processModel.getPaymentAccountPayload(this).getPaymentMethodId() : getTaker().getPaymentMethodId()), // taker payment method id
|
||||||
this instanceof MakerTrade ? processModel.getPaymentAccountPayload(this).getHash() : getMaker().getPaymentAccountPayloadHash(), // maker payment account payload hash
|
this instanceof MakerTrade ? processModel.getPaymentAccountPayload(this).getHash() : getMaker().getPaymentAccountPayloadHash(), // maker payment account payload hash
|
||||||
this instanceof TakerTrade ? processModel.getPaymentAccountPayload(this).getHash() : getTaker().getPaymentAccountPayloadHash(), // maker payment account payload hash
|
this instanceof TakerTrade ? processModel.getPaymentAccountPayload(this).getHash() : getTaker().getPaymentAccountPayloadHash(), // maker payment account payload hash
|
||||||
getMakerPubKeyRing(),
|
getMaker().getPubKeyRing(),
|
||||||
getTakerPubKeyRing(),
|
getTaker().getPubKeyRing(),
|
||||||
this instanceof MakerTrade ? xmrWalletService.getAddressEntry(getId(), XmrAddressEntry.Context.TRADE_PAYOUT).get().getAddressString() : getMaker().getPayoutAddressString(), // maker payout address
|
this instanceof MakerTrade ? xmrWalletService.getAddressEntry(getId(), XmrAddressEntry.Context.TRADE_PAYOUT).get().getAddressString() : getMaker().getPayoutAddressString(), // maker payout address
|
||||||
this instanceof TakerTrade ? xmrWalletService.getAddressEntry(getId(), XmrAddressEntry.Context.TRADE_PAYOUT).get().getAddressString() : getTaker().getPayoutAddressString(), // taker payout address
|
this instanceof TakerTrade ? xmrWalletService.getAddressEntry(getId(), XmrAddressEntry.Context.TRADE_PAYOUT).get().getAddressString() : getTaker().getPayoutAddressString(), // taker payout address
|
||||||
getLockTime(),
|
getLockTime(),
|
||||||
@ -891,8 +809,8 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
if (txs.size() == 2) {
|
if (txs.size() == 2) {
|
||||||
setStatePublished();
|
setStatePublished();
|
||||||
boolean makerFirst = txs.get(0).getHash().equals(processModel.getMaker().getDepositTxHash());
|
boolean makerFirst = txs.get(0).getHash().equals(processModel.getMaker().getDepositTxHash());
|
||||||
makerDepositTx = makerFirst ? txs.get(0) : txs.get(1);
|
getMaker().setDepositTx(makerFirst ? txs.get(0) : txs.get(1));
|
||||||
takerDepositTx = makerFirst ? txs.get(1) : txs.get(0);
|
getTaker().setDepositTx(makerFirst ? txs.get(1) : txs.get(0));
|
||||||
|
|
||||||
// check if deposit txs unlocked
|
// check if deposit txs unlocked
|
||||||
if (txs.get(0).isConfirmed() && txs.get(1).isConfirmed()) {
|
if (txs.get(0).isConfirmed() && txs.get(1).isConfirmed()) {
|
||||||
@ -930,8 +848,8 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
|
|
||||||
// update deposit txs
|
// update deposit txs
|
||||||
boolean makerFirst = txs.get(0).getHash().equals(processModel.getMaker().getDepositTxHash());
|
boolean makerFirst = txs.get(0).getHash().equals(processModel.getMaker().getDepositTxHash());
|
||||||
makerDepositTx = makerFirst ? txs.get(0) : txs.get(1);
|
getMaker().setDepositTx(makerFirst ? txs.get(0) : txs.get(1));
|
||||||
takerDepositTx = makerFirst ? txs.get(1) : txs.get(0);
|
getTaker().setDepositTx(makerFirst ? txs.get(1) : txs.get(0));
|
||||||
|
|
||||||
// check if deposit txs confirmed and compute unlock height
|
// check if deposit txs confirmed and compute unlock height
|
||||||
if (txs.size() == 2 && txs.get(0).isConfirmed() && txs.get(1).isConfirmed() && unlockHeight == null) {
|
if (txs.size() == 2 && txs.get(0).isConfirmed() && txs.get(1).isConfirmed() && unlockHeight == null) {
|
||||||
@ -958,8 +876,8 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
public MoneroTx getTakerDepositTx() {
|
public MoneroTx getTakerDepositTx() {
|
||||||
String depositTxHash = getProcessModel().getTaker().getDepositTxHash();
|
String depositTxHash = getProcessModel().getTaker().getDepositTxHash();
|
||||||
try {
|
try {
|
||||||
if (takerDepositTx == null) takerDepositTx = depositTxHash == null ? null : getXmrWalletService().getTxWithCache(depositTxHash);
|
if (getTaker().getDepositTx() == null) getTaker().setDepositTx(depositTxHash == null ? null : getXmrWalletService().getTxWithCache(depositTxHash));
|
||||||
return takerDepositTx;
|
return getTaker().getDepositTx();
|
||||||
} catch (MoneroError e) {
|
} catch (MoneroError e) {
|
||||||
log.error("Wallet is missing taker deposit tx " + depositTxHash);
|
log.error("Wallet is missing taker deposit tx " + depositTxHash);
|
||||||
return null;
|
return null;
|
||||||
@ -970,8 +888,8 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
public MoneroTx getMakerDepositTx() {
|
public MoneroTx getMakerDepositTx() {
|
||||||
String depositTxHash = getProcessModel().getMaker().getDepositTxHash();
|
String depositTxHash = getProcessModel().getMaker().getDepositTxHash();
|
||||||
try {
|
try {
|
||||||
if (makerDepositTx == null) makerDepositTx = depositTxHash == null ? null : getXmrWalletService().getTxWithCache(depositTxHash);
|
if (getMaker().getDepositTx() == null) getMaker().setDepositTx(depositTxHash == null ? null : getXmrWalletService().getTxWithCache(depositTxHash));
|
||||||
return makerDepositTx;
|
return getMaker().getDepositTx();
|
||||||
} catch (MoneroError e) {
|
} catch (MoneroError e) {
|
||||||
log.error("Wallet is missing maker deposit tx " + depositTxHash);
|
log.error("Wallet is missing maker deposit tx " + depositTxHash);
|
||||||
return null;
|
return null;
|
||||||
@ -1171,6 +1089,10 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
throw new RuntimeException("Trade is not maker, taker, or arbitrator");
|
throw new RuntimeException("Trade is not maker, taker, or arbitrator");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TradingPeer getArbitrator() {
|
||||||
|
return processModel.getArbitrator();
|
||||||
|
}
|
||||||
|
|
||||||
public TradingPeer getMaker() {
|
public TradingPeer getMaker() {
|
||||||
return processModel.getMaker();
|
return processModel.getMaker();
|
||||||
}
|
}
|
||||||
@ -1208,10 +1130,10 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
* @return the trade peer
|
* @return the trade peer
|
||||||
*/
|
*/
|
||||||
public TradingPeer getTradingPeer(NodeAddress address) {
|
public TradingPeer getTradingPeer(NodeAddress address) {
|
||||||
if (address.equals(getMakerNodeAddress())) return processModel.getMaker();
|
if (address.equals(getMaker().getNodeAddress())) return processModel.getMaker();
|
||||||
if (address.equals(getTakerNodeAddress())) return processModel.getTaker();
|
if (address.equals(getTaker().getNodeAddress())) return processModel.getTaker();
|
||||||
if (address.equals(getArbitratorNodeAddress())) return processModel.getArbitrator();
|
if (address.equals(getArbitrator().getNodeAddress())) return processModel.getArbitrator();
|
||||||
throw new RuntimeException("No protocol participant has node address: " + address);
|
throw new RuntimeException("No trade participant with the given address. Their address might have changed: " + address);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getTakeOfferDate() {
|
public Date getTakeOfferDate() {
|
||||||
@ -1505,7 +1427,6 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
",\n contract=" + contract +
|
",\n contract=" + contract +
|
||||||
",\n contractAsJson='" + contractAsJson + '\'' +
|
",\n contractAsJson='" + contractAsJson + '\'' +
|
||||||
",\n contractHash=" + Utilities.bytesAsHexString(contractHash) +
|
",\n contractHash=" + Utilities.bytesAsHexString(contractHash) +
|
||||||
",\n takerPaymentAccountId='" + takerPaymentAccountId + '\'' +
|
|
||||||
",\n errorMessage='" + errorMessage + '\'' +
|
",\n errorMessage='" + errorMessage + '\'' +
|
||||||
",\n counterCurrencyTxId='" + counterCurrencyTxId + '\'' +
|
",\n counterCurrencyTxId='" + counterCurrencyTxId + '\'' +
|
||||||
",\n counterCurrencyExtraData='" + counterCurrencyExtraData + '\'' +
|
",\n counterCurrencyExtraData='" + counterCurrencyExtraData + '\'' +
|
||||||
@ -1519,7 +1440,6 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
",\n disputeStateProperty=" + disputeStateProperty +
|
",\n disputeStateProperty=" + disputeStateProperty +
|
||||||
",\n tradePeriodStateProperty=" + tradePeriodStateProperty +
|
",\n tradePeriodStateProperty=" + tradePeriodStateProperty +
|
||||||
",\n errorMessageProperty=" + errorMessageProperty +
|
",\n errorMessageProperty=" + errorMessageProperty +
|
||||||
",\n depositTx=" + takerDepositTx +
|
|
||||||
",\n delayedPayoutTx=" + delayedPayoutTx +
|
",\n delayedPayoutTx=" + delayedPayoutTx +
|
||||||
",\n payoutTx=" + payoutTx +
|
",\n payoutTx=" + payoutTx +
|
||||||
",\n tradeAmount=" + tradeAmount +
|
",\n tradeAmount=" + tradeAmount +
|
||||||
@ -1529,16 +1449,8 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
",\n mediationResultStateProperty=" + mediationResultStateProperty +
|
",\n mediationResultStateProperty=" + mediationResultStateProperty +
|
||||||
",\n lockTime=" + lockTime +
|
",\n lockTime=" + lockTime +
|
||||||
",\n delayedPayoutTxBytes=" + Utilities.bytesAsHexString(delayedPayoutTxBytes) +
|
",\n delayedPayoutTxBytes=" + Utilities.bytesAsHexString(delayedPayoutTxBytes) +
|
||||||
",\n refundAgentNodeAddress=" + refundAgentNodeAddress +
|
|
||||||
",\n refundAgentPubKeyRing=" + refundAgentPubKeyRing +
|
|
||||||
",\n refundResultState=" + refundResultState +
|
",\n refundResultState=" + refundResultState +
|
||||||
",\n refundResultStateProperty=" + refundResultStateProperty +
|
",\n refundResultStateProperty=" + refundResultStateProperty +
|
||||||
",\n makerNodeAddress=" + makerNodeAddress +
|
|
||||||
",\n makerPubKeyRing=" + makerPubKeyRing +
|
|
||||||
",\n takerNodeAddress=" + takerNodeAddress +
|
|
||||||
",\n takerPubKeyRing=" + takerPubKeyRing +
|
|
||||||
",\n arbitratorNodeAddress=" + arbitratorNodeAddress +
|
|
||||||
",\n arbitratorPubKeyRing=" + arbitratorPubKeyRing +
|
|
||||||
"\n}";
|
"\n}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -538,11 +538,11 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
|
|||||||
request.getTakerNodeAddress(),
|
request.getTakerNodeAddress(),
|
||||||
request.getArbitratorNodeAddress());
|
request.getArbitratorNodeAddress());
|
||||||
|
|
||||||
//System.out.println("TradeManager trade.setTradingPeerNodeAddress(): " + sender);
|
//System.out.println("TradeManager trade.getTradingPeer().setNodeAddress(): " + sender);
|
||||||
//trade.setTradingPeerNodeAddress(sender);
|
//trade.getTradingPeer().setNodeAddress(sender);
|
||||||
// TODO (woodser): what if maker's address changes while offer open, or taker's address changes after multisig deposit available? need to verify and update. see OpenOfferManager.maybeUpdatePersistedOffers()
|
// TODO (woodser): what if maker's address changes while offer open, or taker's address changes after multisig deposit available? need to verify and update. see OpenOfferManager.maybeUpdatePersistedOffers()
|
||||||
trade.setArbitratorPubKeyRing(arbitrator.getPubKeyRing());
|
trade.getArbitrator().setPubKeyRing(arbitrator.getPubKeyRing());
|
||||||
trade.setMakerPubKeyRing(trade.getOffer().getPubKeyRing());
|
trade.getMaker().setPubKeyRing(trade.getOffer().getPubKeyRing());
|
||||||
initTradeAndProtocol(trade, getTradeProtocol(trade));
|
initTradeAndProtocol(trade, getTradeProtocol(trade));
|
||||||
trade.getSelf().setReserveTxHash(openOffer.getReserveTxHash()); // TODO (woodser): initialize in initTradeAndProtocol?
|
trade.getSelf().setReserveTxHash(openOffer.getReserveTxHash()); // TODO (woodser): initialize in initTradeAndProtocol?
|
||||||
trade.getSelf().setReserveTxHex(openOffer.getReserveTxHex());
|
trade.getSelf().setReserveTxHex(openOffer.getReserveTxHex());
|
||||||
@ -764,8 +764,8 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
|
|||||||
trade.getProcessModel().setMakerSignature(model.getMakerSignature());
|
trade.getProcessModel().setMakerSignature(model.getMakerSignature());
|
||||||
trade.getProcessModel().setUseSavingsWallet(useSavingsWallet);
|
trade.getProcessModel().setUseSavingsWallet(useSavingsWallet);
|
||||||
trade.getProcessModel().setFundsNeededForTradeAsLong(fundsNeededForTrade.value);
|
trade.getProcessModel().setFundsNeededForTradeAsLong(fundsNeededForTrade.value);
|
||||||
trade.setTakerPubKeyRing(model.getPubKeyRing());
|
trade.getTaker().setPubKeyRing(model.getPubKeyRing());
|
||||||
trade.setTakerPaymentAccountId(paymentAccountId);
|
trade.getTaker().setPaymentAccountId(paymentAccountId);
|
||||||
|
|
||||||
TradeProtocol tradeProtocol = TradeProtocolFactory.getNewTradeProtocol(trade);
|
TradeProtocol tradeProtocol = TradeProtocolFactory.getNewTradeProtocol(trade);
|
||||||
TradeProtocol prev = tradeProtocolByTradeId.put(trade.getUid(), tradeProtocol);
|
TradeProtocol prev = tradeProtocolByTradeId.put(trade.getUid(), tradeProtocol);
|
||||||
|
@ -51,7 +51,7 @@ public class BuyerAsTakerProtocol extends BuyerProtocol implements TakerProtocol
|
|||||||
super(trade);
|
super(trade);
|
||||||
Offer offer = checkNotNull(trade.getOffer());
|
Offer offer = checkNotNull(trade.getOffer());
|
||||||
trade.getTradingPeer().setPubKeyRing(offer.getPubKeyRing());
|
trade.getTradingPeer().setPubKeyRing(offer.getPubKeyRing());
|
||||||
trade.setMakerPubKeyRing(offer.getPubKeyRing());
|
trade.getMaker().setPubKeyRing(offer.getPubKeyRing());
|
||||||
|
|
||||||
// TODO (woodser): setup deposit and payout listeners on construction for startup like before rebase?
|
// TODO (woodser): setup deposit and payout listeners on construction for startup like before rebase?
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ public class BuyerAsTakerProtocol extends BuyerProtocol implements TakerProtocol
|
|||||||
this.errorMessageHandler = errorMessageHandler;
|
this.errorMessageHandler = errorMessageHandler;
|
||||||
expect(phase(Trade.Phase.INIT)
|
expect(phase(Trade.Phase.INIT)
|
||||||
.with(TakerEvent.TAKE_OFFER)
|
.with(TakerEvent.TAKE_OFFER)
|
||||||
.from(trade.getTradingPeerNodeAddress()))
|
.from(trade.getTradingPeer().getNodeAddress()))
|
||||||
.setup(tasks(
|
.setup(tasks(
|
||||||
ApplyFilter.class,
|
ApplyFilter.class,
|
||||||
TakerReserveTradeFunds.class,
|
TakerReserveTradeFunds.class,
|
||||||
|
@ -285,7 +285,7 @@ public class ProcessModel implements Model, PersistablePayload {
|
|||||||
if (trade instanceof MakerTrade)
|
if (trade instanceof MakerTrade)
|
||||||
paymentAccount = getUser().getPaymentAccount(offer.getMakerPaymentAccountId());
|
paymentAccount = getUser().getPaymentAccount(offer.getMakerPaymentAccountId());
|
||||||
else
|
else
|
||||||
paymentAccount = getUser().getPaymentAccount(trade.getTakerPaymentAccountId());
|
paymentAccount = getUser().getPaymentAccount(trade.getTaker().getPaymentAccountId());
|
||||||
return paymentAccount != null ? paymentAccount.getPaymentAccountPayload() : null;
|
return paymentAccount != null ? paymentAccount.getPaymentAccountPayload() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ public class SellerAsTakerProtocol extends SellerProtocol implements TakerProtoc
|
|||||||
super(trade);
|
super(trade);
|
||||||
Offer offer = checkNotNull(trade.getOffer());
|
Offer offer = checkNotNull(trade.getOffer());
|
||||||
trade.getTradingPeer().setPubKeyRing(offer.getPubKeyRing());
|
trade.getTradingPeer().setPubKeyRing(offer.getPubKeyRing());
|
||||||
trade.setMakerPubKeyRing(offer.getPubKeyRing());
|
trade.getMaker().setPubKeyRing(offer.getPubKeyRing());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ public class SellerAsTakerProtocol extends SellerProtocol implements TakerProtoc
|
|||||||
this.errorMessageHandler = errorMessageHandler;
|
this.errorMessageHandler = errorMessageHandler;
|
||||||
expect(phase(Trade.Phase.INIT)
|
expect(phase(Trade.Phase.INIT)
|
||||||
.with(TakerEvent.TAKE_OFFER)
|
.with(TakerEvent.TAKE_OFFER)
|
||||||
.from(trade.getTradingPeerNodeAddress()))
|
.from(trade.getTradingPeer().getNodeAddress()))
|
||||||
.setup(tasks(
|
.setup(tasks(
|
||||||
ApplyFilter.class,
|
ApplyFilter.class,
|
||||||
TakerReserveTradeFunds.class,
|
TakerReserveTradeFunds.class,
|
||||||
|
@ -453,8 +453,6 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
|
|||||||
|
|
||||||
protected void sendAckMessage(NodeAddress peer, TradeMessage message, boolean result, @Nullable String errorMessage) {
|
protected void sendAckMessage(NodeAddress peer, TradeMessage message, boolean result, @Nullable String errorMessage) {
|
||||||
|
|
||||||
// TODO (woodser): remove trade.getTradingPeerNodeAddress() and processModel.getTempTradingPeerNodeAddress() if everything should be maker, taker, or arbitrator
|
|
||||||
|
|
||||||
// get peer's pub key ring
|
// get peer's pub key ring
|
||||||
PubKeyRing peersPubKeyRing = getPeersPubKeyRing(peer);
|
PubKeyRing peersPubKeyRing = getPeersPubKeyRing(peer);
|
||||||
if (peersPubKeyRing == null) {
|
if (peersPubKeyRing == null) {
|
||||||
@ -546,9 +544,9 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
|
|||||||
|
|
||||||
private PubKeyRing getPeersPubKeyRing(NodeAddress peer) {
|
private PubKeyRing getPeersPubKeyRing(NodeAddress peer) {
|
||||||
trade.setMyNodeAddress(); // TODO: this is a hack to update my node address before verifying the message
|
trade.setMyNodeAddress(); // TODO: this is a hack to update my node address before verifying the message
|
||||||
if (peer.equals(trade.getArbitratorNodeAddress())) return trade.getArbitratorPubKeyRing();
|
if (peer.equals(trade.getArbitrator().getNodeAddress())) return trade.getArbitrator().getPubKeyRing();
|
||||||
else if (peer.equals(trade.getMakerNodeAddress())) return trade.getMakerPubKeyRing();
|
else if (peer.equals(trade.getMaker().getNodeAddress())) return trade.getMaker().getPubKeyRing();
|
||||||
else if (peer.equals(trade.getTakerNodeAddress())) return trade.getTakerPubKeyRing();
|
else if (peer.equals(trade.getTaker().getNodeAddress())) return trade.getTaker().getPubKeyRing();
|
||||||
else {
|
else {
|
||||||
log.warn("Cannot get peer's pub key ring because peer is not maker, taker, or arbitrator. Their address might have changed: " + peer);
|
log.warn("Cannot get peer's pub key ring because peer is not maker, taker, or arbitrator. Their address might have changed: " + peer);
|
||||||
return null;
|
return null;
|
||||||
@ -565,7 +563,7 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
|
|||||||
if (this instanceof ArbitratorProtocol) {
|
if (this instanceof ArbitratorProtocol) {
|
||||||
|
|
||||||
// valid if traders unknown
|
// valid if traders unknown
|
||||||
if (trade.getMaker().getPubKeyRing() == null || trade.getTakerPubKeyRing() == null) return true;
|
if (trade.getMaker().getPubKeyRing() == null || trade.getTaker().getPubKeyRing() == null) return true;
|
||||||
|
|
||||||
// valid if maker pub key
|
// valid if maker pub key
|
||||||
if (message.getSignaturePubKey().equals(trade.getMaker().getPubKeyRing().getSignaturePubKey())) return true;
|
if (message.getSignaturePubKey().equals(trade.getMaker().getPubKeyRing().getSignaturePubKey())) return true;
|
||||||
@ -575,10 +573,10 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
// valid if arbitrator or peer unknown
|
// valid if arbitrator or peer unknown
|
||||||
if (trade.getArbitratorPubKeyRing() == null || (trade.getTradingPeer() == null || trade.getTradingPeer().getPubKeyRing() == null)) return true;
|
if (trade.getArbitrator().getPubKeyRing() == null || (trade.getTradingPeer() == null || trade.getTradingPeer().getPubKeyRing() == null)) return true;
|
||||||
|
|
||||||
// valid if arbitrator's pub key ring
|
// valid if arbitrator's pub key ring
|
||||||
if (message.getSignaturePubKey().equals(trade.getArbitratorPubKeyRing().getSignaturePubKey())) return true;
|
if (message.getSignaturePubKey().equals(trade.getArbitrator().getPubKeyRing().getSignaturePubKey())) return true;
|
||||||
|
|
||||||
// valid if peer's pub key ring
|
// valid if peer's pub key ring
|
||||||
if (message.getSignaturePubKey().equals(trade.getTradingPeer().getPubKeyRing().getSignaturePubKey())) return true;
|
if (message.getSignaturePubKey().equals(trade.getTradingPeer().getPubKeyRing().getSignaturePubKey())) return true;
|
||||||
|
@ -20,7 +20,7 @@ package bisq.core.trade.protocol;
|
|||||||
import bisq.core.btc.model.RawTransactionInput;
|
import bisq.core.btc.model.RawTransactionInput;
|
||||||
import bisq.core.payment.payload.PaymentAccountPayload;
|
import bisq.core.payment.payload.PaymentAccountPayload;
|
||||||
import bisq.core.proto.CoreProtoResolver;
|
import bisq.core.proto.CoreProtoResolver;
|
||||||
|
import bisq.network.p2p.NodeAddress;
|
||||||
import bisq.common.crypto.PubKeyRing;
|
import bisq.common.crypto.PubKeyRing;
|
||||||
import bisq.common.proto.ProtoUtil;
|
import bisq.common.proto.ProtoUtil;
|
||||||
import bisq.common.proto.persistable.PersistablePayload;
|
import bisq.common.proto.persistable.PersistablePayload;
|
||||||
@ -35,6 +35,7 @@ import java.util.stream.Collectors;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import monero.daemon.model.MoneroTx;
|
||||||
import monero.wallet.model.MoneroTxWallet;
|
import monero.wallet.model.MoneroTxWallet;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@ -53,9 +54,14 @@ public final class TradingPeer implements PersistablePayload {
|
|||||||
@Setter
|
@Setter
|
||||||
@Nullable
|
@Nullable
|
||||||
transient private byte[] preparedDepositTx;
|
transient private byte[] preparedDepositTx;
|
||||||
|
transient private MoneroTx depositTx;
|
||||||
|
|
||||||
// Persistable mutable
|
// Persistable mutable
|
||||||
@Nullable
|
@Nullable
|
||||||
|
private NodeAddress nodeAddress;
|
||||||
|
@Nullable
|
||||||
|
private PubKeyRing pubKeyRing;
|
||||||
|
@Nullable
|
||||||
private String accountId;
|
private String accountId;
|
||||||
@Nullable
|
@Nullable
|
||||||
private String paymentAccountId;
|
private String paymentAccountId;
|
||||||
@ -78,8 +84,6 @@ public final class TradingPeer implements PersistablePayload {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private byte[] signature;
|
private byte[] signature;
|
||||||
@Nullable
|
@Nullable
|
||||||
private PubKeyRing pubKeyRing;
|
|
||||||
@Nullable
|
|
||||||
private byte[] multiSigPubKey;
|
private byte[] multiSigPubKey;
|
||||||
@Nullable
|
@Nullable
|
||||||
private List<RawTransactionInput> rawTransactionInputs;
|
private List<RawTransactionInput> rawTransactionInputs;
|
||||||
@ -134,6 +138,8 @@ public final class TradingPeer implements PersistablePayload {
|
|||||||
final protobuf.TradingPeer.Builder builder = protobuf.TradingPeer.newBuilder()
|
final protobuf.TradingPeer.Builder builder = protobuf.TradingPeer.newBuilder()
|
||||||
.setChangeOutputValue(changeOutputValue)
|
.setChangeOutputValue(changeOutputValue)
|
||||||
.addAllReserveTxKeyImages(reserveTxKeyImages);
|
.addAllReserveTxKeyImages(reserveTxKeyImages);
|
||||||
|
Optional.ofNullable(nodeAddress).ifPresent(e -> builder.setNodeAddress(nodeAddress.toProtoMessage()));
|
||||||
|
Optional.ofNullable(pubKeyRing).ifPresent(e -> builder.setPubKeyRing(pubKeyRing.toProtoMessage()));
|
||||||
Optional.ofNullable(accountId).ifPresent(builder::setAccountId);
|
Optional.ofNullable(accountId).ifPresent(builder::setAccountId);
|
||||||
Optional.ofNullable(paymentAccountId).ifPresent(builder::setPaymentAccountId);
|
Optional.ofNullable(paymentAccountId).ifPresent(builder::setPaymentAccountId);
|
||||||
Optional.ofNullable(paymentMethodId).ifPresent(builder::setPaymentMethodId);
|
Optional.ofNullable(paymentMethodId).ifPresent(builder::setPaymentMethodId);
|
||||||
@ -173,6 +179,8 @@ public final class TradingPeer implements PersistablePayload {
|
|||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
TradingPeer tradingPeer = new TradingPeer();
|
TradingPeer tradingPeer = new TradingPeer();
|
||||||
|
tradingPeer.setNodeAddress(proto.hasNodeAddress() ? NodeAddress.fromProto(proto.getNodeAddress()) : null);
|
||||||
|
tradingPeer.setPubKeyRing(proto.hasPubKeyRing() ? PubKeyRing.fromProto(proto.getPubKeyRing()) : null);
|
||||||
tradingPeer.setChangeOutputValue(proto.getChangeOutputValue());
|
tradingPeer.setChangeOutputValue(proto.getChangeOutputValue());
|
||||||
tradingPeer.setAccountId(ProtoUtil.stringOrNullFromProto(proto.getAccountId()));
|
tradingPeer.setAccountId(ProtoUtil.stringOrNullFromProto(proto.getAccountId()));
|
||||||
tradingPeer.setPaymentAccountId(ProtoUtil.stringOrNullFromProto(proto.getPaymentAccountId()));
|
tradingPeer.setPaymentAccountId(ProtoUtil.stringOrNullFromProto(proto.getPaymentAccountId()));
|
||||||
|
@ -56,14 +56,9 @@ public class ArbitratorProcessDepositRequest extends TradeTask {
|
|||||||
String signature = request.getContractSignature();
|
String signature = request.getContractSignature();
|
||||||
|
|
||||||
// get peer info
|
// get peer info
|
||||||
// TODO (woodser): make these utilities / refactor model
|
|
||||||
// TODO (woodser): verify request
|
|
||||||
PubKeyRing peerPubKeyRing;
|
|
||||||
TradingPeer peer = trade.getTradingPeer(request.getSenderNodeAddress());
|
TradingPeer peer = trade.getTradingPeer(request.getSenderNodeAddress());
|
||||||
if (peer == processModel.getArbitrator()) peerPubKeyRing = trade.getArbitratorPubKeyRing();
|
if (peer == null) throw new RuntimeException(request.getClass().getSimpleName() + " is not from maker, taker, or arbitrator");
|
||||||
else if (peer == processModel.getMaker()) peerPubKeyRing = trade.getMakerPubKeyRing();
|
PubKeyRing peerPubKeyRing = peer.getPubKeyRing();
|
||||||
else if (peer == processModel.getTaker()) peerPubKeyRing = trade.getTakerPubKeyRing();
|
|
||||||
else throw new RuntimeException(request.getClass().getSimpleName() + " is not from maker, taker, or arbitrator");
|
|
||||||
|
|
||||||
// verify signature
|
// verify signature
|
||||||
if (!Sig.verify(peerPubKeyRing.getSignaturePubKey(), contractAsJson, signature)) throw new RuntimeException("Peer's contract signature is invalid");
|
if (!Sig.verify(peerPubKeyRing.getSignaturePubKey(), contractAsJson, signature)) throw new RuntimeException("Peer's contract signature is invalid");
|
||||||
@ -73,7 +68,7 @@ public class ArbitratorProcessDepositRequest extends TradeTask {
|
|||||||
|
|
||||||
// collect expected values of deposit tx
|
// collect expected values of deposit tx
|
||||||
Offer offer = trade.getOffer();
|
Offer offer = trade.getOffer();
|
||||||
boolean isFromTaker = request.getSenderNodeAddress().equals(trade.getTakerNodeAddress());
|
boolean isFromTaker = request.getSenderNodeAddress().equals(trade.getTaker().getNodeAddress());
|
||||||
boolean isFromBuyer = isFromTaker ? offer.getDirection() == OfferDirection.SELL : offer.getDirection() == OfferDirection.BUY;
|
boolean isFromBuyer = isFromTaker ? offer.getDirection() == OfferDirection.SELL : offer.getDirection() == OfferDirection.BUY;
|
||||||
BigInteger depositAmount = ParsingUtils.coinToAtomicUnits(isFromBuyer ? offer.getBuyerSecurityDeposit() : offer.getAmount().add(offer.getSellerSecurityDeposit()));
|
BigInteger depositAmount = ParsingUtils.coinToAtomicUnits(isFromBuyer ? offer.getBuyerSecurityDeposit() : offer.getAmount().add(offer.getSellerSecurityDeposit()));
|
||||||
String depositAddress = processModel.getMultisigAddress();
|
String depositAddress = processModel.getMultisigAddress();
|
||||||
@ -121,8 +116,8 @@ public class ArbitratorProcessDepositRequest extends TradeTask {
|
|||||||
new Date().getTime());
|
new Date().getTime());
|
||||||
|
|
||||||
// send deposit response to maker and taker
|
// send deposit response to maker and taker
|
||||||
sendDepositResponse(trade.getMakerNodeAddress(), trade.getMakerPubKeyRing(), response);
|
sendDepositResponse(trade.getMaker().getNodeAddress(), trade.getMaker().getPubKeyRing(), response);
|
||||||
sendDepositResponse(trade.getTakerNodeAddress(), trade.getTakerPubKeyRing(), response);
|
sendDepositResponse(trade.getTaker().getNodeAddress(), trade.getTaker().getPubKeyRing(), response);
|
||||||
} else {
|
} else {
|
||||||
if (processModel.getMaker().getDepositTxHex() == null) log.info("Arbitrator waiting for deposit request from maker for trade " + trade.getId());
|
if (processModel.getMaker().getDepositTxHex() == null) log.info("Arbitrator waiting for deposit request from maker for trade " + trade.getId());
|
||||||
if (processModel.getTaker().getDepositTxHex() == null) log.info("Arbitrator waiting for deposit request from taker for trade " + trade.getId());
|
if (processModel.getTaker().getDepositTxHex() == null) log.info("Arbitrator waiting for deposit request from taker for trade " + trade.getId());
|
||||||
|
@ -59,11 +59,9 @@ public class ArbitratorProcessPaymentAccountKeyRequest extends TradeTask {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// send response to buyer
|
// send response to buyer
|
||||||
boolean isMakerBuyer = trade.getOffer().isBuyOffer();
|
NodeAddress buyerAddress = trade.getBuyer().getNodeAddress();
|
||||||
NodeAddress buyerAddress = isMakerBuyer ? trade.getMakerNodeAddress() : trade.getTakerNodeAddress(); // TODO: trade.getBuyer().getNodeAddress()
|
|
||||||
PubKeyRing buyerPubKeyRing = isMakerBuyer ? trade.getMakerPubKeyRing() : trade.getTakerPubKeyRing();
|
|
||||||
log.info("Arbitrator sending PaymentAccountKeyResponse to buyer={}; offerId={}", buyerAddress, trade.getId());
|
log.info("Arbitrator sending PaymentAccountKeyResponse to buyer={}; offerId={}", buyerAddress, trade.getId());
|
||||||
processModel.getP2PService().sendEncryptedDirectMessage(buyerAddress, buyerPubKeyRing, response, new SendDirectMessageListener() {
|
processModel.getP2PService().sendEncryptedDirectMessage(buyerAddress, trade.getBuyer().getPubKeyRing(), response, new SendDirectMessageListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onArrived() {
|
public void onArrived() {
|
||||||
log.info("{} arrived: trading peer={}; offerId={}; uid={}", response.getClass().getSimpleName(), buyerAddress, trade.getId());
|
log.info("{} arrived: trading peer={}; offerId={}; uid={}", response.getClass().getSimpleName(), buyerAddress, trade.getId());
|
||||||
|
@ -41,8 +41,8 @@ public class ArbitratorProcessPayoutTxPublishedMessage extends TradeTask {
|
|||||||
trade.verifyPayoutTx(request.getSignedPayoutTxHex(), false, true);
|
trade.verifyPayoutTx(request.getSignedPayoutTxHex(), false, true);
|
||||||
|
|
||||||
// update latest peer address
|
// update latest peer address
|
||||||
if (request.isMaker()) trade.setMakerNodeAddress(processModel.getTempTradingPeerNodeAddress());
|
if (request.isMaker()) trade.getMaker().setNodeAddress(processModel.getTempTradingPeerNodeAddress());
|
||||||
else trade.setTakerNodeAddress(processModel.getTempTradingPeerNodeAddress());
|
else trade.getTaker().setNodeAddress(processModel.getTempTradingPeerNodeAddress());
|
||||||
|
|
||||||
// TODO: publish signed witness data?
|
// TODO: publish signed witness data?
|
||||||
//request.getSignedWitness()
|
//request.getSignedWitness()
|
||||||
|
@ -46,7 +46,7 @@ public class ArbitratorProcessReserveTx extends TradeTask {
|
|||||||
runInterceptHook();
|
runInterceptHook();
|
||||||
Offer offer = trade.getOffer();
|
Offer offer = trade.getOffer();
|
||||||
InitTradeRequest request = (InitTradeRequest) processModel.getTradeMessage();
|
InitTradeRequest request = (InitTradeRequest) processModel.getTradeMessage();
|
||||||
boolean isFromTaker = request.getSenderNodeAddress().equals(trade.getTakerNodeAddress());
|
boolean isFromTaker = request.getSenderNodeAddress().equals(trade.getTaker().getNodeAddress());
|
||||||
boolean isFromBuyer = isFromTaker ? offer.getDirection() == OfferDirection.SELL : offer.getDirection() == OfferDirection.BUY;
|
boolean isFromBuyer = isFromTaker ? offer.getDirection() == OfferDirection.SELL : offer.getDirection() == OfferDirection.BUY;
|
||||||
|
|
||||||
// TODO (woodser): if signer online, should never be called by maker
|
// TODO (woodser): if signer online, should never be called by maker
|
||||||
|
@ -58,7 +58,7 @@ public class ArbitratorSendInitTradeOrMultisigRequests extends TradeTask {
|
|||||||
byte[] sig = Sig.sign(processModel.getKeyRing().getSignatureKeyPair().getPrivate(), processModel.getOfferId().getBytes(Charsets.UTF_8));
|
byte[] sig = Sig.sign(processModel.getKeyRing().getSignatureKeyPair().getPrivate(), processModel.getOfferId().getBytes(Charsets.UTF_8));
|
||||||
|
|
||||||
// handle request from taker
|
// handle request from taker
|
||||||
if (request.getSenderNodeAddress().equals(trade.getTakerNodeAddress())) {
|
if (request.getSenderNodeAddress().equals(trade.getTaker().getNodeAddress())) {
|
||||||
|
|
||||||
// create request to initialize trade with maker
|
// create request to initialize trade with maker
|
||||||
InitTradeRequest makerRequest = new InitTradeRequest(
|
InitTradeRequest makerRequest = new InitTradeRequest(
|
||||||
@ -75,9 +75,9 @@ public class ArbitratorSendInitTradeOrMultisigRequests extends TradeTask {
|
|||||||
Version.getP2PMessageVersion(),
|
Version.getP2PMessageVersion(),
|
||||||
sig,
|
sig,
|
||||||
new Date().getTime(),
|
new Date().getTime(),
|
||||||
trade.getMakerNodeAddress(),
|
trade.getMaker().getNodeAddress(),
|
||||||
trade.getTakerNodeAddress(),
|
trade.getTaker().getNodeAddress(),
|
||||||
trade.getArbitratorNodeAddress(),
|
trade.getArbitrator().getNodeAddress(),
|
||||||
null,
|
null,
|
||||||
null, // do not include taker's reserve tx
|
null, // do not include taker's reserve tx
|
||||||
null,
|
null,
|
||||||
@ -85,10 +85,10 @@ public class ArbitratorSendInitTradeOrMultisigRequests extends TradeTask {
|
|||||||
null);
|
null);
|
||||||
|
|
||||||
// send request to maker
|
// send request to maker
|
||||||
log.info("Send {} with offerId {} and uid {} to maker {} with pub key ring", makerRequest.getClass().getSimpleName(), makerRequest.getTradeId(), makerRequest.getUid(), trade.getMakerNodeAddress(), trade.getMakerPubKeyRing());
|
log.info("Send {} with offerId {} and uid {} to maker {} with pub key ring", makerRequest.getClass().getSimpleName(), makerRequest.getTradeId(), makerRequest.getUid(), trade.getMaker().getNodeAddress(), trade.getMaker().getPubKeyRing());
|
||||||
processModel.getP2PService().sendEncryptedDirectMessage(
|
processModel.getP2PService().sendEncryptedDirectMessage(
|
||||||
trade.getMakerNodeAddress(), // TODO (woodser): maker's address might be different from original owner address if they disconnect and reconnect, need to validate and update address when requests received
|
trade.getMaker().getNodeAddress(), // TODO (woodser): maker's address might be different from original owner address if they disconnect and reconnect, need to validate and update address when requests received
|
||||||
trade.getMakerPubKeyRing(),
|
trade.getMaker().getPubKeyRing(),
|
||||||
makerRequest,
|
makerRequest,
|
||||||
new SendDirectMessageListener() {
|
new SendDirectMessageListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -98,7 +98,7 @@ public class ArbitratorSendInitTradeOrMultisigRequests extends TradeTask {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onFault(String errorMessage) {
|
public void onFault(String errorMessage) {
|
||||||
log.error("Sending {} failed: uid={}; peer={}; error={}", makerRequest.getClass().getSimpleName(), makerRequest.getUid(), trade.getArbitratorNodeAddress(), errorMessage);
|
log.error("Sending {} failed: uid={}; peer={}; error={}", makerRequest.getClass().getSimpleName(), makerRequest.getUid(), trade.getArbitrator().getNodeAddress(), errorMessage);
|
||||||
appendToErrorMessage("Sending message failed: message=" + makerRequest + "\nerrorMessage=" + errorMessage);
|
appendToErrorMessage("Sending message failed: message=" + makerRequest + "\nerrorMessage=" + errorMessage);
|
||||||
failed();
|
failed();
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ public class ArbitratorSendInitTradeOrMultisigRequests extends TradeTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handle request from maker
|
// handle request from maker
|
||||||
else if (request.getSenderNodeAddress().equals(trade.getMakerNodeAddress())) {
|
else if (request.getSenderNodeAddress().equals(trade.getMaker().getNodeAddress())) {
|
||||||
sendInitMultisigRequests();
|
sendInitMultisigRequests();
|
||||||
complete(); // TODO: wait for InitMultisigRequest arrivals?
|
complete(); // TODO: wait for InitMultisigRequest arrivals?
|
||||||
} else {
|
} else {
|
||||||
@ -145,10 +145,10 @@ public class ArbitratorSendInitTradeOrMultisigRequests extends TradeTask {
|
|||||||
null);
|
null);
|
||||||
|
|
||||||
// send request to maker
|
// send request to maker
|
||||||
log.info("Send {} with offerId {} and uid {} to maker {}", initMultisigRequest.getClass().getSimpleName(), initMultisigRequest.getTradeId(), initMultisigRequest.getUid(), trade.getMakerNodeAddress());
|
log.info("Send {} with offerId {} and uid {} to maker {}", initMultisigRequest.getClass().getSimpleName(), initMultisigRequest.getTradeId(), initMultisigRequest.getUid(), trade.getMaker().getNodeAddress());
|
||||||
processModel.getP2PService().sendEncryptedDirectMessage(
|
processModel.getP2PService().sendEncryptedDirectMessage(
|
||||||
trade.getMakerNodeAddress(),
|
trade.getMaker().getNodeAddress(),
|
||||||
trade.getMakerPubKeyRing(),
|
trade.getMaker().getPubKeyRing(),
|
||||||
initMultisigRequest,
|
initMultisigRequest,
|
||||||
new SendDirectMessageListener() {
|
new SendDirectMessageListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -157,16 +157,16 @@ public class ArbitratorSendInitTradeOrMultisigRequests extends TradeTask {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onFault(String errorMessage) {
|
public void onFault(String errorMessage) {
|
||||||
log.error("Sending {} failed: uid={}; peer={}; error={}", initMultisigRequest.getClass().getSimpleName(), initMultisigRequest.getUid(), trade.getMakerNodeAddress(), errorMessage);
|
log.error("Sending {} failed: uid={}; peer={}; error={}", initMultisigRequest.getClass().getSimpleName(), initMultisigRequest.getUid(), trade.getMaker().getNodeAddress(), errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// send request to taker
|
// send request to taker
|
||||||
log.info("Send {} with offerId {} and uid {} to taker {}", initMultisigRequest.getClass().getSimpleName(), initMultisigRequest.getTradeId(), initMultisigRequest.getUid(), trade.getTakerNodeAddress());
|
log.info("Send {} with offerId {} and uid {} to taker {}", initMultisigRequest.getClass().getSimpleName(), initMultisigRequest.getTradeId(), initMultisigRequest.getUid(), trade.getTaker().getNodeAddress());
|
||||||
processModel.getP2PService().sendEncryptedDirectMessage(
|
processModel.getP2PService().sendEncryptedDirectMessage(
|
||||||
trade.getTakerNodeAddress(),
|
trade.getTaker().getNodeAddress(),
|
||||||
trade.getTakerPubKeyRing(),
|
trade.getTaker().getPubKeyRing(),
|
||||||
initMultisigRequest,
|
initMultisigRequest,
|
||||||
new SendDirectMessageListener() {
|
new SendDirectMessageListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -175,7 +175,7 @@ public class ArbitratorSendInitTradeOrMultisigRequests extends TradeTask {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onFault(String errorMessage) {
|
public void onFault(String errorMessage) {
|
||||||
log.error("Sending {} failed: uid={}; peer={}; error={}", initMultisigRequest.getClass().getSimpleName(), initMultisigRequest.getUid(), trade.getTakerNodeAddress(), errorMessage);
|
log.error("Sending {} failed: uid={}; peer={}; error={}", initMultisigRequest.getClass().getSimpleName(), initMultisigRequest.getUid(), trade.getTaker().getNodeAddress(), errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -37,8 +37,8 @@ public class BuyerProcessPaymentAccountKeyResponse extends TradeTask {
|
|||||||
runInterceptHook();
|
runInterceptHook();
|
||||||
|
|
||||||
// update peer node address if not from arbitrator
|
// update peer node address if not from arbitrator
|
||||||
if (!processModel.getTempTradingPeerNodeAddress().equals(trade.getArbitratorNodeAddress())) {
|
if (!processModel.getTempTradingPeerNodeAddress().equals(trade.getArbitrator().getNodeAddress())) {
|
||||||
trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
|
trade.getTradingPeer().setNodeAddress(processModel.getTempTradingPeerNodeAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
// decrypt peer's payment account payload
|
// decrypt peer's payment account payload
|
||||||
|
@ -53,7 +53,7 @@ public class BuyerProcessPaymentReceivedMessage extends TradeTask {
|
|||||||
checkArgument(message.getPayoutTxHex() != null);
|
checkArgument(message.getPayoutTxHex() != null);
|
||||||
|
|
||||||
// update to the latest peer address of our peer if the message is correct
|
// update to the latest peer address of our peer if the message is correct
|
||||||
trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
|
trade.getTradingPeer().setNodeAddress(processModel.getTempTradingPeerNodeAddress());
|
||||||
|
|
||||||
// handle if payout tx is not seen on network
|
// handle if payout tx is not seen on network
|
||||||
if (trade.getPhase().ordinal() < Trade.Phase.PAYOUT_PUBLISHED.ordinal()) {
|
if (trade.getPhase().ordinal() < Trade.Phase.PAYOUT_PUBLISHED.ordinal()) {
|
||||||
|
@ -49,10 +49,10 @@ public class BuyerSendPaymentAccountKeyRequestToArbitrator extends TradeTask {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// send request to arbitrator
|
// send request to arbitrator
|
||||||
log.info("Sending {} with offerId {} and uid {} to arbitrator {} with pub key ring {}", request.getClass().getSimpleName(), request.getTradeId(), request.getUid(), trade.getArbitratorNodeAddress(), trade.getArbitratorPubKeyRing());
|
log.info("Sending {} with offerId {} and uid {} to arbitrator {} with pub key ring {}", request.getClass().getSimpleName(), request.getTradeId(), request.getUid(), trade.getArbitrator().getNodeAddress(), trade.getArbitrator().getPubKeyRing());
|
||||||
processModel.getP2PService().sendEncryptedDirectMessage(
|
processModel.getP2PService().sendEncryptedDirectMessage(
|
||||||
trade.getArbitratorNodeAddress(),
|
trade.getArbitrator().getNodeAddress(),
|
||||||
trade.getArbitratorPubKeyRing(),
|
trade.getArbitrator().getPubKeyRing(),
|
||||||
request,
|
request,
|
||||||
new SendDirectMessageListener() {
|
new SendDirectMessageListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -40,12 +40,12 @@ public class BuyerSendPayoutTxPublishedMessage extends SendMailboxMessageTask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NodeAddress getReceiverNodeAddress() {
|
protected NodeAddress getReceiverNodeAddress() {
|
||||||
return trade.getArbitratorNodeAddress();
|
return trade.getArbitrator().getNodeAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected PubKeyRing getReceiverPubKeyRing() {
|
protected PubKeyRing getReceiverPubKeyRing() {
|
||||||
return trade.getArbitratorPubKeyRing();
|
return trade.getArbitrator().getPubKeyRing();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -72,9 +72,9 @@ public class MakerSendInitTradeRequest extends TradeTask {
|
|||||||
Version.getP2PMessageVersion(),
|
Version.getP2PMessageVersion(),
|
||||||
sig,
|
sig,
|
||||||
makerRequest.getCurrentDate(),
|
makerRequest.getCurrentDate(),
|
||||||
trade.getMakerNodeAddress(),
|
trade.getMaker().getNodeAddress(),
|
||||||
trade.getTakerNodeAddress(),
|
trade.getTaker().getNodeAddress(),
|
||||||
trade.getArbitratorNodeAddress(),
|
trade.getArbitrator().getNodeAddress(),
|
||||||
trade.getSelf().getReserveTxHash(),
|
trade.getSelf().getReserveTxHash(),
|
||||||
trade.getSelf().getReserveTxHex(),
|
trade.getSelf().getReserveTxHex(),
|
||||||
trade.getSelf().getReserveTxKey(),
|
trade.getSelf().getReserveTxKey(),
|
||||||
@ -82,10 +82,10 @@ public class MakerSendInitTradeRequest extends TradeTask {
|
|||||||
null);
|
null);
|
||||||
|
|
||||||
// send request to arbitrator
|
// send request to arbitrator
|
||||||
log.info("Sending {} with offerId {} and uid {} to arbitrator {} with pub key ring {}", arbitratorRequest.getClass().getSimpleName(), arbitratorRequest.getTradeId(), arbitratorRequest.getUid(), trade.getArbitratorNodeAddress(), trade.getArbitratorPubKeyRing());
|
log.info("Sending {} with offerId {} and uid {} to arbitrator {} with pub key ring {}", arbitratorRequest.getClass().getSimpleName(), arbitratorRequest.getTradeId(), arbitratorRequest.getUid(), trade.getArbitrator().getNodeAddress(), trade.getArbitrator().getPubKeyRing());
|
||||||
processModel.getP2PService().sendEncryptedDirectMessage(
|
processModel.getP2PService().sendEncryptedDirectMessage(
|
||||||
trade.getArbitratorNodeAddress(),
|
trade.getArbitrator().getNodeAddress(),
|
||||||
trade.getArbitratorPubKeyRing(),
|
trade.getArbitrator().getPubKeyRing(),
|
||||||
arbitratorRequest,
|
arbitratorRequest,
|
||||||
new SendDirectMessageListener() {
|
new SendDirectMessageListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -97,32 +97,32 @@ public class MaybeSendSignContractRequest extends TradeTask {
|
|||||||
depositTx.getHash());
|
depositTx.getHash());
|
||||||
|
|
||||||
// send request to trading peer
|
// send request to trading peer
|
||||||
processModel.getP2PService().sendEncryptedDirectMessage(trade.getTradingPeerNodeAddress(), trade.getTradingPeerPubKeyRing(), request, new SendDirectMessageListener() {
|
processModel.getP2PService().sendEncryptedDirectMessage(trade.getTradingPeer().getNodeAddress(), trade.getTradingPeer().getPubKeyRing(), request, new SendDirectMessageListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onArrived() {
|
public void onArrived() {
|
||||||
log.info("{} arrived: trading peer={}; offerId={}; uid={}", request.getClass().getSimpleName(), trade.getTradingPeerNodeAddress(), trade.getId());
|
log.info("{} arrived: trading peer={}; offerId={}; uid={}", request.getClass().getSimpleName(), trade.getTradingPeer().getNodeAddress(), trade.getId());
|
||||||
ack1 = true;
|
ack1 = true;
|
||||||
if (ack1 && ack2) completeAux();
|
if (ack1 && ack2) completeAux();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onFault(String errorMessage) {
|
public void onFault(String errorMessage) {
|
||||||
log.error("Sending {} failed: uid={}; peer={}; error={}", request.getClass().getSimpleName(), trade.getTradingPeerNodeAddress(), trade.getId(), errorMessage);
|
log.error("Sending {} failed: uid={}; peer={}; error={}", request.getClass().getSimpleName(), trade.getTradingPeer().getNodeAddress(), trade.getId(), errorMessage);
|
||||||
appendToErrorMessage("Sending message failed: message=" + request + "\nerrorMessage=" + errorMessage);
|
appendToErrorMessage("Sending message failed: message=" + request + "\nerrorMessage=" + errorMessage);
|
||||||
failed();
|
failed();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// send request to arbitrator
|
// send request to arbitrator
|
||||||
processModel.getP2PService().sendEncryptedDirectMessage(trade.getArbitratorNodeAddress(), trade.getArbitratorPubKeyRing(), request, new SendDirectMessageListener() {
|
processModel.getP2PService().sendEncryptedDirectMessage(trade.getArbitrator().getNodeAddress(), trade.getArbitrator().getPubKeyRing(), request, new SendDirectMessageListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onArrived() {
|
public void onArrived() {
|
||||||
log.info("{} arrived: trading peer={}; offerId={}; uid={}", request.getClass().getSimpleName(), trade.getArbitratorNodeAddress(), trade.getId());
|
log.info("{} arrived: trading peer={}; offerId={}; uid={}", request.getClass().getSimpleName(), trade.getArbitrator().getNodeAddress(), trade.getId());
|
||||||
ack2 = true;
|
ack2 = true;
|
||||||
if (ack1 && ack2) completeAux();
|
if (ack1 && ack2) completeAux();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onFault(String errorMessage) {
|
public void onFault(String errorMessage) {
|
||||||
log.error("Sending {} failed: uid={}; peer={}; error={}", request.getClass().getSimpleName(), trade.getArbitratorNodeAddress(), trade.getId(), errorMessage);
|
log.error("Sending {} failed: uid={}; peer={}; error={}", request.getClass().getSimpleName(), trade.getArbitrator().getNodeAddress(), trade.getId(), errorMessage);
|
||||||
appendToErrorMessage("Sending message failed: message=" + request + "\nerrorMessage=" + errorMessage);
|
appendToErrorMessage("Sending message failed: message=" + request + "\nerrorMessage=" + errorMessage);
|
||||||
failed();
|
failed();
|
||||||
}
|
}
|
||||||
|
@ -73,9 +73,9 @@ public class ProcessInitMultisigRequest extends TradeTask {
|
|||||||
|
|
||||||
// get peer multisig participant
|
// get peer multisig participant
|
||||||
TradingPeer multisigParticipant;
|
TradingPeer multisigParticipant;
|
||||||
if (request.getSenderNodeAddress().equals(trade.getMakerNodeAddress())) multisigParticipant = processModel.getMaker();
|
if (request.getSenderNodeAddress().equals(trade.getMaker().getNodeAddress())) multisigParticipant = processModel.getMaker();
|
||||||
else if (request.getSenderNodeAddress().equals(trade.getTakerNodeAddress())) multisigParticipant = processModel.getTaker();
|
else if (request.getSenderNodeAddress().equals(trade.getTaker().getNodeAddress())) multisigParticipant = processModel.getTaker();
|
||||||
else if (request.getSenderNodeAddress().equals(trade.getArbitratorNodeAddress())) multisigParticipant = processModel.getArbitrator();
|
else if (request.getSenderNodeAddress().equals(trade.getArbitrator().getNodeAddress())) multisigParticipant = processModel.getArbitrator();
|
||||||
else throw new RuntimeException("Invalid sender to process init trade message: " + trade.getClass().getName());
|
else throw new RuntimeException("Invalid sender to process init trade message: " + trade.getClass().getName());
|
||||||
|
|
||||||
// reconcile peer's established multisig hex with message
|
// reconcile peer's established multisig hex with message
|
||||||
@ -135,20 +135,20 @@ public class ProcessInitMultisigRequest extends TradeTask {
|
|||||||
NodeAddress peer2Address;
|
NodeAddress peer2Address;
|
||||||
PubKeyRing peer2PubKeyRing;
|
PubKeyRing peer2PubKeyRing;
|
||||||
if (trade instanceof ArbitratorTrade) {
|
if (trade instanceof ArbitratorTrade) {
|
||||||
peer1Address = trade.getTakerNodeAddress();
|
peer1Address = trade.getTaker().getNodeAddress();
|
||||||
peer1PubKeyRing = trade.getTakerPubKeyRing();
|
peer1PubKeyRing = trade.getTaker().getPubKeyRing();
|
||||||
peer2Address = trade.getMakerNodeAddress();
|
peer2Address = trade.getMaker().getNodeAddress();
|
||||||
peer2PubKeyRing = trade.getMakerPubKeyRing();
|
peer2PubKeyRing = trade.getMaker().getPubKeyRing();
|
||||||
} else if (trade instanceof MakerTrade) {
|
} else if (trade instanceof MakerTrade) {
|
||||||
peer1Address = trade.getTakerNodeAddress();
|
peer1Address = trade.getTaker().getNodeAddress();
|
||||||
peer1PubKeyRing = trade.getTakerPubKeyRing();
|
peer1PubKeyRing = trade.getTaker().getPubKeyRing();
|
||||||
peer2Address = trade.getArbitratorNodeAddress();
|
peer2Address = trade.getArbitrator().getNodeAddress();
|
||||||
peer2PubKeyRing = trade.getArbitratorPubKeyRing();
|
peer2PubKeyRing = trade.getArbitrator().getPubKeyRing();
|
||||||
} else {
|
} else {
|
||||||
peer1Address = trade.getMakerNodeAddress();
|
peer1Address = trade.getMaker().getNodeAddress();
|
||||||
peer1PubKeyRing = trade.getMakerPubKeyRing();
|
peer1PubKeyRing = trade.getMaker().getPubKeyRing();
|
||||||
peer2Address = trade.getArbitratorNodeAddress();
|
peer2Address = trade.getArbitrator().getNodeAddress();
|
||||||
peer2PubKeyRing = trade.getArbitratorPubKeyRing();
|
peer2PubKeyRing = trade.getArbitrator().getPubKeyRing();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (peer1Address == null) throw new RuntimeException("Peer1 address is null");
|
if (peer1Address == null) throw new RuntimeException("Peer1 address is null");
|
||||||
|
@ -61,16 +61,16 @@ public class ProcessInitTradeRequest extends TradeTask {
|
|||||||
// handle request as arbitrator
|
// handle request as arbitrator
|
||||||
TradingPeer multisigParticipant;
|
TradingPeer multisigParticipant;
|
||||||
if (trade instanceof ArbitratorTrade) {
|
if (trade instanceof ArbitratorTrade) {
|
||||||
trade.setMakerPubKeyRing((trade.getOffer().getPubKeyRing()));
|
trade.getMaker().setPubKeyRing((trade.getOffer().getPubKeyRing()));
|
||||||
trade.setArbitratorPubKeyRing(processModel.getPubKeyRing());
|
trade.getArbitrator().setPubKeyRing(processModel.getPubKeyRing());
|
||||||
processModel.getArbitrator().setPubKeyRing(processModel.getPubKeyRing()); // TODO (woodser): why duplicating field in process model
|
processModel.getArbitrator().setPubKeyRing(processModel.getPubKeyRing()); // TODO (woodser): why duplicating field in process model
|
||||||
|
|
||||||
// handle request from taker
|
// handle request from taker
|
||||||
if (request.getSenderNodeAddress().equals(request.getTakerNodeAddress())) {
|
if (request.getSenderNodeAddress().equals(request.getTakerNodeAddress())) {
|
||||||
multisigParticipant = processModel.getTaker();
|
multisigParticipant = processModel.getTaker();
|
||||||
if (!trade.getTakerNodeAddress().equals(request.getTakerNodeAddress())) throw new RuntimeException("Init trade requests from maker and taker do not agree");
|
if (!trade.getTaker().getNodeAddress().equals(request.getTakerNodeAddress())) throw new RuntimeException("Init trade requests from maker and taker do not agree");
|
||||||
if (trade.getTakerPubKeyRing() != null) throw new RuntimeException("Pub key ring should not be initialized before processing InitTradeRequest");
|
if (trade.getTaker().getPubKeyRing() != null) throw new RuntimeException("Pub key ring should not be initialized before processing InitTradeRequest");
|
||||||
trade.setTakerPubKeyRing(request.getPubKeyRing());
|
trade.getTaker().setPubKeyRing(request.getPubKeyRing());
|
||||||
if (!TradeUtils.isMakerSignatureValid(request, request.getMakerSignature(), offer.getPubKeyRing())) throw new RuntimeException("Maker signature is invalid for the trade request"); // verify maker signature
|
if (!TradeUtils.isMakerSignatureValid(request, request.getMakerSignature(), offer.getPubKeyRing())) throw new RuntimeException("Maker signature is invalid for the trade request"); // verify maker signature
|
||||||
|
|
||||||
// check trade price
|
// check trade price
|
||||||
@ -88,10 +88,10 @@ public class ProcessInitTradeRequest extends TradeTask {
|
|||||||
// handle request from maker
|
// handle request from maker
|
||||||
else if (request.getSenderNodeAddress().equals(request.getMakerNodeAddress())) {
|
else if (request.getSenderNodeAddress().equals(request.getMakerNodeAddress())) {
|
||||||
multisigParticipant = processModel.getMaker();
|
multisigParticipant = processModel.getMaker();
|
||||||
if (!trade.getMakerNodeAddress().equals(request.getMakerNodeAddress())) throw new RuntimeException("Init trade requests from maker and taker do not agree"); // TODO (woodser): test when maker and taker do not agree, use proper handling, uninitialize trade for other takers
|
if (!trade.getMaker().getNodeAddress().equals(request.getMakerNodeAddress())) throw new RuntimeException("Init trade requests from maker and taker do not agree"); // TODO (woodser): test when maker and taker do not agree, use proper handling, uninitialize trade for other takers
|
||||||
if (trade.getMakerPubKeyRing() == null) trade.setMakerPubKeyRing(request.getPubKeyRing());
|
if (trade.getMaker().getPubKeyRing() == null) trade.getMaker().setPubKeyRing(request.getPubKeyRing());
|
||||||
else if (!trade.getMakerPubKeyRing().equals(request.getPubKeyRing())) throw new RuntimeException("Init trade requests from maker and taker do not agree"); // TODO (woodser): proper handling
|
else if (!trade.getMaker().getPubKeyRing().equals(request.getPubKeyRing())) throw new RuntimeException("Init trade requests from maker and taker do not agree"); // TODO (woodser): proper handling
|
||||||
trade.setMakerPubKeyRing(request.getPubKeyRing());
|
trade.getMaker().setPubKeyRing(request.getPubKeyRing());
|
||||||
if (trade.getPrice().getValue() != request.getTradePrice()) throw new RuntimeException("Maker and taker price do not agree");
|
if (trade.getPrice().getValue() != request.getTradePrice()) throw new RuntimeException("Maker and taker price do not agree");
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Sender is not trade's maker or taker");
|
throw new RuntimeException("Sender is not trade's maker or taker");
|
||||||
@ -101,8 +101,8 @@ public class ProcessInitTradeRequest extends TradeTask {
|
|||||||
// handle maker trade
|
// handle maker trade
|
||||||
else if (trade instanceof MakerTrade) {
|
else if (trade instanceof MakerTrade) {
|
||||||
multisigParticipant = processModel.getTaker();
|
multisigParticipant = processModel.getTaker();
|
||||||
trade.setTakerNodeAddress(request.getSenderNodeAddress()); // arbitrator sends maker InitTradeRequest with taker's node address and pub key ring
|
trade.getTaker().setNodeAddress(request.getSenderNodeAddress()); // arbitrator sends maker InitTradeRequest with taker's node address and pub key ring
|
||||||
trade.setTakerPubKeyRing(request.getPubKeyRing());
|
trade.getTaker().setPubKeyRing(request.getPubKeyRing());
|
||||||
|
|
||||||
// check trade price
|
// check trade price
|
||||||
try {
|
try {
|
||||||
|
@ -112,10 +112,10 @@ public class ProcessSignContractRequest extends TradeTask {
|
|||||||
encryptedPaymentAccountPayload);
|
encryptedPaymentAccountPayload);
|
||||||
|
|
||||||
// get response recipients. only arbitrator sends response to both peers
|
// get response recipients. only arbitrator sends response to both peers
|
||||||
NodeAddress recipient1 = trade instanceof ArbitratorTrade ? trade.getMakerNodeAddress() : trade.getTradingPeerNodeAddress();
|
NodeAddress recipient1 = trade instanceof ArbitratorTrade ? trade.getMaker().getNodeAddress() : trade.getTradingPeer().getNodeAddress();
|
||||||
PubKeyRing recipient1PubKey = trade instanceof ArbitratorTrade ? trade.getMakerPubKeyRing() : trade.getTradingPeerPubKeyRing();
|
PubKeyRing recipient1PubKey = trade instanceof ArbitratorTrade ? trade.getMaker().getPubKeyRing() : trade.getTradingPeer().getPubKeyRing();
|
||||||
NodeAddress recipient2 = trade instanceof ArbitratorTrade ? trade.getTakerNodeAddress() : null;
|
NodeAddress recipient2 = trade instanceof ArbitratorTrade ? trade.getTaker().getNodeAddress() : null;
|
||||||
PubKeyRing recipient2PubKey = trade instanceof ArbitratorTrade ? trade.getTakerPubKeyRing() : null;
|
PubKeyRing recipient2PubKey = trade instanceof ArbitratorTrade ? trade.getTaker().getPubKeyRing() : null;
|
||||||
|
|
||||||
// send response to recipient 1
|
// send response to recipient 1
|
||||||
processModel.getP2PService().sendEncryptedDirectMessage(recipient1, recipient1PubKey, response, new SendDirectMessageListener() {
|
processModel.getP2PService().sendEncryptedDirectMessage(recipient1, recipient1PubKey, response, new SendDirectMessageListener() {
|
||||||
|
@ -54,13 +54,8 @@ public class ProcessSignContractResponse extends TradeTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get peer info
|
// get peer info
|
||||||
// TODO (woodser): make these utilities / refactor model
|
|
||||||
PubKeyRing peerPubKeyRing;
|
|
||||||
TradingPeer peer = trade.getTradingPeer(response.getSenderNodeAddress());
|
TradingPeer peer = trade.getTradingPeer(response.getSenderNodeAddress());
|
||||||
if (peer == processModel.getArbitrator()) peerPubKeyRing = trade.getArbitratorPubKeyRing();
|
PubKeyRing peerPubKeyRing = peer.getPubKeyRing();
|
||||||
else if (peer == processModel.getMaker()) peerPubKeyRing = trade.getMakerPubKeyRing();
|
|
||||||
else if (peer == processModel.getTaker()) peerPubKeyRing = trade.getTakerPubKeyRing();
|
|
||||||
else throw new RuntimeException(response.getClass().getSimpleName() + " is not from maker, taker, or arbitrator");
|
|
||||||
|
|
||||||
// save peer's encrypted payment account payload
|
// save peer's encrypted payment account payload
|
||||||
peer.setEncryptedPaymentAccountPayload(response.getEncryptedPaymentAccountPayload());
|
peer.setEncryptedPaymentAccountPayload(response.getEncryptedPaymentAccountPayload());
|
||||||
@ -94,18 +89,18 @@ public class ProcessSignContractResponse extends TradeTask {
|
|||||||
trade.getSelf().getPaymentAccountKey());
|
trade.getSelf().getPaymentAccountKey());
|
||||||
|
|
||||||
// send request to arbitrator
|
// send request to arbitrator
|
||||||
log.info("Sending {} to arbitrator {}; offerId={}; uid={}", request.getClass().getSimpleName(), trade.getArbitratorNodeAddress(), trade.getId(), request.getUid());
|
log.info("Sending {} to arbitrator {}; offerId={}; uid={}", request.getClass().getSimpleName(), trade.getArbitrator().getNodeAddress(), trade.getId(), request.getUid());
|
||||||
processModel.getP2PService().sendEncryptedDirectMessage(trade.getArbitratorNodeAddress(), trade.getArbitratorPubKeyRing(), request, new SendDirectMessageListener() {
|
processModel.getP2PService().sendEncryptedDirectMessage(trade.getArbitrator().getNodeAddress(), trade.getArbitrator().getPubKeyRing(), request, new SendDirectMessageListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onArrived() {
|
public void onArrived() {
|
||||||
log.info("{} arrived: arbitrator={}; offerId={}; uid={}", request.getClass().getSimpleName(), trade.getArbitratorNodeAddress(), trade.getId(), request.getUid());
|
log.info("{} arrived: arbitrator={}; offerId={}; uid={}", request.getClass().getSimpleName(), trade.getArbitrator().getNodeAddress(), trade.getId(), request.getUid());
|
||||||
trade.setStateIfValidTransitionTo(Trade.State.SAW_ARRIVED_PUBLISH_DEPOSIT_TX_REQUEST);
|
trade.setStateIfValidTransitionTo(Trade.State.SAW_ARRIVED_PUBLISH_DEPOSIT_TX_REQUEST);
|
||||||
processModel.getTradeManager().requestPersistence();
|
processModel.getTradeManager().requestPersistence();
|
||||||
complete();
|
complete();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onFault(String errorMessage) {
|
public void onFault(String errorMessage) {
|
||||||
log.error("Sending {} failed: uid={}; peer={}; error={}", request.getClass().getSimpleName(), trade.getArbitratorNodeAddress(), trade.getId(), errorMessage);
|
log.error("Sending {} failed: uid={}; peer={}; error={}", request.getClass().getSimpleName(), trade.getArbitrator().getNodeAddress(), trade.getId(), errorMessage);
|
||||||
appendToErrorMessage("Sending message failed: message=" + request + "\nerrorMessage=" + errorMessage);
|
appendToErrorMessage("Sending message failed: message=" + request + "\nerrorMessage=" + errorMessage);
|
||||||
failed();
|
failed();
|
||||||
}
|
}
|
||||||
|
@ -88,8 +88,8 @@ public class ProcessUpdateMultisigRequest extends TradeTask {
|
|||||||
new Date().getTime(),
|
new Date().getTime(),
|
||||||
updatedMultisigHex);
|
updatedMultisigHex);
|
||||||
|
|
||||||
log.info("Send {} with offerId {} and uid {} to peer {}", response.getClass().getSimpleName(), response.getTradeId(), response.getUid(), trade.getTradingPeerNodeAddress());
|
log.info("Send {} with offerId {} and uid {} to peer {}", response.getClass().getSimpleName(), response.getTradeId(), response.getUid(), trade.getTradingPeer().getNodeAddress());
|
||||||
processModel.getP2PService().sendEncryptedDirectMessage(trade.getTradingPeerNodeAddress(), trade.getTradingPeerPubKeyRing(), response, new SendDirectMessageListener() {
|
processModel.getP2PService().sendEncryptedDirectMessage(trade.getTradingPeer().getNodeAddress(), trade.getTradingPeer().getPubKeyRing(), response, new SendDirectMessageListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onArrived() {
|
public void onArrived() {
|
||||||
log.info("{} arrived at trading peer: offerId={}; uid={}", response.getClass().getSimpleName(), response.getTradeId(), response.getUid());
|
log.info("{} arrived at trading peer: offerId={}; uid={}", response.getClass().getSimpleName(), response.getTradeId(), response.getUid());
|
||||||
@ -97,7 +97,7 @@ public class ProcessUpdateMultisigRequest extends TradeTask {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onFault(String errorMessage) {
|
public void onFault(String errorMessage) {
|
||||||
log.error("Sending {} failed: uid={}; peer={}; error={}", response.getClass().getSimpleName(), response.getUid(), trade.getArbitratorNodeAddress(), errorMessage);
|
log.error("Sending {} failed: uid={}; peer={}; error={}", response.getClass().getSimpleName(), response.getUid(), trade.getArbitrator().getNodeAddress(), errorMessage);
|
||||||
appendToErrorMessage("Sending response failed: response=" + response + "\nerrorMessage=" + errorMessage);
|
appendToErrorMessage("Sending response failed: response=" + response + "\nerrorMessage=" + errorMessage);
|
||||||
failed();
|
failed();
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ public class PublishTradeStatistics extends TradeTask {
|
|||||||
extraDataMap.put(OfferPayload.REFERRAL_ID, processModel.getReferralIdService().getOptionalReferralId().get());
|
extraDataMap.put(OfferPayload.REFERRAL_ID, processModel.getReferralIdService().getOptionalReferralId().get());
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeAddress mediatorNodeAddress = checkNotNull(trade.getArbitratorNodeAddress());
|
NodeAddress mediatorNodeAddress = checkNotNull(trade.getArbitrator().getNodeAddress());
|
||||||
// The first 4 chars are sufficient to identify a mediator.
|
// The first 4 chars are sufficient to identify a mediator.
|
||||||
// For testing with regtest/localhost we use the full address as its localhost and would result in
|
// For testing with regtest/localhost we use the full address as its localhost and would result in
|
||||||
// same values for multiple mediators.
|
// same values for multiple mediators.
|
||||||
|
@ -55,12 +55,12 @@ public class SellerMaybeSendPayoutTxPublishedMessage extends SendMailboxMessageT
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NodeAddress getReceiverNodeAddress() {
|
protected NodeAddress getReceiverNodeAddress() {
|
||||||
return trade.getArbitratorNodeAddress();
|
return trade.getArbitrator().getNodeAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected PubKeyRing getReceiverPubKeyRing() {
|
protected PubKeyRing getReceiverPubKeyRing() {
|
||||||
return trade.getArbitratorPubKeyRing();
|
return trade.getArbitrator().getPubKeyRing();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -58,7 +58,7 @@ public class SellerProcessPaymentSentMessage extends TradeTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update latest peer address
|
// update latest peer address
|
||||||
trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
|
trade.getTradingPeer().setNodeAddress(processModel.getTempTradingPeerNodeAddress());
|
||||||
|
|
||||||
String counterCurrencyTxId = message.getCounterCurrencyTxId();
|
String counterCurrencyTxId = message.getCounterCurrencyTxId();
|
||||||
if (counterCurrencyTxId != null && counterCurrencyTxId.length() < 100) {
|
if (counterCurrencyTxId != null && counterCurrencyTxId.length() < 100) {
|
||||||
|
@ -36,7 +36,7 @@ public class SellerPublishTradeStatistics extends TradeTask {
|
|||||||
//
|
//
|
||||||
// checkNotNull(trade.getDepositTx());
|
// checkNotNull(trade.getDepositTx());
|
||||||
//
|
//
|
||||||
// processModel.getP2PService().findPeersCapabilities(trade.getTradingPeerNodeAddress())
|
// processModel.getP2PService().findPeersCapabilities(trade.getTradingPeer().getNodeAddress())
|
||||||
// .filter(capabilities -> capabilities.containsAll(Capability.TRADE_STATISTICS_3))
|
// .filter(capabilities -> capabilities.containsAll(Capability.TRADE_STATISTICS_3))
|
||||||
// .ifPresentOrElse(capabilities -> {
|
// .ifPresentOrElse(capabilities -> {
|
||||||
// // Our peer has updated, so as we are the seller we will publish the trade statistics.
|
// // Our peer has updated, so as we are the seller we will publish the trade statistics.
|
||||||
|
@ -71,7 +71,7 @@ public class SellerSendPaymentReceivedMessage extends SendMailboxMessageTask {
|
|||||||
protected void setStateSent() {
|
protected void setStateSent() {
|
||||||
trade.setState(trade.getState().ordinal() >= Trade.State.SELLER_PUBLISHED_PAYOUT_TX.ordinal() ? Trade.State.SELLER_SENT_PAYOUT_TX_PUBLISHED_MSG : Trade.State.SELLER_SENT_PAYMENT_RECEIVED_MSG);
|
trade.setState(trade.getState().ordinal() >= Trade.State.SELLER_PUBLISHED_PAYOUT_TX.ordinal() ? Trade.State.SELLER_SENT_PAYOUT_TX_PUBLISHED_MSG : Trade.State.SELLER_SENT_PAYMENT_RECEIVED_MSG);
|
||||||
log.info("Sent SellerReceivedPaymentMessage: tradeId={} at peer {} SignedWitness {}",
|
log.info("Sent SellerReceivedPaymentMessage: tradeId={} at peer {} SignedWitness {}",
|
||||||
trade.getId(), trade.getTradingPeerNodeAddress(), signedWitness);
|
trade.getId(), trade.getTradingPeer().getNodeAddress(), signedWitness);
|
||||||
processModel.getTradeManager().requestPersistence();
|
processModel.getTradeManager().requestPersistence();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ public class SellerSendPaymentReceivedMessage extends SendMailboxMessageTask {
|
|||||||
protected void setStateArrived() {
|
protected void setStateArrived() {
|
||||||
trade.setState(trade.getState().ordinal() >= Trade.State.SELLER_PUBLISHED_PAYOUT_TX.ordinal() ? Trade.State.SELLER_SAW_ARRIVED_PAYOUT_TX_PUBLISHED_MSG : Trade.State.SELLER_SAW_ARRIVED_PAYMENT_RECEIVED_MSG);
|
trade.setState(trade.getState().ordinal() >= Trade.State.SELLER_PUBLISHED_PAYOUT_TX.ordinal() ? Trade.State.SELLER_SAW_ARRIVED_PAYOUT_TX_PUBLISHED_MSG : Trade.State.SELLER_SAW_ARRIVED_PAYMENT_RECEIVED_MSG);
|
||||||
log.info("Seller's PaymentReceivedMessage arrived: tradeId={} at peer {} SignedWitness {}",
|
log.info("Seller's PaymentReceivedMessage arrived: tradeId={} at peer {} SignedWitness {}",
|
||||||
trade.getId(), trade.getTradingPeerNodeAddress(), signedWitness);
|
trade.getId(), trade.getTradingPeer().getNodeAddress(), signedWitness);
|
||||||
processModel.getTradeManager().requestPersistence();
|
processModel.getTradeManager().requestPersistence();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ public class SellerSendPaymentReceivedMessage extends SendMailboxMessageTask {
|
|||||||
protected void setStateStoredInMailbox() {
|
protected void setStateStoredInMailbox() {
|
||||||
trade.setState(trade.getState().ordinal() >= Trade.State.SELLER_PUBLISHED_PAYOUT_TX.ordinal() ? Trade.State.SELLER_STORED_IN_MAILBOX_PAYOUT_TX_PUBLISHED_MSG : Trade.State.SELLER_STORED_IN_MAILBOX_PAYMENT_RECEIVED_MSG);
|
trade.setState(trade.getState().ordinal() >= Trade.State.SELLER_PUBLISHED_PAYOUT_TX.ordinal() ? Trade.State.SELLER_STORED_IN_MAILBOX_PAYOUT_TX_PUBLISHED_MSG : Trade.State.SELLER_STORED_IN_MAILBOX_PAYMENT_RECEIVED_MSG);
|
||||||
log.info("Seller's PaymentReceivedMessage stored in mailbox: tradeId={} at peer {} SignedWitness {}",
|
log.info("Seller's PaymentReceivedMessage stored in mailbox: tradeId={} at peer {} SignedWitness {}",
|
||||||
trade.getId(), trade.getTradingPeerNodeAddress(), signedWitness);
|
trade.getId(), trade.getTradingPeer().getNodeAddress(), signedWitness);
|
||||||
processModel.getTradeManager().requestPersistence();
|
processModel.getTradeManager().requestPersistence();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ public class SellerSendPaymentReceivedMessage extends SendMailboxMessageTask {
|
|||||||
protected void setStateFault() {
|
protected void setStateFault() {
|
||||||
trade.setState(trade.getState().ordinal() >= Trade.State.SELLER_PUBLISHED_PAYOUT_TX.ordinal() ? Trade.State.SELLER_SEND_FAILED_PAYOUT_TX_PUBLISHED_MSG : Trade.State.SELLER_SEND_FAILED_PAYMENT_RECEIVED_MSG);
|
trade.setState(trade.getState().ordinal() >= Trade.State.SELLER_PUBLISHED_PAYOUT_TX.ordinal() ? Trade.State.SELLER_SEND_FAILED_PAYOUT_TX_PUBLISHED_MSG : Trade.State.SELLER_SEND_FAILED_PAYMENT_RECEIVED_MSG);
|
||||||
log.error("SellerReceivedPaymentMessage failed: tradeId={} at peer {} SignedWitness {}",
|
log.error("SellerReceivedPaymentMessage failed: tradeId={} at peer {} SignedWitness {}",
|
||||||
trade.getId(), trade.getTradingPeerNodeAddress(), signedWitness);
|
trade.getId(), trade.getTradingPeer().getNodeAddress(), signedWitness);
|
||||||
processModel.getTradeManager().requestPersistence();
|
processModel.getTradeManager().requestPersistence();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ public abstract class SendMailboxMessageTask extends TradeTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected NodeAddress getReceiverNodeAddress() {
|
protected NodeAddress getReceiverNodeAddress() {
|
||||||
return trade.getTradingPeerNodeAddress();
|
return trade.getTradingPeer().getNodeAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PubKeyRing getReceiverPubKeyRing() {
|
protected PubKeyRing getReceiverPubKeyRing() {
|
||||||
|
@ -93,8 +93,8 @@ public class TakerSendInitTradeRequestToArbitrator extends TradeTask {
|
|||||||
|
|
||||||
// set pub keys
|
// set pub keys
|
||||||
processModel.getArbitrator().setPubKeyRing(arbitrator.getPubKeyRing());
|
processModel.getArbitrator().setPubKeyRing(arbitrator.getPubKeyRing());
|
||||||
trade.setArbitratorNodeAddress(arbitratorNodeAddress);
|
trade.getArbitrator().setNodeAddress(arbitratorNodeAddress);
|
||||||
trade.setArbitratorPubKeyRing(processModel.getArbitrator().getPubKeyRing());
|
trade.getArbitrator().setPubKeyRing(processModel.getArbitrator().getPubKeyRing());
|
||||||
|
|
||||||
// create request to arbitrator
|
// create request to arbitrator
|
||||||
InitTradeRequest makerRequest = (InitTradeRequest) processModel.getTradeMessage(); // taker's InitTradeRequest to maker
|
InitTradeRequest makerRequest = (InitTradeRequest) processModel.getTradeMessage(); // taker's InitTradeRequest to maker
|
||||||
@ -114,7 +114,7 @@ public class TakerSendInitTradeRequestToArbitrator extends TradeTask {
|
|||||||
makerRequest.getCurrentDate(),
|
makerRequest.getCurrentDate(),
|
||||||
makerRequest.getMakerNodeAddress(),
|
makerRequest.getMakerNodeAddress(),
|
||||||
makerRequest.getTakerNodeAddress(),
|
makerRequest.getTakerNodeAddress(),
|
||||||
trade.getArbitratorNodeAddress(),
|
trade.getArbitrator().getNodeAddress(),
|
||||||
processModel.getReserveTx().getHash(),
|
processModel.getReserveTx().getHash(),
|
||||||
processModel.getReserveTx().getFullHex(),
|
processModel.getReserveTx().getFullHex(),
|
||||||
processModel.getReserveTx().getKey(),
|
processModel.getReserveTx().getKey(),
|
||||||
@ -122,7 +122,7 @@ public class TakerSendInitTradeRequestToArbitrator extends TradeTask {
|
|||||||
processModel.getMakerSignature());
|
processModel.getMakerSignature());
|
||||||
|
|
||||||
// send request to arbitrator
|
// send request to arbitrator
|
||||||
log.info("Sending {} with offerId {} and uid {} to arbitrator {} with pub key ring {}", arbitratorRequest.getClass().getSimpleName(), arbitratorRequest.getTradeId(), arbitratorRequest.getUid(), trade.getArbitratorNodeAddress(), trade.getArbitratorPubKeyRing());
|
log.info("Sending {} with offerId {} and uid {} to arbitrator {} with pub key ring {}", arbitratorRequest.getClass().getSimpleName(), arbitratorRequest.getTradeId(), arbitratorRequest.getUid(), trade.getArbitrator().getNodeAddress(), trade.getArbitrator().getPubKeyRing());
|
||||||
processModel.getP2PService().sendEncryptedDirectMessage(
|
processModel.getP2PService().sendEncryptedDirectMessage(
|
||||||
arbitratorNodeAddress,
|
arbitratorNodeAddress,
|
||||||
arbitrator.getPubKeyRing(),
|
arbitrator.getPubKeyRing(),
|
||||||
|
@ -95,16 +95,16 @@ public class UpdateMultisigWithTradingPeer extends TradeTask {
|
|||||||
|
|
||||||
System.out.println("Sending message: " + message);
|
System.out.println("Sending message: " + message);
|
||||||
|
|
||||||
// TODO (woodser): trade.getTradingPeerNodeAddress() and/or trade.getTradingPeerPubKeyRing() are null on restart of application, so cannot send payment to complete trade
|
// TODO (woodser): trade.getTradingPeer().getNodeAddress() and/or trade.getTradingPeer().getPubKeyRing() are null on restart of application, so cannot send payment to complete trade
|
||||||
log.info("Send {} with offerId {} and uid {} to peer {}", message.getClass().getSimpleName(), message.getTradeId(), message.getUid(), trade.getTradingPeerNodeAddress());
|
log.info("Send {} with offerId {} and uid {} to peer {}", message.getClass().getSimpleName(), message.getTradeId(), message.getUid(), trade.getTradingPeer().getNodeAddress());
|
||||||
processModel.getP2PService().sendEncryptedDirectMessage(trade.getTradingPeerNodeAddress(), trade.getTradingPeerPubKeyRing(), message, new SendDirectMessageListener() {
|
processModel.getP2PService().sendEncryptedDirectMessage(trade.getTradingPeer().getNodeAddress(), trade.getTradingPeer().getPubKeyRing(), message, new SendDirectMessageListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onArrived() {
|
public void onArrived() {
|
||||||
log.info("{} arrived at trading peer: offerId={}; uid={}", message.getClass().getSimpleName(), message.getTradeId(), message.getUid());
|
log.info("{} arrived at trading peer: offerId={}; uid={}", message.getClass().getSimpleName(), message.getTradeId(), message.getUid());
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onFault(String errorMessage) {
|
public void onFault(String errorMessage) {
|
||||||
log.error("Sending {} failed: uid={}; peer={}; error={}", message.getClass().getSimpleName(), message.getUid(), trade.getArbitratorNodeAddress(), errorMessage);
|
log.error("Sending {} failed: uid={}; peer={}; error={}", message.getClass().getSimpleName(), message.getUid(), trade.getArbitrator().getNodeAddress(), errorMessage);
|
||||||
appendToErrorMessage("Sending message failed: message=" + message + "\nerrorMessage=" + errorMessage);
|
appendToErrorMessage("Sending message failed: message=" + message + "\nerrorMessage=" + errorMessage);
|
||||||
failed();
|
failed();
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ public class ProcessMediatedPayoutSignatureMessage extends TradeTask {
|
|||||||
trade.getTradingPeer().setMediatedPayoutTxSignature(checkNotNull(message.getTxSignature()));
|
trade.getTradingPeer().setMediatedPayoutTxSignature(checkNotNull(message.getTxSignature()));
|
||||||
|
|
||||||
// update to the latest peer address of our peer if the message is correct
|
// update to the latest peer address of our peer if the message is correct
|
||||||
trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
|
trade.getTradingPeer().setNodeAddress(processModel.getTempTradingPeerNodeAddress());
|
||||||
|
|
||||||
trade.setMediationResultState(MediationResultState.RECEIVED_SIG_MSG);
|
trade.setMediationResultState(MediationResultState.RECEIVED_SIG_MSG);
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ public class ProcessMediatedPayoutTxPublishedMessage extends TradeTask {
|
|||||||
// checkArgument(message.getPayoutTx() != null);
|
// checkArgument(message.getPayoutTx() != null);
|
||||||
//
|
//
|
||||||
// // update to the latest peer address of our peer if the message is correct
|
// // update to the latest peer address of our peer if the message is correct
|
||||||
// trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
|
// trade.getTradingPeer().setNodeAddress(processModel.getTempTradingPeerNodeAddress());
|
||||||
//
|
//
|
||||||
// if (trade.getPayoutTx() == null) {
|
// if (trade.getPayoutTx() == null) {
|
||||||
// Transaction committedMediatedPayoutTx = WalletService.maybeAddNetworkTxToWallet(message.getPayoutTx(), processModel.getBtcWalletService().getWallet());
|
// Transaction committedMediatedPayoutTx = WalletService.maybeAddNetworkTxToWallet(message.getPayoutTx(), processModel.getBtcWalletService().getWallet());
|
||||||
|
@ -81,7 +81,7 @@ public final class TradeStatistics2 implements ProcessOncePersistableNetworkPayl
|
|||||||
extraDataMap.put(OfferPayload.REFERRAL_ID, referralId);
|
extraDataMap.put(OfferPayload.REFERRAL_ID, referralId);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeAddress arbitratorNodeAddress = trade.getArbitratorNodeAddress();
|
NodeAddress arbitratorNodeAddress = trade.getArbitrator().getNodeAddress();
|
||||||
if (arbitratorNodeAddress != null) {
|
if (arbitratorNodeAddress != null) {
|
||||||
// The first 4 chars are sufficient to identify a arbitrator.
|
// The first 4 chars are sufficient to identify a arbitrator.
|
||||||
// For testing with regtest/localhost we use the full address as its localhost and would result in
|
// For testing with regtest/localhost we use the full address as its localhost and would result in
|
||||||
|
@ -86,7 +86,7 @@ public final class TradeStatistics3 implements ProcessOncePersistableNetworkPayl
|
|||||||
extraDataMap.put(OfferPayload.REFERRAL_ID, referralId);
|
extraDataMap.put(OfferPayload.REFERRAL_ID, referralId);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeAddress arbitratorNodeAddress = checkNotNull(trade.getArbitratorNodeAddress());
|
NodeAddress arbitratorNodeAddress = checkNotNull(trade.getArbitrator().getNodeAddress());
|
||||||
|
|
||||||
// The first 4 chars are sufficient to identify an arbitrator.
|
// The first 4 chars are sufficient to identify an arbitrator.
|
||||||
// For testing with regtest/localhost we use the full address as its localhost and would result in
|
// For testing with regtest/localhost we use the full address as its localhost and would result in
|
||||||
|
@ -142,7 +142,7 @@ class AltCoinAccountsDataModel extends ActivatableDataModel {
|
|||||||
.isPresent();
|
.isPresent();
|
||||||
isPaymentAccountUsed = isPaymentAccountUsed || tradeManager.getObservableList().stream()
|
isPaymentAccountUsed = isPaymentAccountUsed || tradeManager.getObservableList().stream()
|
||||||
.filter(t -> t.getOffer().getMakerPaymentAccountId().equals(paymentAccount.getId()) ||
|
.filter(t -> t.getOffer().getMakerPaymentAccountId().equals(paymentAccount.getId()) ||
|
||||||
paymentAccount.getId().equals(t.getTakerPaymentAccountId()))
|
paymentAccount.getId().equals(t.getTaker().getPaymentAccountId()))
|
||||||
.findAny()
|
.findAny()
|
||||||
.isPresent();
|
.isPresent();
|
||||||
if (!isPaymentAccountUsed)
|
if (!isPaymentAccountUsed)
|
||||||
|
@ -147,7 +147,7 @@ class FiatAccountsDataModel extends ActivatableDataModel {
|
|||||||
.anyMatch(o -> o.getOffer().getMakerPaymentAccountId().equals(paymentAccount.getId()));
|
.anyMatch(o -> o.getOffer().getMakerPaymentAccountId().equals(paymentAccount.getId()));
|
||||||
isPaymentAccountUsed = isPaymentAccountUsed || tradeManager.getObservableList().stream()
|
isPaymentAccountUsed = isPaymentAccountUsed || tradeManager.getObservableList().stream()
|
||||||
.anyMatch(t -> t.getOffer().getMakerPaymentAccountId().equals(paymentAccount.getId()) ||
|
.anyMatch(t -> t.getOffer().getMakerPaymentAccountId().equals(paymentAccount.getId()) ||
|
||||||
paymentAccount.getId().equals(t.getTakerPaymentAccountId()));
|
paymentAccount.getId().equals(t.getTaker().getPaymentAccountId()));
|
||||||
if (!isPaymentAccountUsed)
|
if (!isPaymentAccountUsed)
|
||||||
user.removePaymentAccount(paymentAccount);
|
user.removePaymentAccount(paymentAccount);
|
||||||
return isPaymentAccountUsed;
|
return isPaymentAccountUsed;
|
||||||
|
@ -208,7 +208,7 @@ public class TradeDetailsWindow extends Overlay<TradeDetailsWindow> {
|
|||||||
rows++;
|
rows++;
|
||||||
if (trade.hasFailed())
|
if (trade.hasFailed())
|
||||||
rows += 2;
|
rows += 2;
|
||||||
if (trade.getTradingPeerNodeAddress() != null)
|
if (trade.getTradingPeer().getNodeAddress() != null)
|
||||||
rows++;
|
rows++;
|
||||||
if (showXmrProofResult)
|
if (showXmrProofResult)
|
||||||
rows++;
|
rows++;
|
||||||
@ -232,16 +232,16 @@ public class TradeDetailsWindow extends Overlay<TradeDetailsWindow> {
|
|||||||
Res.get("shared.takerTxFee", formatter.formatCoinWithCode(trade.getTxFee().multiply(3)));
|
Res.get("shared.takerTxFee", formatter.formatCoinWithCode(trade.getTxFee().multiply(3)));
|
||||||
addConfirmationLabelTextField(gridPane, ++rowIndex, Res.get("tradeDetailsWindow.txFee"), txFee);
|
addConfirmationLabelTextField(gridPane, ++rowIndex, Res.get("tradeDetailsWindow.txFee"), txFee);
|
||||||
|
|
||||||
NodeAddress arbitratorNodeAddress = trade.getArbitratorNodeAddress();
|
NodeAddress arbitratorNodeAddress = trade.getArbitrator().getNodeAddress();
|
||||||
if (arbitratorNodeAddress != null) {
|
if (arbitratorNodeAddress != null) {
|
||||||
addConfirmationLabelTextField(gridPane, ++rowIndex,
|
addConfirmationLabelTextField(gridPane, ++rowIndex,
|
||||||
Res.get("tradeDetailsWindow.agentAddresses"),
|
Res.get("tradeDetailsWindow.agentAddresses"),
|
||||||
arbitratorNodeAddress.getFullAddress());
|
arbitratorNodeAddress.getFullAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trade.getTradingPeerNodeAddress() != null)
|
if (trade.getTradingPeer().getNodeAddress() != null)
|
||||||
addConfirmationLabelTextField(gridPane, ++rowIndex, Res.get("tradeDetailsWindow.tradingPeersOnion"),
|
addConfirmationLabelTextField(gridPane, ++rowIndex, Res.get("tradeDetailsWindow.tradingPeersOnion"),
|
||||||
trade.getTradingPeerNodeAddress().getFullAddress());
|
trade.getTradingPeer().getNodeAddress().getFullAddress());
|
||||||
|
|
||||||
if (showXmrProofResult) {
|
if (showXmrProofResult) {
|
||||||
// As the window is already overloaded we replace the tradingPeersPubKeyHash field with the auto-conf state
|
// As the window is already overloaded we replace the tradingPeersPubKeyHash field with the auto-conf state
|
||||||
|
@ -501,7 +501,7 @@ public class ClosedTradesView extends ActivatableViewAndModel<VBox, ClosedTrades
|
|||||||
if (!empty && item != null && item.getTradable() instanceof Trade) {
|
if (!empty && item != null && item.getTradable() instanceof Trade) {
|
||||||
Trade tradeModel = (Trade) item.getTradable();
|
Trade tradeModel = (Trade) item.getTradable();
|
||||||
int numPastTrades = item.getNumPastTrades();
|
int numPastTrades = item.getNumPastTrades();
|
||||||
NodeAddress tradingPeerNodeAddress = tradeModel.getTradingPeerNodeAddress();
|
NodeAddress tradingPeerNodeAddress = tradeModel.getTradingPeer().getNodeAddress();
|
||||||
String role = Res.get("peerInfoIcon.tooltip.tradePeer");
|
String role = Res.get("peerInfoIcon.tooltip.tradePeer");
|
||||||
Node peerInfoIcon = new PeerInfoIconTrading(tradingPeerNodeAddress,
|
Node peerInfoIcon = new PeerInfoIconTrading(tradingPeerNodeAddress,
|
||||||
role,
|
role,
|
||||||
|
@ -522,7 +522,7 @@ public class PendingTradesDataModel extends ActivatableDataModel {
|
|||||||
// If no dispute state set we start with mediation
|
// If no dispute state set we start with mediation
|
||||||
resultHandler = () -> navigation.navigateTo(MainView.class, SupportView.class, MediationClientView.class);
|
resultHandler = () -> navigation.navigateTo(MainView.class, SupportView.class, MediationClientView.class);
|
||||||
disputeManager = mediationManager;
|
disputeManager = mediationManager;
|
||||||
PubKeyRing arbitratorPubKeyRing = trade.getArbitratorPubKeyRing();
|
PubKeyRing arbitratorPubKeyRing = trade.getArbitrator().getPubKeyRing();
|
||||||
checkNotNull(arbitratorPubKeyRing, "arbitratorPubKeyRing must not be null");
|
checkNotNull(arbitratorPubKeyRing, "arbitratorPubKeyRing must not be null");
|
||||||
byte[] depositTxSerialized = null; // depositTx.bitcoinSerialize(); // TODO (woodser): no serialized txs in xmr
|
byte[] depositTxSerialized = null; // depositTx.bitcoinSerialize(); // TODO (woodser): no serialized txs in xmr
|
||||||
Dispute dispute = new Dispute(new Date().getTime(),
|
Dispute dispute = new Dispute(new Date().getTime(),
|
||||||
|
@ -849,7 +849,7 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
|||||||
super.updateItem(newItem, empty);
|
super.updateItem(newItem, empty);
|
||||||
if (!empty && newItem != null) {
|
if (!empty && newItem != null) {
|
||||||
final Trade trade = newItem.getTrade();
|
final Trade trade = newItem.getTrade();
|
||||||
final NodeAddress tradingPeerNodeAddress = trade.getTradingPeerNodeAddress();
|
final NodeAddress tradingPeerNodeAddress = trade.getTradingPeer().getNodeAddress();
|
||||||
int numPastTrades = model.getNumPastTrades(trade);
|
int numPastTrades = model.getNumPastTrades(trade);
|
||||||
String role = Res.get("peerInfoIcon.tooltip.tradePeer");
|
String role = Res.get("peerInfoIcon.tooltip.tradePeer");
|
||||||
Node peerInfoIcon = new PeerInfoIconTrading(tradingPeerNodeAddress,
|
Node peerInfoIcon = new PeerInfoIconTrading(tradingPeerNodeAddress,
|
||||||
|
@ -372,9 +372,9 @@ public class PendingTradesViewModel extends ActivatableWithDataModel<PendingTrad
|
|||||||
.filter(e -> {
|
.filter(e -> {
|
||||||
if (e instanceof Trade) {
|
if (e instanceof Trade) {
|
||||||
Trade t = (Trade) e;
|
Trade t = (Trade) e;
|
||||||
return t.getTradingPeerNodeAddress() != null &&
|
return t.getTradingPeer().getNodeAddress() != null &&
|
||||||
trade.getTradingPeerNodeAddress() != null &&
|
trade.getTradingPeer().getNodeAddress() != null &&
|
||||||
t.getTradingPeerNodeAddress().getFullAddress().equals(trade.getTradingPeerNodeAddress().getFullAddress());
|
t.getTradingPeer().getNodeAddress().getFullAddress().equals(trade.getTradingPeer().getNodeAddress().getFullAddress());
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -1725,28 +1725,18 @@ message Trade {
|
|||||||
bytes contract_hash = 16;
|
bytes contract_hash = 16;
|
||||||
NodeAddress arbitrator_node_address = 17;
|
NodeAddress arbitrator_node_address = 17;
|
||||||
NodeAddress mediator_node_address = 18;
|
NodeAddress mediator_node_address = 18;
|
||||||
bytes arbitrator_btc_pub_key = 19;
|
|
||||||
string taker_payment_account_id = 20;
|
|
||||||
string error_message = 21;
|
string error_message = 21;
|
||||||
PubKeyRing arbitrator_pub_key_ring = 22;
|
|
||||||
PubKeyRing mediator_pub_key_ring = 23;
|
|
||||||
string counter_currency_tx_id = 24;
|
string counter_currency_tx_id = 24;
|
||||||
repeated ChatMessage chat_message = 25;
|
repeated ChatMessage chat_message = 25;
|
||||||
MediationResultState mediation_result_state = 26;
|
MediationResultState mediation_result_state = 26;
|
||||||
int64 lock_time = 27;
|
int64 lock_time = 27;
|
||||||
bytes delayed_payout_tx_bytes = 28;
|
bytes delayed_payout_tx_bytes = 28;
|
||||||
NodeAddress refund_agent_node_address = 29;
|
NodeAddress refund_agent_node_address = 29;
|
||||||
PubKeyRing refund_agent_pub_key_ring = 30;
|
RefundResultState refund_result_state = 30;
|
||||||
RefundResultState refund_result_state = 31;
|
int64 last_refresh_request_date = 31 [deprecated = true];
|
||||||
int64 last_refresh_request_date = 32 [deprecated = true];
|
string counter_currency_extra_data = 32;
|
||||||
string counter_currency_extra_data = 33;
|
string asset_tx_proof_result = 33; // name of AssetTxProofResult enum
|
||||||
string asset_tx_proof_result = 34; // name of AssetTxProofResult enum
|
string uid = 34;
|
||||||
string uid = 35;
|
|
||||||
|
|
||||||
NodeAddress maker_node_address = 100; // TODO (woodser): move these into TradingPeer
|
|
||||||
NodeAddress taker_node_address = 101;
|
|
||||||
PubKeyRing taker_pub_key_ring = 102;
|
|
||||||
PubKeyRing maker_pub_key_ring = 103;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message BuyerAsMakerTrade {
|
message BuyerAsMakerTrade {
|
||||||
@ -1800,26 +1790,27 @@ message ProcessModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message TradingPeer {
|
message TradingPeer {
|
||||||
string account_id = 1;
|
NodeAddress node_address = 1;
|
||||||
string payment_account_id = 2;
|
PubKeyRing pub_key_ring = 2;
|
||||||
string payment_method_id = 3;
|
string account_id = 3;
|
||||||
bytes payment_account_payload_hash = 4;
|
string payment_account_id = 4;
|
||||||
bytes encrypted_payment_account_payload = 5;
|
string payment_method_id = 5;
|
||||||
bytes payment_account_key = 6;
|
bytes payment_account_payload_hash = 6;
|
||||||
PaymentAccountPayload payment_account_payload = 7;
|
bytes encrypted_payment_account_payload = 7;
|
||||||
string payout_address_string = 8;
|
bytes payment_account_key = 8;
|
||||||
string contract_as_json = 9;
|
PaymentAccountPayload payment_account_payload = 9;
|
||||||
string contract_signature = 10;
|
string payout_address_string = 10;
|
||||||
bytes signature = 11; // TODO (woodser): remove unused fields? this was buyer-signed payout tx as bytes
|
string contract_as_json = 11;
|
||||||
PubKeyRing pub_key_ring = 12;
|
string contract_signature = 12;
|
||||||
bytes multi_sig_pub_key = 13;
|
bytes signature = 13; // TODO (woodser): remove unused fields? this was buyer-signed payout tx as bytes
|
||||||
repeated RawTransactionInput raw_transaction_inputs = 14;
|
bytes multi_sig_pub_key = 14;
|
||||||
int64 change_output_value = 15;
|
repeated RawTransactionInput raw_transaction_inputs = 15;
|
||||||
string change_output_address = 16;
|
int64 change_output_value = 16;
|
||||||
bytes account_age_witness_nonce = 17;
|
string change_output_address = 17;
|
||||||
bytes account_age_witness_signature = 18;
|
bytes account_age_witness_nonce = 18;
|
||||||
int64 current_date = 19;
|
bytes account_age_witness_signature = 19;
|
||||||
bytes mediated_payout_tx_signature = 20;
|
int64 current_date = 20;
|
||||||
|
bytes mediated_payout_tx_signature = 21;
|
||||||
|
|
||||||
string reserve_tx_hash = 1001;
|
string reserve_tx_hash = 1001;
|
||||||
string reserve_tx_hex = 1002;
|
string reserve_tx_hex = 1002;
|
||||||
|
Loading…
Reference in New Issue
Block a user