mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-29 01:38:39 -04:00
get trade account payloads over grpc, support crypto account forms
This commit is contained in:
parent
1f61e82946
commit
0d981a2df6
32 changed files with 292 additions and 295 deletions
|
@ -502,14 +502,18 @@ public class CoreApi {
|
|||
return paymentAccountsService.getPaymentAccounts();
|
||||
}
|
||||
|
||||
public List<PaymentMethod> getFiatPaymentMethods() {
|
||||
return paymentAccountsService.getFiatPaymentMethods();
|
||||
public List<PaymentMethod> getPaymentMethods() {
|
||||
return paymentAccountsService.getPaymentMethods();
|
||||
}
|
||||
|
||||
public PaymentAccountForm getPaymentAccountForm(String paymentMethodId) {
|
||||
return paymentAccountsService.getPaymentAccountForm(paymentMethodId);
|
||||
}
|
||||
|
||||
public PaymentAccountForm getPaymentAccountForm(PaymentAccount paymentAccount) {
|
||||
return paymentAccountsService.getPaymentAccountForm(paymentAccount);
|
||||
}
|
||||
|
||||
public PaymentAccount createCryptoCurrencyPaymentAccount(String accountName,
|
||||
String currencyCode,
|
||||
String address,
|
||||
|
|
|
@ -19,7 +19,6 @@ package bisq.core.api;
|
|||
|
||||
import bisq.core.account.witness.AccountAgeWitnessService;
|
||||
import bisq.core.api.model.PaymentAccountForm;
|
||||
import bisq.core.api.model.PaymentAccountForm;
|
||||
import bisq.core.api.model.PaymentAccountFormField;
|
||||
import bisq.core.locale.CryptoCurrency;
|
||||
import bisq.core.locale.CurrencyUtil;
|
||||
|
@ -64,8 +63,6 @@ class CorePaymentAccountsService {
|
|||
this.user = user;
|
||||
}
|
||||
|
||||
// Fiat Currency Accounts
|
||||
|
||||
PaymentAccount createPaymentAccount(PaymentAccountForm form) {
|
||||
PaymentAccount paymentAccount = form.toPaymentAccount();
|
||||
setSelectedTradeCurrency(paymentAccount); // TODO: selected trade currency is function of offer, not payment account payload
|
||||
|
@ -81,12 +78,15 @@ class CorePaymentAccountsService {
|
|||
private static void setSelectedTradeCurrency(PaymentAccount paymentAccount) {
|
||||
TradeCurrency singleTradeCurrency = paymentAccount.getSingleTradeCurrency();
|
||||
List<TradeCurrency> tradeCurrencies = paymentAccount.getTradeCurrencies();
|
||||
if (singleTradeCurrency != null) return;
|
||||
else if (tradeCurrencies != null && !tradeCurrencies.isEmpty()) {
|
||||
if (tradeCurrencies.contains(CurrencyUtil.getDefaultTradeCurrency()))
|
||||
if (singleTradeCurrency != null) {
|
||||
paymentAccount.setSelectedTradeCurrency(singleTradeCurrency);
|
||||
return;
|
||||
} else if (tradeCurrencies != null && !tradeCurrencies.isEmpty()) {
|
||||
if (tradeCurrencies.contains(CurrencyUtil.getDefaultTradeCurrency())) {
|
||||
paymentAccount.setSelectedTradeCurrency(CurrencyUtil.getDefaultTradeCurrency());
|
||||
else
|
||||
} else {
|
||||
paymentAccount.setSelectedTradeCurrency(tradeCurrencies.get(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,9 +94,8 @@ class CorePaymentAccountsService {
|
|||
return user.getPaymentAccounts();
|
||||
}
|
||||
|
||||
List<PaymentMethod> getFiatPaymentMethods() {
|
||||
List<PaymentMethod> getPaymentMethods() {
|
||||
return PaymentMethod.getPaymentMethods().stream()
|
||||
.filter(paymentMethod -> !paymentMethod.isBlockchain())
|
||||
.sorted(Comparator.comparing(PaymentMethod::getId))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
@ -105,6 +104,10 @@ class CorePaymentAccountsService {
|
|||
return PaymentAccountForm.getForm(paymentMethodId);
|
||||
}
|
||||
|
||||
PaymentAccountForm getPaymentAccountForm(PaymentAccount paymentAccount) {
|
||||
return paymentAccount.toForm();
|
||||
}
|
||||
|
||||
String getPaymentAccountFormAsString(String paymentMethodId) {
|
||||
File jsonForm = getPaymentAccountFormFile(paymentMethodId);
|
||||
jsonForm.deleteOnExit(); // If just asking for a string, delete the form file.
|
||||
|
|
|
@ -18,13 +18,13 @@
|
|||
package bisq.core.api.model;
|
||||
|
||||
import bisq.common.Payload;
|
||||
import bisq.core.payment.payload.PaymentAccountPayload;
|
||||
import bisq.core.proto.CoreProtoResolver;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import static bisq.core.api.model.PaymentAccountPayloadInfo.emptyPaymentAccountPayload;
|
||||
|
||||
/**
|
||||
* A lightweight Trade Contract constructed from a trade's json contract.
|
||||
* Many fields in the core Contract are ignored, but can be added as needed.
|
||||
|
@ -38,8 +38,8 @@ public class ContractInfo implements Payload {
|
|||
private final boolean isBuyerMakerAndSellerTaker;
|
||||
private final String makerAccountId;
|
||||
private final String takerAccountId;
|
||||
private final PaymentAccountPayloadInfo makerPaymentAccountPayload;
|
||||
private final PaymentAccountPayloadInfo takerPaymentAccountPayload;
|
||||
private final PaymentAccountPayload makerPaymentAccountPayload;
|
||||
private final PaymentAccountPayload takerPaymentAccountPayload;
|
||||
private final String makerPayoutAddressString;
|
||||
private final String takerPayoutAddressString;
|
||||
private final long lockTime;
|
||||
|
@ -50,8 +50,8 @@ public class ContractInfo implements Payload {
|
|||
boolean isBuyerMakerAndSellerTaker,
|
||||
String makerAccountId,
|
||||
String takerAccountId,
|
||||
PaymentAccountPayloadInfo makerPaymentAccountPayload,
|
||||
PaymentAccountPayloadInfo takerPaymentAccountPayload,
|
||||
PaymentAccountPayload makerPaymentAccountPayload,
|
||||
PaymentAccountPayload takerPaymentAccountPayload,
|
||||
String makerPayoutAddressString,
|
||||
String takerPayoutAddressString,
|
||||
long lockTime) {
|
||||
|
@ -77,8 +77,8 @@ public class ContractInfo implements Payload {
|
|||
false,
|
||||
"",
|
||||
"",
|
||||
emptyPaymentAccountPayload.get(),
|
||||
emptyPaymentAccountPayload.get(),
|
||||
null,
|
||||
null,
|
||||
"",
|
||||
"",
|
||||
0);
|
||||
|
@ -88,14 +88,15 @@ public class ContractInfo implements Payload {
|
|||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static ContractInfo fromProto(bisq.proto.grpc.ContractInfo proto) {
|
||||
CoreProtoResolver coreProtoResolver = new CoreProtoResolver();
|
||||
return new ContractInfo(proto.getBuyerNodeAddress(),
|
||||
proto.getSellerNodeAddress(),
|
||||
proto.getArbitratorNodeAddress(),
|
||||
proto.getIsBuyerMakerAndSellerTaker(),
|
||||
proto.getMakerAccountId(),
|
||||
proto.getTakerAccountId(),
|
||||
proto.getMakerPaymentAccountPayload() == null ? null : PaymentAccountPayloadInfo.fromProto(proto.getMakerPaymentAccountPayload()),
|
||||
proto.getTakerPaymentAccountPayload() == null ? null : PaymentAccountPayloadInfo.fromProto(proto.getTakerPaymentAccountPayload()),
|
||||
proto.getMakerPaymentAccountPayload() == null ? null : PaymentAccountPayload.fromProto(proto.getMakerPaymentAccountPayload(), coreProtoResolver),
|
||||
proto.getTakerPaymentAccountPayload() == null ? null : PaymentAccountPayload.fromProto(proto.getTakerPaymentAccountPayload(), coreProtoResolver),
|
||||
proto.getMakerPayoutAddressString(),
|
||||
proto.getTakerPayoutAddressString(),
|
||||
proto.getLockTime());
|
||||
|
@ -113,8 +114,8 @@ public class ContractInfo implements Payload {
|
|||
.setMakerPayoutAddressString(makerPayoutAddressString)
|
||||
.setTakerPayoutAddressString(takerPayoutAddressString)
|
||||
.setLockTime(lockTime);
|
||||
if (makerPaymentAccountPayload != null) builder.setMakerPaymentAccountPayload(makerPaymentAccountPayload.toProtoMessage());
|
||||
if (takerPaymentAccountPayload != null) builder.setTakerPaymentAccountPayload(takerPaymentAccountPayload.toProtoMessage());
|
||||
if (makerPaymentAccountPayload != null) builder.setMakerPaymentAccountPayload((protobuf.PaymentAccountPayload) makerPaymentAccountPayload.toProtoMessage());
|
||||
if (takerPaymentAccountPayload != null) builder.setTakerPaymentAccountPayload((protobuf.PaymentAccountPayload) takerPaymentAccountPayload.toProtoMessage());
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
package bisq.core.api.model;
|
||||
|
||||
import static bisq.core.payment.payload.PaymentMethod.getPaymentMethod;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static java.lang.String.format;
|
||||
import static java.lang.System.getProperty;
|
||||
|
@ -28,15 +27,14 @@ import bisq.common.proto.persistable.PersistablePayload;
|
|||
import bisq.core.payment.PaymentAccount;
|
||||
import bisq.core.payment.PaymentAccountFactory;
|
||||
import bisq.core.payment.payload.PaymentMethod;
|
||||
import bisq.core.trade.HavenoUtils;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.CaseFormat;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Files;
|
||||
|
@ -60,11 +58,8 @@ import org.apache.commons.lang3.StringUtils;
|
|||
@Slf4j
|
||||
public final class PaymentAccountForm implements PersistablePayload {
|
||||
|
||||
private static final GsonBuilder gsonBuilder = new GsonBuilder()
|
||||
.setPrettyPrinting()
|
||||
.serializeNulls();
|
||||
|
||||
public enum FormId {
|
||||
BLOCK_CHAINS,
|
||||
REVOLUT,
|
||||
SEPA,
|
||||
SEPA_INSTANT,
|
||||
|
@ -113,6 +108,10 @@ public final class PaymentAccountForm implements PersistablePayload {
|
|||
return new PaymentAccountForm(FormId.fromProto(proto.getId()), fields);
|
||||
}
|
||||
|
||||
public void addField(PaymentAccountFormField field) {
|
||||
fields.add(field);
|
||||
}
|
||||
|
||||
public String getValue(PaymentAccountFormField.FieldId fieldId) {
|
||||
for (PaymentAccountFormField field : fields) {
|
||||
if (field.getId() == fieldId) {
|
||||
|
@ -122,14 +121,6 @@ public final class PaymentAccountForm implements PersistablePayload {
|
|||
throw new IllegalArgumentException("Form does not contain field " + fieldId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a structured form for the given payment method.
|
||||
*/
|
||||
public static PaymentAccountForm getForm(String paymentMethodId) {
|
||||
PaymentAccount paymentAccount = PaymentAccountFactory.getPaymentAccount(PaymentMethod.getPaymentMethod(paymentMethodId));
|
||||
return paymentAccount.toForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert this form to a PaymentAccount json string.
|
||||
*/
|
||||
|
@ -137,7 +128,7 @@ public final class PaymentAccountForm implements PersistablePayload {
|
|||
Map<String, Object> formMap = new HashMap<String, Object>();
|
||||
formMap.put("paymentMethodId", getId().toString());
|
||||
for (PaymentAccountFormField field : getFields()) {
|
||||
formMap.put(toCamelCase(field.getId().toString()), field.getValue());
|
||||
formMap.put(HavenoUtils.toCamelCase(field.getId().toString()), field.getValue());
|
||||
}
|
||||
return new Gson().toJson(formMap);
|
||||
}
|
||||
|
@ -146,19 +137,15 @@ public final class PaymentAccountForm implements PersistablePayload {
|
|||
* Convert this form to a PaymentAccount.
|
||||
*/
|
||||
public PaymentAccount toPaymentAccount() {
|
||||
return toPaymentAccount(toPaymentAccountJsonString());
|
||||
return PaymentAccount.fromJson(toPaymentAccountJsonString());
|
||||
}
|
||||
|
||||
/**
|
||||
* De-serialize a PaymentAccount json string into a new PaymentAccount instance.
|
||||
*
|
||||
* @param paymentAccountJsonString The json data representing a new payment account form.
|
||||
* @return A populated PaymentAccount subclass instance.
|
||||
* Get a structured form for the given payment method.
|
||||
*/
|
||||
public static PaymentAccount toPaymentAccount(String paymentAccountJsonString) {
|
||||
Class<? extends PaymentAccount> clazz = getPaymentAccountClassFromJson(paymentAccountJsonString);
|
||||
Gson gson = gsonBuilder.registerTypeAdapter(clazz, new PaymentAccountTypeAdapter(clazz)).create();
|
||||
return gson.fromJson(paymentAccountJsonString, clazz);
|
||||
public static PaymentAccountForm getForm(String paymentMethodId) {
|
||||
PaymentAccount paymentAccount = PaymentAccountFactory.getPaymentAccount(PaymentMethod.getPaymentMethod(paymentMethodId));
|
||||
return paymentAccount.toForm();
|
||||
}
|
||||
|
||||
// ----------------------------- OLD FORM API -----------------------------
|
||||
|
@ -170,7 +157,7 @@ public final class PaymentAccountForm implements PersistablePayload {
|
|||
* @return A uniquely named tmp file used to define new payment account details.
|
||||
*/
|
||||
public static File getPaymentAccountForm(String paymentMethodId) {
|
||||
PaymentMethod paymentMethod = getPaymentMethod(paymentMethodId);
|
||||
PaymentMethod paymentMethod = PaymentMethod.getPaymentMethod(paymentMethodId);
|
||||
File file = getTmpJsonFile(paymentMethodId);
|
||||
try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(checkNotNull(file), false), UTF_8)) {
|
||||
PaymentAccount paymentAccount = PaymentAccountFactory.getPaymentAccount(paymentMethod);
|
||||
|
@ -193,8 +180,7 @@ public final class PaymentAccountForm implements PersistablePayload {
|
|||
@SuppressWarnings("unused")
|
||||
@VisibleForTesting
|
||||
public static PaymentAccount toPaymentAccount(File jsonForm) {
|
||||
String jsonString = toJsonString(jsonForm);
|
||||
return toPaymentAccount(jsonString);
|
||||
return PaymentAccount.fromJson(toJsonString(jsonForm));
|
||||
}
|
||||
|
||||
public static String toJsonString(File jsonFile) {
|
||||
|
@ -243,22 +229,4 @@ public final class PaymentAccountForm implements PersistablePayload {
|
|||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
// -------------------------------- HELPERS -------------------------------
|
||||
|
||||
private static String toCamelCase(String underscore) {
|
||||
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, underscore);
|
||||
}
|
||||
|
||||
private static Class<? extends PaymentAccount> getPaymentAccountClassFromJson(String json) {
|
||||
Map<String, Object> jsonMap = gsonBuilder.create().fromJson(json, (Type) Object.class);
|
||||
String paymentMethodId = checkNotNull((String) jsonMap.get("paymentMethodId"),
|
||||
format("cannot not find a paymentMethodId in json string: %s", json));
|
||||
return getPaymentAccountClass(paymentMethodId);
|
||||
}
|
||||
|
||||
private static Class<? extends PaymentAccount> getPaymentAccountClass(String paymentMethodId) {
|
||||
PaymentMethod paymentMethod = getPaymentMethod(paymentMethodId);
|
||||
return PaymentAccountFactory.getPaymentAccount(paymentMethod).getClass();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ import javax.annotation.concurrent.Immutable;
|
|||
public final class PaymentAccountFormField implements PersistablePayload {
|
||||
|
||||
public enum FieldId {
|
||||
ADDRESS,
|
||||
ACCEPTED_COUNTRY_CODES,
|
||||
ACCOUNT_ID,
|
||||
ACCOUNT_NAME,
|
||||
|
@ -96,8 +97,7 @@ public final class PaymentAccountFormField implements PersistablePayload {
|
|||
SPECIAL_INSTRUCTIONS,
|
||||
STATE,
|
||||
TRADE_CURRENCIES,
|
||||
USER_NAME,
|
||||
VIRTUAL_PAYMENT_ADDRESS;
|
||||
USER_NAME;
|
||||
|
||||
public static PaymentAccountFormField.FieldId fromProto(protobuf.PaymentAccountFormField.FieldId fieldId) {
|
||||
return ProtoUtil.enumFromProto(PaymentAccountFormField.FieldId.class, fieldId.name());
|
||||
|
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* This file is part of Haveno.
|
||||
*
|
||||
* Haveno is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Haveno is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Haveno. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package bisq.core.api.model;
|
||||
|
||||
import bisq.core.payment.payload.CryptoCurrencyAccountPayload;
|
||||
import bisq.core.payment.payload.InstantCryptoCurrencyPayload;
|
||||
import bisq.core.payment.payload.PaymentAccountPayload;
|
||||
|
||||
import bisq.common.Payload;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@Getter
|
||||
public class PaymentAccountPayloadInfo implements Payload {
|
||||
|
||||
private final String id;
|
||||
private final String paymentMethodId;
|
||||
@Nullable
|
||||
private final String address;
|
||||
|
||||
public PaymentAccountPayloadInfo(String id,
|
||||
String paymentMethodId,
|
||||
@Nullable String address) {
|
||||
this.id = id;
|
||||
this.paymentMethodId = paymentMethodId;
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public static PaymentAccountPayloadInfo toPaymentAccountPayloadInfo(PaymentAccountPayload paymentAccountPayload) {
|
||||
if (paymentAccountPayload == null) return null;
|
||||
Optional<String> address = Optional.empty();
|
||||
if (paymentAccountPayload instanceof CryptoCurrencyAccountPayload)
|
||||
address = Optional.of(((CryptoCurrencyAccountPayload) paymentAccountPayload).getAddress());
|
||||
else if (paymentAccountPayload instanceof InstantCryptoCurrencyPayload)
|
||||
address = Optional.of(((InstantCryptoCurrencyPayload) paymentAccountPayload).getAddress());
|
||||
|
||||
return new PaymentAccountPayloadInfo(paymentAccountPayload.getId(),
|
||||
paymentAccountPayload.getPaymentMethodId(),
|
||||
address.orElse(""));
|
||||
}
|
||||
|
||||
// For transmitting TradeInfo messages when no contract & payloads are available.
|
||||
public static Supplier<PaymentAccountPayloadInfo> emptyPaymentAccountPayload = () ->
|
||||
new PaymentAccountPayloadInfo("", "", "");
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PROTO BUFFER
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static PaymentAccountPayloadInfo fromProto(bisq.proto.grpc.PaymentAccountPayloadInfo proto) {
|
||||
return new PaymentAccountPayloadInfo(proto.getId(), proto.getPaymentMethodId(), proto.getAddress());
|
||||
}
|
||||
|
||||
@Override
|
||||
public bisq.proto.grpc.PaymentAccountPayloadInfo toProtoMessage() {
|
||||
return bisq.proto.grpc.PaymentAccountPayloadInfo.newBuilder()
|
||||
.setId(id)
|
||||
.setPaymentMethodId(paymentMethodId)
|
||||
.setAddress(address != null ? address : "")
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -28,7 +28,6 @@ import lombok.EqualsAndHashCode;
|
|||
import lombok.Getter;
|
||||
|
||||
import static bisq.core.api.model.OfferInfo.toOfferInfo;
|
||||
import static bisq.core.api.model.PaymentAccountPayloadInfo.toPaymentAccountPayloadInfo;
|
||||
import static bisq.core.util.PriceUtil.reformatMarketPrice;
|
||||
import static bisq.core.util.VolumeUtil.formatVolume;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
@ -141,8 +140,8 @@ public class TradeInfo implements Payload {
|
|||
contract.isBuyerMakerAndSellerTaker(),
|
||||
contract.getMakerAccountId(),
|
||||
contract.getTakerAccountId(),
|
||||
toPaymentAccountPayloadInfo(trade.getMaker().getPaymentAccountPayload()),
|
||||
toPaymentAccountPayloadInfo(trade.getTaker().getPaymentAccountPayload()),
|
||||
trade.getMaker().getPaymentAccountPayload(),
|
||||
trade.getTaker().getPaymentAccountPayload(),
|
||||
contract.getMakerPayoutAddressString(),
|
||||
contract.getTakerPayoutAddressString(),
|
||||
contract.getLockTime());
|
||||
|
|
|
@ -611,11 +611,11 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
|||
}
|
||||
|
||||
public Optional<OpenOffer> getOpenOfferById(String offerId) {
|
||||
return openOffers.stream().filter(e -> e.getId().equals(offerId)).findFirst();
|
||||
return openOffers.getObservableList().stream().filter(e -> e.getId().equals(offerId)).findFirst();
|
||||
}
|
||||
|
||||
public Optional<SignedOffer> getSignedOfferById(String offerId) {
|
||||
return signedOffers.stream().filter(e -> e.getOfferId().equals(offerId)).findFirst();
|
||||
return signedOffers.getObservableList().stream().filter(e -> e.getOfferId().equals(offerId)).findFirst();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
package bisq.core.payment;
|
||||
|
||||
import bisq.core.payment.payload.AssetsAccountPayload;
|
||||
import bisq.core.payment.payload.AssetAccountPayload;
|
||||
import bisq.core.payment.payload.PaymentMethod;
|
||||
|
||||
public abstract class AssetAccount extends PaymentAccount {
|
||||
|
@ -26,10 +26,10 @@ public abstract class AssetAccount extends PaymentAccount {
|
|||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
((AssetsAccountPayload) paymentAccountPayload).setAddress(address);
|
||||
((AssetAccountPayload) paymentAccountPayload).setAddress(address);
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return ((AssetsAccountPayload) paymentAccountPayload).getAddress();
|
||||
return ((AssetAccountPayload) paymentAccountPayload).getAddress();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import bisq.core.payment.payload.CountryBasedPaymentAccountPayload;
|
|||
import bisq.core.payment.payload.PaymentMethod;
|
||||
import java.util.List;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NonNull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -35,17 +34,14 @@ public abstract class CountryBasedPaymentAccount extends PaymentAccount {
|
|||
@Nullable
|
||||
protected List<Country> acceptedCountries;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
protected CountryBasedPaymentAccount(PaymentMethod paymentMethod) {
|
||||
super(paymentMethod);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Getter, Setter
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -33,6 +33,13 @@ import lombok.NonNull;
|
|||
@EqualsAndHashCode(callSuper = true)
|
||||
public final class CryptoCurrencyAccount extends AssetAccount {
|
||||
|
||||
private static final List<PaymentAccountFormField.FieldId> INPUT_FIELD_IDS = List.of(
|
||||
PaymentAccountFormField.FieldId.ACCOUNT_NAME,
|
||||
PaymentAccountFormField.FieldId.TRADE_CURRENCIES,
|
||||
PaymentAccountFormField.FieldId.ADDRESS,
|
||||
PaymentAccountFormField.FieldId.SALT
|
||||
);
|
||||
|
||||
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = new ArrayList<>(CurrencyUtil.getAllSortedCryptoCurrencies());
|
||||
|
||||
public CryptoCurrencyAccount() {
|
||||
|
@ -51,6 +58,13 @@ public final class CryptoCurrencyAccount extends AssetAccount {
|
|||
|
||||
@Override
|
||||
public @NonNull List<PaymentAccountFormField.FieldId> getInputFieldIds() {
|
||||
throw new RuntimeException("Not implemented");
|
||||
return INPUT_FIELD_IDS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PaymentAccountFormField getEmptyFormField(PaymentAccountFormField.FieldId fieldId) {
|
||||
var field = super.getEmptyFormField(fieldId);
|
||||
if (field.getId() == PaymentAccountFormField.FieldId.TRADE_CURRENCIES) field.setComponent(PaymentAccountFormField.Component.SELECT_ONE);
|
||||
return field;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,11 +19,12 @@ package bisq.core.payment;
|
|||
|
||||
import bisq.core.api.model.PaymentAccountForm;
|
||||
import bisq.core.api.model.PaymentAccountFormField;
|
||||
import bisq.core.api.model.PaymentAccountFormField.Component;
|
||||
import bisq.core.api.model.PaymentAccountFormField.FieldId;
|
||||
import bisq.core.locale.BankUtil;
|
||||
import bisq.core.locale.Country;
|
||||
import bisq.core.locale.CountryUtil;
|
||||
import bisq.core.locale.CurrencyUtil;
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.locale.TradeCurrency;
|
||||
import bisq.core.payment.payload.PaymentAccountPayload;
|
||||
import bisq.core.payment.payload.PaymentMethod;
|
||||
|
@ -35,6 +36,7 @@ import bisq.core.payment.validation.EmailValidator;
|
|||
import bisq.core.payment.validation.IBANValidator;
|
||||
import bisq.core.payment.validation.LengthValidator;
|
||||
import bisq.core.proto.CoreProtoResolver;
|
||||
import bisq.core.trade.HavenoUtils;
|
||||
import bisq.core.util.validation.InputValidator;
|
||||
import bisq.core.util.validation.InputValidator.ValidationResult;
|
||||
import bisq.common.proto.ProtoUtil;
|
||||
|
@ -43,7 +45,9 @@ import bisq.common.util.Utilities;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
|
@ -59,12 +63,17 @@ import lombok.extern.slf4j.Slf4j;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import static bisq.core.payment.payload.PaymentMethod.TRANSFERWISE_ID;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static java.util.Arrays.stream;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
@Getter
|
||||
|
@ -89,6 +98,10 @@ public abstract class PaymentAccount implements PersistablePayload {
|
|||
@Nullable
|
||||
protected TradeCurrency selectedTradeCurrency;
|
||||
|
||||
private static final GsonBuilder gsonBuilder = new GsonBuilder()
|
||||
.setPrettyPrinting()
|
||||
.serializeNulls();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
|
@ -104,6 +117,12 @@ public abstract class PaymentAccount implements PersistablePayload {
|
|||
paymentAccountPayload = createPayload();
|
||||
}
|
||||
|
||||
public void init(PaymentAccountPayload payload) {
|
||||
id = payload.getId();
|
||||
creationDate = new Date().getTime();
|
||||
paymentAccountPayload = payload;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PROTO BUFFER
|
||||
|
@ -123,6 +142,19 @@ public abstract class PaymentAccount implements PersistablePayload {
|
|||
return builder.build();
|
||||
}
|
||||
|
||||
public protobuf.PaymentAccount toProtoMessage(protobuf.PaymentAccountPayload paymentAccountPayload) {
|
||||
checkNotNull(accountName, "accountName must not be null");
|
||||
protobuf.PaymentAccount.Builder builder = protobuf.PaymentAccount.newBuilder()
|
||||
.setPaymentMethod(paymentMethod.toProtoMessage())
|
||||
.setId(id)
|
||||
.setCreationDate(creationDate)
|
||||
.setPaymentAccountPayload(paymentAccountPayload)
|
||||
.setAccountName(accountName)
|
||||
.addAllTradeCurrencies(ProtoUtil.collectionToProto(tradeCurrencies, protobuf.TradeCurrency.class));
|
||||
Optional.ofNullable(selectedTradeCurrency).ifPresent(selectedTradeCurrency -> builder.setSelectedTradeCurrency((protobuf.TradeCurrency) selectedTradeCurrency.toProtoMessage()));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static PaymentAccount fromProto(protobuf.PaymentAccount proto, CoreProtoResolver coreProtoResolver) {
|
||||
String paymentMethodId = proto.getPaymentMethod().getId();
|
||||
List<TradeCurrency> tradeCurrencies = proto.getTradeCurrenciesList().stream()
|
||||
|
@ -286,15 +318,56 @@ public abstract class PaymentAccount implements PersistablePayload {
|
|||
@NonNull
|
||||
public abstract List<TradeCurrency> getSupportedCurrencies();
|
||||
|
||||
// ---------------------------- SERIALIZATION -----------------------------
|
||||
|
||||
public String toJson() {
|
||||
Map<String, Object> jsonMap = new HashMap<String, Object>();
|
||||
if (paymentAccountPayload != null) jsonMap.putAll(gsonBuilder.create().fromJson(paymentAccountPayload.toJson(), (Type) Object.class));
|
||||
jsonMap.put("accountName", getAccountName());
|
||||
jsonMap.put("accountId", getId());
|
||||
if (paymentAccountPayload != null) jsonMap.put("salt", getSaltAsHex());
|
||||
return gsonBuilder.create().toJson(jsonMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize a PaymentAccount json string into a new PaymentAccount instance.
|
||||
*
|
||||
* @param paymentAccountJsonString The json data representing a new payment account form.
|
||||
* @return A populated PaymentAccount subclass instance.
|
||||
*/
|
||||
public static PaymentAccount fromJson(String paymentAccountJsonString) {
|
||||
Class<? extends PaymentAccount> clazz = getPaymentAccountClassFromJson(paymentAccountJsonString);
|
||||
Gson gson = gsonBuilder.registerTypeAdapter(clazz, new PaymentAccountTypeAdapter(clazz)).create();
|
||||
return gson.fromJson(paymentAccountJsonString, clazz);
|
||||
}
|
||||
|
||||
private static Class<? extends PaymentAccount> getPaymentAccountClassFromJson(String json) {
|
||||
Map<String, Object> jsonMap = gsonBuilder.create().fromJson(json, (Type) Object.class);
|
||||
String paymentMethodId = checkNotNull((String) jsonMap.get("paymentMethodId"),
|
||||
String.format("cannot not find a paymentMethodId in json string: %s", json));
|
||||
return getPaymentAccountClass(paymentMethodId);
|
||||
}
|
||||
|
||||
private static Class<? extends PaymentAccount> getPaymentAccountClass(String paymentMethodId) {
|
||||
PaymentMethod paymentMethod = PaymentMethod.getPaymentMethod(paymentMethodId);
|
||||
return PaymentAccountFactory.getPaymentAccount(paymentMethod).getClass();
|
||||
}
|
||||
|
||||
// ------------------------- PAYMENT ACCOUNT FORM -------------------------
|
||||
|
||||
@NonNull
|
||||
public abstract List<PaymentAccountFormField.FieldId> getInputFieldIds();
|
||||
|
||||
public PaymentAccountForm toForm() {
|
||||
|
||||
// convert to json map
|
||||
Map<String, Object> jsonMap = gsonBuilder.create().fromJson(toJson(), (Type) Object.class);
|
||||
|
||||
// build form
|
||||
PaymentAccountForm form = new PaymentAccountForm(PaymentAccountForm.FormId.valueOf(paymentMethod.getId()));
|
||||
for (PaymentAccountFormField.FieldId fieldId : getInputFieldIds()) {
|
||||
PaymentAccountFormField field = getEmptyFormField(fieldId);
|
||||
field.setValue((String) jsonMap.get(HavenoUtils.toCamelCase(field.getId().toString())));
|
||||
form.getFields().add(field);
|
||||
}
|
||||
return form;
|
||||
|
@ -463,8 +536,9 @@ public abstract class PaymentAccount implements PersistablePayload {
|
|||
case USER_NAME:
|
||||
processValidationResult(new LengthValidator(3, 100).validate(value));
|
||||
break;
|
||||
case VIRTUAL_PAYMENT_ADDRESS:
|
||||
throw new IllegalArgumentException("Not implemented");
|
||||
case ADDRESS:
|
||||
processValidationResult(new LengthValidator(10, 150).validate(value)); // TODO: validate crypto address
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unhandled form field: " + fieldId);
|
||||
}
|
||||
|
@ -673,8 +747,12 @@ public abstract class PaymentAccount implements PersistablePayload {
|
|||
field.setMinLength(3);
|
||||
field.setMaxLength(100);
|
||||
break;
|
||||
case VIRTUAL_PAYMENT_ADDRESS:
|
||||
throw new IllegalArgumentException("Not implemented");
|
||||
case ADDRESS:
|
||||
field.setComponent(PaymentAccountFormField.Component.TEXT);
|
||||
field.setLabel("Address");
|
||||
field.setMinLength(10);
|
||||
field.setMaxLength(150);
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unhandled form field: " + field);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
* along with Haveno. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package bisq.core.api.model;
|
||||
package bisq.core.payment;
|
||||
|
||||
|
||||
import bisq.core.locale.Country;
|
||||
|
@ -23,9 +23,6 @@ import bisq.core.locale.CountryUtil;
|
|||
import bisq.core.locale.FiatCurrency;
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.locale.TradeCurrency;
|
||||
import bisq.core.payment.CountryBasedPaymentAccount;
|
||||
import bisq.core.payment.MoneyGramAccount;
|
||||
import bisq.core.payment.PaymentAccount;
|
||||
import bisq.core.payment.payload.PaymentAccountPayload;
|
||||
|
||||
import com.google.gson.TypeAdapter;
|
||||
|
@ -156,13 +153,10 @@ class PaymentAccountTypeAdapter extends TypeAdapter<PaymentAccount> {
|
|||
field.getType().getSimpleName(),
|
||||
field.getName(),
|
||||
value);
|
||||
|
||||
String fieldName = field.getName();
|
||||
out.name(fieldName);
|
||||
if (fieldName.equals("country"))
|
||||
out.value("your two letter country code");
|
||||
else
|
||||
out.value("your " + fieldName.toLowerCase());
|
||||
if (fieldName.equals("country")) out.value("your two letter country code");
|
||||
else out.value("your " + fieldName.toLowerCase());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
String errMsg = format("cannot create a new %s json form",
|
|
@ -24,7 +24,6 @@ import bisq.core.payment.payload.PaymentAccountPayload;
|
|||
import bisq.core.payment.payload.PaymentMethod;
|
||||
import bisq.core.payment.payload.RevolutAccountPayload;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NonNull;
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ import bisq.core.payment.payload.PaymentMethod;
|
|||
import bisq.core.payment.payload.TransferwiseAccountPayload;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NonNull;
|
||||
|
||||
|
|
|
@ -34,10 +34,10 @@ import lombok.extern.slf4j.Slf4j;
|
|||
@Setter
|
||||
@Getter
|
||||
@Slf4j
|
||||
public abstract class AssetsAccountPayload extends PaymentAccountPayload {
|
||||
public abstract class AssetAccountPayload extends PaymentAccountPayload {
|
||||
protected String address = "";
|
||||
|
||||
protected AssetsAccountPayload(String paymentMethod, String id) {
|
||||
protected AssetAccountPayload(String paymentMethod, String id) {
|
||||
super(paymentMethod, id);
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ public abstract class AssetsAccountPayload extends PaymentAccountPayload {
|
|||
// PROTO BUFFER
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
protected AssetsAccountPayload(String paymentMethod,
|
||||
protected AssetAccountPayload(String paymentMethod,
|
||||
String id,
|
||||
String address,
|
||||
long maxTradePeriod,
|
|
@ -33,7 +33,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
@Setter
|
||||
@Getter
|
||||
@Slf4j
|
||||
public final class CryptoCurrencyAccountPayload extends AssetsAccountPayload {
|
||||
public final class CryptoCurrencyAccountPayload extends AssetAccountPayload {
|
||||
|
||||
public CryptoCurrencyAccountPayload(String paymentMethod, String id) {
|
||||
super(paymentMethod, id);
|
||||
|
|
|
@ -33,7 +33,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
@Setter
|
||||
@Getter
|
||||
@Slf4j
|
||||
public final class InstantCryptoCurrencyPayload extends AssetsAccountPayload {
|
||||
public final class InstantCryptoCurrencyPayload extends AssetAccountPayload {
|
||||
|
||||
public InstantCryptoCurrencyPayload(String paymentMethod, String id) {
|
||||
super(paymentMethod, id);
|
||||
|
|
|
@ -23,9 +23,12 @@ import bisq.common.crypto.Hash;
|
|||
import bisq.common.proto.network.NetworkPayload;
|
||||
import bisq.common.util.JsonExclude;
|
||||
import bisq.common.util.Utilities;
|
||||
import bisq.core.proto.CoreProtoResolver;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -66,6 +69,10 @@ public abstract class PaymentAccountPayload implements NetworkPayload, UsedForTr
|
|||
@JsonExclude
|
||||
protected final Map<String, String> excludeFromJsonDataMap;
|
||||
|
||||
private static final GsonBuilder gsonBuilder = new GsonBuilder()
|
||||
.setPrettyPrinting()
|
||||
.serializeNulls();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
|
@ -109,11 +116,18 @@ public abstract class PaymentAccountPayload implements NetworkPayload, UsedForTr
|
|||
return builder;
|
||||
}
|
||||
|
||||
public static PaymentAccountPayload fromProto(protobuf.PaymentAccountPayload proto, CoreProtoResolver coreProtoResolver) {
|
||||
return coreProtoResolver.fromProto(proto);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// API
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public String toJson() {
|
||||
return gsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
public abstract String getPaymentDetails();
|
||||
|
||||
public abstract String getPaymentDetailsForTradePopup();
|
||||
|
|
|
@ -331,6 +331,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable<Payme
|
|||
// TODO: delete this override method, which overrides the paymentMethods variable, when all payment methods supported using structured form api, and make paymentMethods private
|
||||
public static final List<PaymentMethod> getPaymentMethods() {
|
||||
List<String> paymentMethodIds = List.of(
|
||||
BLOCK_CHAINS_ID,
|
||||
REVOLUT_ID,
|
||||
SEPA_ID,
|
||||
SEPA_INSTANT_ID,
|
||||
|
|
|
@ -36,6 +36,7 @@ import java.util.concurrent.ExecutorService;
|
|||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
/**
|
||||
|
@ -225,6 +226,7 @@ public class HavenoUtils {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: replace with GenUtils.executeTasks()
|
||||
public static void executeTasks(Collection<Runnable> tasks) {
|
||||
executeTasks(tasks, tasks.size());
|
||||
}
|
||||
|
@ -241,4 +243,8 @@ public class HavenoUtils {
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String toCamelCase(String underscore) {
|
||||
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, underscore);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -750,7 +750,7 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
|
|||
handleTaskRunnerSuccess(null, null, "SendDepositsConfirmedMessages");
|
||||
},
|
||||
(errorMessage) -> {
|
||||
handleTaskRunnerFault(null, null, errorMessage);
|
||||
handleTaskRunnerFault(null, null, "SendDepositsConfirmedMessages", errorMessage);
|
||||
})))
|
||||
.executeTasks(true);
|
||||
awaitTradeLatch();
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
package bisq.core.trade.txproof.xmr;
|
||||
|
||||
import bisq.core.monetary.Volume;
|
||||
import bisq.core.payment.payload.AssetsAccountPayload;
|
||||
import bisq.core.payment.payload.AssetAccountPayload;
|
||||
import bisq.core.payment.payload.PaymentAccountPayload;
|
||||
import bisq.core.trade.Trade;
|
||||
import bisq.core.trade.txproof.AssetTxProofModel;
|
||||
|
@ -26,8 +26,6 @@ import bisq.core.user.AutoConfirmSettings;
|
|||
|
||||
import bisq.common.app.DevEnv;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import java.util.Date;
|
||||
|
@ -67,7 +65,7 @@ public class XmrTxProofModel implements AssetTxProofModel {
|
|||
PaymentAccountPayload sellersPaymentAccountPayload = checkNotNull(trade.getSeller().getPaymentAccountPayload());
|
||||
recipientAddress = DevEnv.isDevMode() ?
|
||||
XmrTxProofModel.DEV_ADDRESS : // For dev testing we need to add the matching address to the dev tx key and dev view key
|
||||
((AssetsAccountPayload) sellersPaymentAccountPayload).getAddress();
|
||||
((AssetAccountPayload) sellersPaymentAccountPayload).getAddress();
|
||||
txHash = trade.getCounterCurrencyTxId();
|
||||
txKey = trade.getCounterCurrencyExtraData();
|
||||
tradeDate = trade.getDate();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue