Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add altcoin payment method for live trading #2490

Merged
merged 8 commits into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions common/src/main/proto/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ message PaymentAccountPayload {
HalCashAccountPayload hal_cash_account_payload = 24;
PromptPayAccountPayload prompt_pay_account_payload = 25;
AdvancedCashAccountPayload advanced_cash_account_payload = 26;
InstantCryptoCurrencyAccountPayload instant_crypto_currency_account_payload = 27;
}
map<string, string> exclude_from_json_data = 15;
}
Expand Down Expand Up @@ -836,6 +837,10 @@ message CryptoCurrencyAccountPayload {
string address = 1;
}

message InstantCryptoCurrencyAccountPayload {
string address = 1;
}

message FasterPaymentsAccountPayload {
string sort_code = 1;
string account_nr = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void onUpdatedDataReceived() {
private void republishAllFiatAccounts() {
if (user.getPaymentAccounts() != null)
user.getPaymentAccounts().stream()
.filter(e -> !(e instanceof CryptoCurrencyAccount))
.filter(e -> !(e instanceof AssetAccount))
.forEach(e -> {
// We delay with a random interval of 20-60 sec to ensure to be better connected and don't stress the
// P2P network with publishing all at once at startup time.
Expand Down
35 changes: 35 additions & 0 deletions core/src/main/java/bisq/core/payment/AssetAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.core.payment;

import bisq.core.payment.payload.AssetsAccountPayload;
import bisq.core.payment.payload.PaymentMethod;

public abstract class AssetAccount extends PaymentAccount {
protected AssetAccount(PaymentMethod paymentMethod) {
super(paymentMethod);
}

public void setAddress(String address) {
((AssetsAccountPayload) paymentAccountPayload).setAddress(address);
}

public String getAddress() {
return ((AssetsAccountPayload) paymentAccountPayload).getAddress();
}
}
10 changes: 1 addition & 9 deletions core/src/main/java/bisq/core/payment/CryptoCurrencyAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
public final class CryptoCurrencyAccount extends PaymentAccount {
public final class CryptoCurrencyAccount extends AssetAccount {

public CryptoCurrencyAccount() {
super(PaymentMethod.BLOCK_CHAINS);
Expand All @@ -34,12 +34,4 @@ public CryptoCurrencyAccount() {
protected PaymentAccountPayload createPayload() {
return new CryptoCurrencyAccountPayload(paymentMethod.getId(), id);
}

public void setAddress(String address) {
((CryptoCurrencyAccountPayload) paymentAccountPayload).setAddress(address);
}

public String getAddress() {
return ((CryptoCurrencyAccountPayload) paymentAccountPayload).getAddress();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.core.payment;

import bisq.core.payment.payload.InstantCryptoCurrencyPayload;
import bisq.core.payment.payload.PaymentAccountPayload;
import bisq.core.payment.payload.PaymentMethod;

import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
public final class InstantCryptoCurrencyAccount extends AssetAccount {

public InstantCryptoCurrencyAccount() {
super(PaymentMethod.BLOCK_CHAINS_INSTANT);
}

@Override
protected PaymentAccountPayload createPayload() {
return new InstantCryptoCurrencyPayload(paymentMethod.getId(), id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public static PaymentAccount getPaymentAccount(PaymentMethod paymentMethod) {
return new PromptPayAccount();
case PaymentMethod.ADVANCED_CASH_ID:
return new AdvancedCashAccount();
case PaymentMethod.BLOCK_CHAINS_INSTANT_ID:
return new InstantCryptoCurrencyAccount();
default:
throw new RuntimeException("Not supported PaymentMethod: " + paymentMethod);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.core.payment.payload;

import bisq.core.locale.Res;

import java.nio.charset.Charset;

import java.util.Map;

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

import javax.annotation.Nullable;

@EqualsAndHashCode(callSuper = true)
@ToString
@Setter
@Getter
@Slf4j
public abstract class AssetsAccountPayload extends PaymentAccountPayload {
protected String address = "";

protected AssetsAccountPayload(String paymentMethod, String id) {
super(paymentMethod, id);
}


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

protected AssetsAccountPayload(String paymentMethod,
String id,
String address,
long maxTradePeriod,
@Nullable Map<String, String> excludeFromJsonDataMap) {
super(paymentMethod,
id,
maxTradePeriod,
excludeFromJsonDataMap);
this.address = address;
}


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

@Override
public String getPaymentDetails() {
return Res.getWithCol("payment.altcoin.receiver.address") + " " + address;
}

@Override
public String getPaymentDetailsForTradePopup() {
return getPaymentDetails();
}

@Override
public byte[] getAgeWitnessInputData() {
return super.getAgeWitnessInputData(address.getBytes(Charset.forName("UTF-8")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@

package bisq.core.payment.payload;

import bisq.core.locale.Res;

import io.bisq.generated.protobuffer.PB;

import com.google.protobuf.Message;

import org.springframework.util.CollectionUtils;

import java.nio.charset.Charset;

import java.util.HashMap;
import java.util.Map;

Expand All @@ -43,8 +39,7 @@
@Setter
@Getter
@Slf4j
public final class CryptoCurrencyAccountPayload extends PaymentAccountPayload {
private String address = "";
public final class CryptoCurrencyAccountPayload extends AssetsAccountPayload {

public CryptoCurrencyAccountPayload(String paymentMethod, String id) {
super(paymentMethod, id);
Expand All @@ -62,9 +57,9 @@ private CryptoCurrencyAccountPayload(String paymentMethod,
@Nullable Map<String, String> excludeFromJsonDataMap) {
super(paymentMethod,
id,
address,
maxTradePeriod,
excludeFromJsonDataMap);
this.address = address;
}

@Override
Expand All @@ -83,23 +78,4 @@ public static CryptoCurrencyAccountPayload fromProto(PB.PaymentAccountPayload pr
CollectionUtils.isEmpty(proto.getExcludeFromJsonDataMap()) ? null : new HashMap<>(proto.getExcludeFromJsonDataMap()));
}


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

@Override
public String getPaymentDetails() {
return Res.getWithCol("payment.altcoin.receiver.address") + " " + address;
}

@Override
public String getPaymentDetailsForTradePopup() {
return getPaymentDetails();
}

@Override
public byte[] getAgeWitnessInputData() {
return super.getAgeWitnessInputData(address.getBytes(Charset.forName("UTF-8")));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.core.payment.payload;

import io.bisq.generated.protobuffer.PB;

import com.google.protobuf.Message;

import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.Map;

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

import javax.annotation.Nullable;

@EqualsAndHashCode(callSuper = true)
@ToString
@Setter
@Getter
@Slf4j
public final class InstantCryptoCurrencyPayload extends AssetsAccountPayload {

public InstantCryptoCurrencyPayload(String paymentMethod, String id) {
super(paymentMethod, id);
}


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

private InstantCryptoCurrencyPayload(String paymentMethod,
String id,
String address,
long maxTradePeriod,
@Nullable Map<String, String> excludeFromJsonDataMap) {
super(paymentMethod,
id,
address,
maxTradePeriod,
excludeFromJsonDataMap);
}

@Override
public Message toProtoMessage() {
return getPaymentAccountPayloadBuilder()
.setInstantCryptoCurrencyAccountPayload(PB.InstantCryptoCurrencyAccountPayload.newBuilder()
.setAddress(address))
.build();
}

public static InstantCryptoCurrencyPayload fromProto(PB.PaymentAccountPayload proto) {
return new InstantCryptoCurrencyPayload(proto.getPaymentMethodId(),
proto.getId(),
proto.getInstantCryptoCurrencyAccountPayload().getAddress(),
proto.getMaxTradePeriod(),
CollectionUtils.isEmpty(proto.getExcludeFromJsonDataMap()) ? null : new HashMap<>(proto.getExcludeFromJsonDataMap()));
}
}
10 changes: 9 additions & 1 deletion core/src/main/java/bisq/core/payment/payload/PaymentMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable {
public static final String BLOCK_CHAINS_ID = "BLOCK_CHAINS";
public static final String PROMPT_PAY_ID = "PROMPT_PAY";
public static final String ADVANCED_CASH_ID = "ADVANCED_CASH";
public static final String BLOCK_CHAINS_INSTANT_ID = "BLOCK_CHAINS_INSTANT";

public static PaymentMethod UPHOLD;
public static PaymentMethod MONEY_BEAM;
Expand Down Expand Up @@ -116,6 +117,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable {
public static PaymentMethod BLOCK_CHAINS;
public static PaymentMethod PROMPT_PAY;
public static PaymentMethod ADVANCED_CASH;
public static PaymentMethod BLOCK_CHAINS_INSTANT;

// The limit and duration assignment must not be changed as that could break old offers (if amount would be higher
// than new trade limit) and violate the maker expectation when he created the offer (duration).
Expand Down Expand Up @@ -166,7 +168,9 @@ public final class PaymentMethod implements PersistablePayload, Comparable {
PROMPT_PAY = new PaymentMethod(PROMPT_PAY_ID, DAY, DEFAULT_TRADE_LIMIT_LOW_RISK),

// Altcoins
BLOCK_CHAINS = new PaymentMethod(BLOCK_CHAINS_ID, DAY, DEFAULT_TRADE_LIMIT_VERY_LOW_RISK)
BLOCK_CHAINS = new PaymentMethod(BLOCK_CHAINS_ID, DAY, DEFAULT_TRADE_LIMIT_VERY_LOW_RISK),
// Altcoins with 1 hour trade period
BLOCK_CHAINS_INSTANT = new PaymentMethod(BLOCK_CHAINS_INSTANT_ID, TimeUnit.HOURS.toMillis(1), DEFAULT_TRADE_LIMIT_VERY_LOW_RISK)
));

static {
Expand Down Expand Up @@ -292,4 +296,8 @@ public int compareTo(@NotNull Object other) {
else
return 0;
}

public boolean isAsset() {
return this.equals(BLOCK_CHAINS_INSTANT) || this.equals(BLOCK_CHAINS);
}
}
Loading