impl. feedback from aaron. improve popups, add warning for remove offer, deactivate mainnet,...

This commit is contained in:
Manfred Karrer 2015-11-17 20:54:03 +01:00
parent 2950f6e347
commit f9a31f4b8a
37 changed files with 425 additions and 281 deletions

View file

@ -150,7 +150,7 @@ public class CountryUtil {
}
public static String getNamesByCodesString(List<String> countryCodes) {
return getNamesByCodes(countryCodes).stream().collect(Collectors.joining(", "));
return getNamesByCodes(countryCodes).stream().collect(Collectors.joining(",\n"));
}
private static final String[] countryCodes = new String[]{"AE", "AL", "AR", "AT", "AU", "BA", "BE", "BG", "BH",

View file

@ -37,11 +37,14 @@ public class SepaAccountContractData extends PaymentAccountContractData implemen
private String holderName;
private String iban;
private String bic;
private Set<String> acceptedCountryCodes;
// Dont use a set here as we need a deterministic ordering, otherwise the contract hash does not match
private ArrayList<String> acceptedCountryCodes;
public SepaAccountContractData(String paymentMethod, String id, int maxTradePeriod) {
super(paymentMethod, id, maxTradePeriod);
acceptedCountryCodes = CountryUtil.getAllSepaCountries().stream().map(e -> e.code).collect(Collectors.toSet());
Set<String> acceptedCountryCodesAsSet = CountryUtil.getAllSepaCountries().stream().map(e -> e.code).collect(Collectors.toSet());
acceptedCountryCodes = new ArrayList<>(acceptedCountryCodesAsSet);
acceptedCountryCodes.sort((a, b) -> a.compareTo(b));
}
public void setHolderName(String holderName) {
@ -69,17 +72,17 @@ public class SepaAccountContractData extends PaymentAccountContractData implemen
}
public void addAcceptedCountry(String countryCode) {
acceptedCountryCodes.add(countryCode);
if (!acceptedCountryCodes.contains(countryCode))
acceptedCountryCodes.add(countryCode);
}
public void removeAcceptedCountry(String countryCode) {
acceptedCountryCodes.remove(countryCode);
if (acceptedCountryCodes.contains(countryCode))
acceptedCountryCodes.remove(countryCode);
}
public List<String> getAcceptedCountryCodes() {
List<String> sortedList = new ArrayList<>(acceptedCountryCodes);
sortedList.sort((a, b) -> a.compareTo(b));
return sortedList;
return acceptedCountryCodes;
}
@Override

View file

@ -38,11 +38,13 @@ public class Contract implements Serializable {
@JsonExclude
public static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
public static final String TAC = "I commit to the trade conditions as defined above.";
public final Offer offer;
private final long tradeAmount;
public final String takeOfferFeeTxID;
public final Address arbitratorAddress;
private final boolean isBuyerOffererOrSellerTaker;
private final boolean isBuyerOffererAndSellerTaker;
private final String offererAccountId;
private final String takerAccountId;
private final PaymentAccountContractData offererPaymentAccountContractData;
@ -62,17 +64,13 @@ public class Contract implements Serializable {
@JsonExclude
private final byte[] takerBtcPubKey;
// TODO some basic TAC
public final String tac = "With my signature I commit to the trading agreement of Bitsquare and to fulfill the trade as defined there.";
public Contract(Offer offer,
Coin tradeAmount,
String takeOfferFeeTxID,
Address buyerAddress,
Address sellerAddress,
Address arbitratorAddress,
boolean isBuyerOffererOrSellerTaker,
boolean isBuyerOffererAndSellerTaker,
String offererAccountId,
String takerAccountId,
PaymentAccountContractData offererPaymentAccountContractData,
@ -89,7 +87,7 @@ public class Contract implements Serializable {
this.tradeAmount = tradeAmount.value;
this.takeOfferFeeTxID = takeOfferFeeTxID;
this.arbitratorAddress = arbitratorAddress;
this.isBuyerOffererOrSellerTaker = isBuyerOffererOrSellerTaker;
this.isBuyerOffererAndSellerTaker = isBuyerOffererAndSellerTaker;
this.offererAccountId = offererAccountId;
this.takerAccountId = takerAccountId;
this.offererPaymentAccountContractData = offererPaymentAccountContractData;
@ -103,44 +101,44 @@ public class Contract implements Serializable {
}
public String getBuyerAccountId() {
return isBuyerOffererOrSellerTaker ? offererAccountId : takerAccountId;
return isBuyerOffererAndSellerTaker ? offererAccountId : takerAccountId;
}
public String getSellerAccountId() {
return isBuyerOffererOrSellerTaker ? takerAccountId : offererAccountId;
return isBuyerOffererAndSellerTaker ? takerAccountId : offererAccountId;
}
public String getBuyerPayoutAddressString() {
return isBuyerOffererOrSellerTaker ? offererPayoutAddressString : takerPayoutAddressString;
return isBuyerOffererAndSellerTaker ? offererPayoutAddressString : takerPayoutAddressString;
}
public String getSellerPayoutAddressString() {
return isBuyerOffererOrSellerTaker ? takerPayoutAddressString : offererPayoutAddressString;
return isBuyerOffererAndSellerTaker ? takerPayoutAddressString : offererPayoutAddressString;
}
public PubKeyRing getBuyerPubKeyRing() {
return isBuyerOffererOrSellerTaker ? offererPubKeyRing : takerPubKeyRing;
return isBuyerOffererAndSellerTaker ? offererPubKeyRing : takerPubKeyRing;
}
public PubKeyRing getSellerPubKeyRing() {
return isBuyerOffererOrSellerTaker ? takerPubKeyRing : offererPubKeyRing;
return isBuyerOffererAndSellerTaker ? takerPubKeyRing : offererPubKeyRing;
}
public byte[] getBuyerBtcPubKey() {
return isBuyerOffererOrSellerTaker ? offererBtcPubKey : takerBtcPubKey;
return isBuyerOffererAndSellerTaker ? offererBtcPubKey : takerBtcPubKey;
}
public byte[] getSellerBtcPubKey() {
return isBuyerOffererOrSellerTaker ? takerBtcPubKey : offererBtcPubKey;
return isBuyerOffererAndSellerTaker ? takerBtcPubKey : offererBtcPubKey;
}
public PaymentAccountContractData getBuyerPaymentAccountContractData() {
return isBuyerOffererOrSellerTaker ? offererPaymentAccountContractData : takerPaymentAccountContractData;
return isBuyerOffererAndSellerTaker ? offererPaymentAccountContractData : takerPaymentAccountContractData;
}
public PaymentAccountContractData getSellerPaymentAccountContractData() {
return isBuyerOffererOrSellerTaker ? takerPaymentAccountContractData : offererPaymentAccountContractData;
return isBuyerOffererAndSellerTaker ? takerPaymentAccountContractData : offererPaymentAccountContractData;
}
public String getPaymentMethodName() {
@ -166,17 +164,19 @@ public class Contract implements Serializable {
@Override
public String toString() {
return "Contract{" +
"tac='" + tac + '\'' +
", offer=" + offer +
"offer=" + offer +
", tradeAmount=" + tradeAmount +
", isBuyerOffererOrSellerTaker=" + isBuyerOffererOrSellerTaker +
", takeOfferFeeTxID='" + takeOfferFeeTxID + '\'' +
", offererAccountID='" + offererAccountId + '\'' +
", takerAccountID='" + takerAccountId + '\'' +
", offererPaymentAccount=" + offererPaymentAccountContractData +
", takerPaymentAccount=" + takerPaymentAccountContractData +
", arbitratorAddress=" + arbitratorAddress +
", isBuyerOffererAndSellerTaker=" + isBuyerOffererAndSellerTaker +
", offererAccountId='" + offererAccountId + '\'' +
", takerAccountId='" + takerAccountId + '\'' +
", offererPaymentAccountContractData=" + offererPaymentAccountContractData +
", takerPaymentAccountContractData=" + takerPaymentAccountContractData +
", offererPubKeyRing=" + offererPubKeyRing +
", takerPubKeyRing=" + takerPubKeyRing +
", buyerAddress=" + buyerAddress +
", sellerAddress=" + sellerAddress +
", offererPayoutAddressString='" + offererPayoutAddressString + '\'' +
", takerPayoutAddressString='" + takerPayoutAddressString + '\'' +
", offererBtcPubKey=" + Arrays.toString(offererBtcPubKey) +
@ -192,7 +192,7 @@ public class Contract implements Serializable {
Contract contract = (Contract) o;
if (tradeAmount != contract.tradeAmount) return false;
if (isBuyerOffererOrSellerTaker != contract.isBuyerOffererOrSellerTaker) return false;
if (isBuyerOffererAndSellerTaker != contract.isBuyerOffererAndSellerTaker) return false;
if (offer != null ? !offer.equals(contract.offer) : contract.offer != null) return false;
if (takeOfferFeeTxID != null ? !takeOfferFeeTxID.equals(contract.takeOfferFeeTxID) : contract.takeOfferFeeTxID != null)
return false;
@ -219,8 +219,7 @@ public class Contract implements Serializable {
if (takerPayoutAddressString != null ? !takerPayoutAddressString.equals(contract.takerPayoutAddressString) : contract.takerPayoutAddressString != null)
return false;
if (!Arrays.equals(offererBtcPubKey, contract.offererBtcPubKey)) return false;
if (!Arrays.equals(takerBtcPubKey, contract.takerBtcPubKey)) return false;
return !(tac != null ? !tac.equals(contract.tac) : contract.tac != null);
return Arrays.equals(takerBtcPubKey, contract.takerBtcPubKey);
}
@ -230,7 +229,7 @@ public class Contract implements Serializable {
result = 31 * result + (int) (tradeAmount ^ (tradeAmount >>> 32));
result = 31 * result + (takeOfferFeeTxID != null ? takeOfferFeeTxID.hashCode() : 0);
result = 31 * result + (arbitratorAddress != null ? arbitratorAddress.hashCode() : 0);
result = 31 * result + (isBuyerOffererOrSellerTaker ? 1 : 0);
result = 31 * result + (isBuyerOffererAndSellerTaker ? 1 : 0);
result = 31 * result + (offererAccountId != null ? offererAccountId.hashCode() : 0);
result = 31 * result + (takerAccountId != null ? takerAccountId.hashCode() : 0);
result = 31 * result + (offererPaymentAccountContractData != null ? offererPaymentAccountContractData.hashCode() : 0);
@ -243,7 +242,7 @@ public class Contract implements Serializable {
result = 31 * result + (takerPayoutAddressString != null ? takerPayoutAddressString.hashCode() : 0);
result = 31 * result + (offererBtcPubKey != null ? Arrays.hashCode(offererBtcPubKey) : 0);
result = 31 * result + (takerBtcPubKey != null ? Arrays.hashCode(takerBtcPubKey) : 0);
result = 31 * result + (tac != null ? tac.hashCode() : 0);
return result;
}
}

View file

@ -53,6 +53,10 @@ public final class Offer implements PubKeyProtectedExpirablePayload {
transient private static final Logger log = LoggerFactory.getLogger(Offer.class);
public static final long TTL = 10 * 60 * 1000; // 10 min.
public final static String TAC_OFFERER = "When placing that offer I accept that anyone who fulfills my conditions can " +
"take that offer.";
public static final String TAC_TAKER = "With taking the offer I commit to the trade conditions as defined.";
public enum Direction {BUY, SELL}
@ -397,14 +401,21 @@ public final class Offer implements PubKeyProtectedExpirablePayload {
", fiatPrice=" + fiatPrice +
", amount=" + amount +
", minAmount=" + minAmount +
", address=" + offererAddress +
", pubKeyRing.hashCode()=" + pubKeyRing.hashCode() +
", offererAddress=" + offererAddress +
", pubKeyRing=" + pubKeyRing +
", paymentMethodName='" + paymentMethodName + '\'' +
", paymentMethodCountryCode='" + paymentMethodCountryCode + '\'' +
", offererPaymentAccountId='" + offererPaymentAccountId + '\'' +
", acceptedCountryCodes=" + acceptedCountryCodes +
", arbitratorAddresses=" + arbitratorAddresses +
", offerFeePaymentTxID='" + offerFeePaymentTxID + '\'' +
", state=" + state +
", stateProperty=" + stateProperty +
", availabilityProtocol=" + availabilityProtocol +
", errorMessageProperty=" + errorMessageProperty +
", TAC_OFFERER=" + TAC_OFFERER +
", TAC_TAKER=" + TAC_TAKER +
'}';
}
}

View file

@ -41,11 +41,12 @@ public class SignAndPublishDepositTxAsBuyer extends TradeTask {
try {
runInterceptHook();
log.debug("getContractAsJson");
log.debug("----------");
log.debug(trade.getContractAsJson());
log.debug("----------");
log.info("\n\n------------------------------------------------------------\n"
+ "Contract as json\n"
+ trade.getContractAsJson()
+ "\n------------------------------------------------------------\n");
byte[] contractHash = Hash.getHash(trade.getContractAsJson());
trade.setContractHash(contractHash);
processModel.getTradeWalletService().takerSignsAndPublishesDepositTx(

View file

@ -48,11 +48,11 @@ public class CreateAndSignContract extends TradeTask {
TradingPeer taker = processModel.tradingPeer;
PaymentAccountContractData offererPaymentAccountContractData = processModel.getPaymentAccountContractData(trade);
PaymentAccountContractData takerPaymentAccountContractData = taker.getPaymentAccountContractData();
boolean isBuyerOffererOrSellerTaker = trade instanceof BuyerAsOffererTrade;
boolean isBuyerOffererAndSellerTaker = trade instanceof BuyerAsOffererTrade;
Address buyerAddress = isBuyerOffererOrSellerTaker ? processModel.getMyAddress() : processModel.getTempTradingPeerAddress();
Address sellerAddress = isBuyerOffererOrSellerTaker ? processModel.getTempTradingPeerAddress() : processModel.getMyAddress();
log.debug("isBuyerOffererOrSellerTaker " + isBuyerOffererOrSellerTaker);
Address buyerAddress = isBuyerOffererAndSellerTaker ? processModel.getMyAddress() : processModel.getTempTradingPeerAddress();
Address sellerAddress = isBuyerOffererAndSellerTaker ? processModel.getTempTradingPeerAddress() : processModel.getMyAddress();
log.debug("isBuyerOffererAndSellerTaker " + isBuyerOffererAndSellerTaker);
log.debug("buyerAddress " + buyerAddress);
log.debug("sellerAddress " + sellerAddress);
Contract contract = new Contract(
@ -62,7 +62,7 @@ public class CreateAndSignContract extends TradeTask {
buyerAddress,
sellerAddress,
trade.getArbitratorAddress(),
isBuyerOffererOrSellerTaker,
isBuyerOffererAndSellerTaker,
processModel.getAccountId(),
taker.getAccountId(),
offererPaymentAccountContractData,

View file

@ -44,6 +44,11 @@ public class CreateAndSignDepositTxAsSeller extends TradeTask {
Coin sellerInputAmount = FeePolicy.SECURITY_DEPOSIT.add(FeePolicy.TX_FEE).add(trade.getTradeAmount());
Coin msOutputAmount = sellerInputAmount.add(FeePolicy.SECURITY_DEPOSIT);
log.info("\n\n------------------------------------------------------------\n"
+ "Contract as json\n"
+ trade.getContractAsJson()
+ "\n------------------------------------------------------------\n");
byte[] contractHash = Hash.getHash(trade.getContractAsJson());
trade.setContractHash(contractHash);
PreparedDepositTxAndOffererInputs result = processModel.getTradeWalletService().offererCreatesAndSignsDepositTx(

View file

@ -40,10 +40,10 @@ public class SignAndPublishDepositTxAsSeller extends TradeTask {
protected void run() {
try {
runInterceptHook();
log.debug("getContractAsJson");
log.debug("----------");
log.debug(trade.getContractAsJson());
log.debug("----------");
log.info("\n\n------------------------------------------------------------\n"
+ "Contract as json\n"
+ trade.getContractAsJson()
+ "\n------------------------------------------------------------\n");
byte[] contractHash = Hash.getHash(trade.getContractAsJson());
trade.setContractHash(contractHash);

View file

@ -41,7 +41,7 @@ public class BroadcastTakeOfferFeeTx extends TradeTask {
new FutureCallback<Transaction>() {
@Override
public void onSuccess(Transaction transaction) {
log.debug("Take offer fee published successfully. Transaction ID = " + transaction.getHashAsString());
log.debug("Trading fee published successfully. Transaction ID = " + transaction.getHashAsString());
trade.setState(Trade.State.TAKER_FEE_PAID);
complete();
@ -49,7 +49,7 @@ public class BroadcastTakeOfferFeeTx extends TradeTask {
@Override
public void onFailure(@NotNull Throwable t) {
appendToErrorMessage("Take offer fee payment failed. Maybe your network connection was lost. Please try again.");
appendToErrorMessage("Trading fee payment failed. Maybe your network connection was lost. Please try again.");
failed(t);
}
});

View file

@ -47,10 +47,10 @@ public class VerifyAndSignContract extends TradeTask {
PaymentAccountContractData offererPaymentAccountContractData = offerer.getPaymentAccountContractData();
PaymentAccountContractData takerPaymentAccountContractData = processModel.getPaymentAccountContractData(trade);
boolean isBuyerOffererOrSellerTaker = trade instanceof SellerAsTakerTrade;
Address buyerAddress = isBuyerOffererOrSellerTaker ? processModel.getTempTradingPeerAddress() : processModel.getMyAddress();
Address sellerAddress = isBuyerOffererOrSellerTaker ? processModel.getMyAddress() : processModel.getTempTradingPeerAddress();
log.debug("isBuyerOffererOrSellerTaker " + isBuyerOffererOrSellerTaker);
boolean isBuyerOffererAndSellerTaker = trade instanceof SellerAsTakerTrade;
Address buyerAddress = isBuyerOffererAndSellerTaker ? processModel.getTempTradingPeerAddress() : processModel.getMyAddress();
Address sellerAddress = isBuyerOffererAndSellerTaker ? processModel.getMyAddress() : processModel.getTempTradingPeerAddress();
log.debug("isBuyerOffererAndSellerTaker " + isBuyerOffererAndSellerTaker);
log.debug("buyerAddress " + buyerAddress);
log.debug("sellerAddress " + sellerAddress);
@ -61,7 +61,7 @@ public class VerifyAndSignContract extends TradeTask {
buyerAddress,
sellerAddress,
trade.getArbitratorAddress(),
isBuyerOffererOrSellerTaker,
isBuyerOffererAndSellerTaker,
offerer.getAccountId(),
processModel.getAccountId(),
offererPaymentAccountContractData,

View file

@ -67,7 +67,6 @@ public class User implements Serializable {
private Alert displayedAlert;
@Nullable
private List<Arbitrator> acceptedArbitrators = new ArrayList<>();
@Nullable
private Arbitrator registeredArbitrator;
@ -244,7 +243,6 @@ public class User implements Serializable {
return registeredArbitrator;
}
@Nullable
public List<Arbitrator> getAcceptedArbitrators() {
return acceptedArbitrators;
}