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

Sync changes from 1.3.0 to master #898

Merged
merged 7 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# buildscript - project id
projectGroup=com.generalbytes.batm.public
projectVersion=1.4.4
projectVersion=1.4.5

# buildscript - common dependency versions
bitrafaelVersion=1.0.44
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package com.generalbytes.batm.server.extensions;

import com.generalbytes.batm.server.extensions.quiz.QuizResult;
import com.generalbytes.batm.server.extensions.questionnaire.QuestionnaireResult;

import java.math.BigDecimal;
import java.util.Date;
Expand Down Expand Up @@ -205,10 +205,10 @@ public interface ITransactionPreparation {
void setWithdrawalReason(int reason);

/**
* Returns quiz results if any quiz has been activated.
* Returns questionnaire results if any questionnaire has been activated.
*
* @return List of {@link QuizResult}. Can be null.
* @return List of {@link QuestionnaireResult}. Can be null.
*/
List<QuizResult> getQuizResults();
List<QuestionnaireResult> getQuestionnaireResults();

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************************
* Copyright (C) 2014-2020 GENERAL BYTES s.r.o. All rights reserved.
* Copyright (C) 2014-2024 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
Expand All @@ -17,7 +17,7 @@
************************************************************************************/
package com.generalbytes.batm.server.extensions;

import com.generalbytes.batm.server.extensions.quiz.QuizResult;
import com.generalbytes.batm.server.extensions.questionnaire.QuestionnaireResult;

import java.math.BigDecimal;
import java.util.Date;
Expand Down Expand Up @@ -160,11 +160,11 @@ public interface ITransactionRequest {
BigDecimal getDiscountQuotient();

/**
* Returns quiz results if any quiz has been activated.
* Returns questionnaire results if any questionnaire has been activated.
*
* @return List of {@link QuizResult}. Can be null.
* @return List of {@link QuestionnaireResult}. Can be null.
*/
List<QuizResult> getQuizResults();
List<QuestionnaireResult> getQuestionnaireResults();

/**
* Error message displayed to the customer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
* Web : http://www.generalbytes.com
*
************************************************************************************/
package com.generalbytes.batm.server.extensions.quiz;
package com.generalbytes.batm.server.extensions.questionnaire;

import com.generalbytes.batm.server.extensions.customfields.CustomFieldDefinition;
import com.generalbytes.batm.server.extensions.customfields.CustomFieldDefinitionType;

/**
* An object representing the question and answer data in the {@link QuizResult}.
* An object representing the question and answer data in the {@link QuestionnaireResult}.
*/
public class QuestionAnswer {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************************
* Copyright (C) 2014-2023 GENERAL BYTES s.r.o. All rights reserved.
* Copyright (C) 2014-2024 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
Expand All @@ -15,34 +15,34 @@
* Web : http://www.generalbytes.com
*
************************************************************************************/
package com.generalbytes.batm.server.extensions.quiz;
package com.generalbytes.batm.server.extensions.questionnaire;

import java.util.List;

/**
* An object representing data about quiz result.
* An object representing data about questionnaire result.
*/
public class QuizResult {
public class QuestionnaireResult {

private String quizName;
private String questionnaireName;

private List<QuestionAnswer> answers;

public QuizResult() {
public QuestionnaireResult() {

}

public QuizResult(String quizName, List<QuestionAnswer> answers) {
this.quizName = quizName;
public QuestionnaireResult(String questionnaireName, List<QuestionAnswer> answers) {
this.questionnaireName = questionnaireName;
this.answers = answers;
}

public String getQuizName() {
return quizName;
public String getQuestionnaireName() {
return questionnaireName;
}

public void setQuizName(String quizName) {
this.quizName = quizName;
public void setQuestionnaireName(String questionnaireName) {
this.questionnaireName = questionnaireName;
}

public List<QuestionAnswer> getAnswers() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************************
* Copyright (C) 2014-2020 GENERAL BYTES s.r.o. All rights reserved.
* Copyright (C) 2014-2024 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
Expand Down Expand Up @@ -291,9 +291,11 @@ public IWallet createWallet(String walletLogin, String tunnelPassword) {
String proxyUrl = st.nextToken("\n").replaceFirst(":", "");
return new BitcoreWallet(apiKey, proxyUrl);
} else if ("bitgo".equalsIgnoreCase(walletType) || "bitgonoforward".equalsIgnoreCase(walletType)) {
// bitgo:host:port:token:wallet_address:wallet_passphrase:num_blocks
// bitgo:host:port:token:wallet_address:wallet_passphrase:num_blocks:fee_rate:max_fee_rate
// but host is optionally including the "http://" and port is optional,
// num_blocks is an optional integer greater than 2 and it's used to calculate mining fee.
// num_blocks is an optional integer greater than 2 and it's used to calculate mining fee,
// fee_rate is an optional integer defined fee rate,
// max_fee_rate is an optional integer defined maximum fee rate.
// bitgo:http://localhost:80:token:wallet_address:wallet_passphrase
// bitgo:http://localhost:token:wallet_address:wallet_passphrase
// bitgo:localhost:token:wallet_address:wallet_passphrase
Expand Down Expand Up @@ -328,22 +330,22 @@ public IWallet createWallet(String walletLogin, String tunnelPassword) {
host = tunnelAddress.getHostString();
port = tunnelAddress.getPort();

String blocks;
int num;
Integer numBlocks = 2;
if(st.hasMoreTokens()){
blocks = st.nextToken();
num = Integer.parseInt(blocks);
if(num > 2) {
numBlocks = num;
}
int numBlocks = 2;
if (st.hasMoreTokens()) {
int number = Integer.parseInt(st.nextToken());
if (number > 2) {
numBlocks = number;
}
}

Integer feeRate = st.hasMoreTokens() ? Integer.parseInt(st.nextToken()) : null;
Integer maxFeeRate = st.hasMoreTokens() ? Integer.parseInt(st.nextToken()) : null;

if ("bitgonoforward".equalsIgnoreCase(walletType)) {
return new BitgoWalletWithUniqueAddresses(scheme, host, port, token, walletId, walletPassphrase, numBlocks);
return new BitgoWalletWithUniqueAddresses(scheme, host, port, token, walletId, walletPassphrase, numBlocks, feeRate, maxFeeRate);
}

return new BitgoWallet(scheme, host, port, token, walletId, walletPassphrase, numBlocks);
return new BitgoWallet(scheme, host, port, token, walletId, walletPassphrase, numBlocks, feeRate, maxFeeRate);

} else if ("coinbasewallet2".equalsIgnoreCase(walletType)
|| "coinbasewallet2noforward".equalsIgnoreCase(walletType)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************************
* Copyright (C) 2014-2020 GENERAL BYTES s.r.o. All rights reserved.
* Copyright (C) 2014-2024 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
Expand Down Expand Up @@ -57,6 +57,8 @@ public class BitgoWallet implements IWallet, ICanSendMany {
protected String url;
protected static final Integer readTimeout = 90 * 1000; //90 seconds
protected Integer numBlocks;
protected Integer feeRate;
protected Integer maxFeeRate;

protected static final Map<String, String> cryptoCurrencies = new HashMap<String, String>() {
{
Expand Down Expand Up @@ -93,10 +95,16 @@ private int pow10Exp(BigDecimal val) {
};

public BitgoWallet(String scheme, String host, int port, String token, String walletId, String walletPassphrase, Integer numBlocks) {
this(scheme, host, port, token, walletId, walletPassphrase, numBlocks, null, null);
}

public BitgoWallet(String scheme, String host, int port, String token, String walletId, String walletPassphrase, Integer numBlocks, Integer feeRate, Integer maxFeeRate) {
this.walletId = walletId;
this.walletPassphrase = walletPassphrase;
this.url = new HttpUrl.Builder().scheme(scheme).host(host).port(port).build().toString();
this.numBlocks = numBlocks;
this.feeRate = feeRate;
this.maxFeeRate = maxFeeRate;

ClientConfig config = new ClientConfig();
config.setHttpReadTimeout(readTimeout);
Expand Down Expand Up @@ -146,7 +154,7 @@ public String sendMany(Collection<Transfer> transfers, String cryptoCurrency, St
@Override
public String sendCoins(String destinationAddress, BigDecimal amount, String cryptoCurrency, String description) {
try {
final BitGoCoinRequest request = new BitGoCoinRequest(destinationAddress, toSatoshis(amount, cryptoCurrency), walletPassphrase, description, this.numBlocks);
final BitGoCoinRequest request = new BitGoCoinRequest(destinationAddress, toSatoshis(amount, cryptoCurrency), walletPassphrase, description, this.numBlocks, this.feeRate, this.maxFeeRate);
String bitgoCryptoCurrency = cryptoCurrencies.get(cryptoCurrency);
return getResultTxId(api.sendCoins(bitgoCryptoCurrency, this.walletId, request));
} catch (HttpStatusIOException hse) {
Expand All @@ -172,7 +180,7 @@ private Integer getDecimals(String cryptoCurrency) {

@Override
public String getCryptoAddress(String cryptoCurrency) {
if(cryptoCurrency == null) {
if (cryptoCurrency == null) {
cryptoCurrency = getPreferredCryptoCurrency();
}
String bitgoCryptoCurrency = cryptoCurrencies.get(cryptoCurrency);
Expand All @@ -181,18 +189,18 @@ public String getCryptoAddress(String cryptoCurrency) {
}
try {
final Map<String, Object> response = api.getWalletById(bitgoCryptoCurrency, walletId);
if(response == null || response.isEmpty()) {
if (response == null || response.isEmpty()) {
return null;
}

Object receiveAddressObj = response.get("receiveAddress");
if(receiveAddressObj == null || !(receiveAddressObj instanceof Map)) {
if (!(receiveAddressObj instanceof Map)) {
return null;
}

Map receiveAddressMap = (Map)receiveAddressObj;
Object addressObj = receiveAddressMap.get("address");
if(addressObj == null || !(addressObj instanceof String)) {
if (!(addressObj instanceof String)) {
return null;
}
return (String)addressObj;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************************
* Copyright (C) 2014-2020 GENERAL BYTES s.r.o. All rights reserved.
* Copyright (C) 2014-2024 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
Expand Down Expand Up @@ -46,6 +46,10 @@ public BitgoWalletWithUniqueAddresses(String scheme, String host, int port, Stri
super(scheme, host, port, token, walletId, walletPassphrase, numBlocks);
}

public BitgoWalletWithUniqueAddresses(String scheme, String host, int port, String token, String walletId, String walletPassphrase, Integer numBlocks, Integer feeRate, Integer maxFeeRate) {
super(scheme, host, port, token, walletId, walletPassphrase, numBlocks, feeRate, maxFeeRate);
}

@Override
public String generateNewDepositCryptoAddress(String cryptoCurrency, String label) {
if (cryptoCurrency == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************************
* Copyright (C) 2014-2020 GENERAL BYTES s.r.o. All rights reserved.
* Copyright (C) 2014-2024 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
Expand All @@ -23,6 +23,8 @@ public class BitGoCoinRequest {
private String walletPassphrase;
private Integer numBlocks;
private String comment;
private Integer feeRate;
private Integer maxFeeRate;


public BitGoCoinRequest(String address, String amount, String walletPassphrase, String comment, Integer numBlocks) {
Expand All @@ -33,6 +35,13 @@ public BitGoCoinRequest(String address, String amount, String walletPassphrase,
this.comment = comment;
}

public BitGoCoinRequest(String address, String amount, String walletPassphrase, String comment, Integer numBlocks, Integer feeRate, Integer maxFeeRate) {
this(address, amount, walletPassphrase, comment, numBlocks);

this.feeRate = feeRate;
this.maxFeeRate = maxFeeRate;
}

public String getAddress() {
return address;
}
Expand Down Expand Up @@ -72,4 +81,20 @@ public String getComment() {
public void setComment(String comment){
this.comment = comment;
}

public Integer getFeeRate() {
return feeRate;
}

public void setFeeRate(Integer feeRate) {
this.feeRate = feeRate;
}

public Integer getMaxFeeRate() {
return maxFeeRate;
}

public void setMaxFeeRate(Integer maxFeeRate) {
this.maxFeeRate = maxFeeRate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
<param name="wallet_id" />
<param name="wallet_passphrase" />
<param name="num_blocks" />
<param name="fee_rate" />
<param name="max_fee_rate" />
<cryptocurrency buyonly="true">BCH</cryptocurrency>
<cryptocurrency>BTC</cryptocurrency>
<cryptocurrency>LTC</cryptocurrency>
Expand All @@ -54,6 +56,8 @@
<param name="wallet_id" />
<param name="wallet_passphrase" />
<param name="num_blocks" />
<param name="fee_rate" />
<param name="max_fee_rate" />
<cryptocurrency buyonly="true">BCH</cryptocurrency>
<cryptocurrency>BTC</cryptocurrency>
<cryptocurrency>LTC</cryptocurrency>
Expand Down
Loading