Updated on 2026-08-14
This commit is contained in:
commit
5c6ea5ca04
18 changed files with 195 additions and 57 deletions
|
|
@ -0,0 +1,15 @@
|
|||
package com.tangem.data.network;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.GET;
|
||||
|
||||
public interface EstimatefeeApi {
|
||||
@GET(Server.ApiEstimatefee.Method.N_2)
|
||||
Call<String> getEstimateFeePriority();
|
||||
|
||||
@GET(Server.ApiEstimatefee.Method.N_3)
|
||||
Call<String> getEstimateFeeNormal();
|
||||
|
||||
@GET(Server.ApiEstimatefee.Method.N_6)
|
||||
Call<String> getEstimateFeeMinimal();
|
||||
}
|
||||
|
|
@ -6,9 +6,11 @@ import com.tangem.data.network.model.InfuraEthGasPriceResponse;
|
|||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.Header;
|
||||
import retrofit2.http.Headers;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface InfuraApi {
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST(Server.ApiInfura.Method.MAIN)
|
||||
Call<InfuraEthGasPriceResponse> ethGasPrice(@Header("Content-Type") String contentType, @Body InfuraEthGasPriceBody body);
|
||||
Call<InfuraEthGasPriceResponse> ethGasPrice(@Body InfuraEthGasPriceBody body);
|
||||
}
|
||||
|
|
@ -28,7 +28,7 @@ public class Server {
|
|||
* https://coinmarketcap.com/api/
|
||||
*/
|
||||
public static class ApiCoinmarket {
|
||||
public static final String URL_COINMARKET = ServerURL.API_COINMARKET;
|
||||
public static final String URL_COINMARKET = ServerURL.API_COINMARKETCAP;
|
||||
|
||||
public static class Method {
|
||||
public static final String V1_TICKER_CONVERT = URL_COINMARKET + "v1/ticker/?convert=USD&lmit=10";
|
||||
|
|
@ -44,7 +44,19 @@ public class Server {
|
|||
public static class Method {
|
||||
public static final String MAIN = URL_INFURA + "AfWg0tmYEX5Kukn2UkKV";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* https://estimatefee.com/
|
||||
*/
|
||||
public static class ApiEstimatefee {
|
||||
public static final String URL_ESTIMATEFEE = ServerURL.API_ESTIMATEFEE;
|
||||
|
||||
public static class Method {
|
||||
public static final String N_2 = URL_ESTIMATEFEE + "n/2";
|
||||
public static final String N_3 = URL_ESTIMATEFEE + "n/3";
|
||||
public static final String N_6 = URL_ESTIMATEFEE + "n/6";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,9 +4,6 @@ import android.annotation.SuppressLint;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
||||
import com.tangem.data.network.model.CardVerify;
|
||||
import com.tangem.data.network.model.CardVerifyBody;
|
||||
|
|
@ -21,9 +18,6 @@ import com.tangem.domain.wallet.Blockchain;
|
|||
import com.tangem.domain.wallet.TangemCard;
|
||||
import com.tangem.util.Util;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
|
@ -54,6 +48,66 @@ import retrofit2.converter.gson.GsonConverterFactory;
|
|||
public class ServerApiHelper {
|
||||
private static String TAG = ServerApiHelper.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* HTTP
|
||||
* Estimate fee
|
||||
*/
|
||||
public static final int ESTIMATE_FEE_PRIORITY = 2;
|
||||
public static final int ESTIMATE_FEE_NORMAL = 3;
|
||||
public static final int ESTIMATE_FEE_MINIMAL = 6;
|
||||
private EstimateFeeListener estimateFeeListener;
|
||||
|
||||
public interface EstimateFeeListener {
|
||||
void onInfuraEthGasPrice(int blockCount, String estimateFeeResponse);
|
||||
}
|
||||
|
||||
public void setEstimateFee(EstimateFeeListener listener) {
|
||||
estimateFeeListener = listener;
|
||||
}
|
||||
|
||||
public void estimateFee(int blockCount) {
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.baseUrl(Server.ApiEstimatefee.URL_ESTIMATEFEE)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build();
|
||||
|
||||
EstimatefeeApi estimatefeeApi = retrofit.create(EstimatefeeApi.class);
|
||||
|
||||
Call<String> call;
|
||||
switch (blockCount) {
|
||||
case ESTIMATE_FEE_PRIORITY:
|
||||
call = estimatefeeApi.getEstimateFeePriority();
|
||||
break;
|
||||
|
||||
case ESTIMATE_FEE_NORMAL:
|
||||
call = estimatefeeApi.getEstimateFeeNormal();
|
||||
break;
|
||||
|
||||
case ESTIMATE_FEE_MINIMAL:
|
||||
call = estimatefeeApi.getEstimateFeeMinimal();
|
||||
break;
|
||||
|
||||
default:
|
||||
call = estimatefeeApi.getEstimateFeeNormal();
|
||||
}
|
||||
|
||||
call.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.code() == 200) {
|
||||
estimateFeeListener.onInfuraEthGasPrice(blockCount, response.body());
|
||||
Log.i(TAG, "estimateFee onResponse " + response.code());
|
||||
} else
|
||||
Log.e(TAG, "estimateFee onResponse " + response.code());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||
Log.e(TAG, "estimateFee onFailure " + t.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP
|
||||
* InfuraEthGasPrice
|
||||
|
|
@ -78,7 +132,7 @@ public class ServerApiHelper {
|
|||
|
||||
InfuraEthGasPriceBody infuraEthGasPriceBody = new InfuraEthGasPriceBody(method, id);
|
||||
|
||||
Call<InfuraEthGasPriceResponse> call = infuraApi.ethGasPrice("application/json", infuraEthGasPriceBody);
|
||||
Call<InfuraEthGasPriceResponse> call = infuraApi.ethGasPrice(infuraEthGasPriceBody);
|
||||
|
||||
call.enqueue(new Callback<InfuraEthGasPriceResponse>() {
|
||||
@Override
|
||||
|
|
@ -124,7 +178,7 @@ public class ServerApiHelper {
|
|||
|
||||
CardVerifyBody cardVerifyBody = new CardVerifyBody(requests);
|
||||
|
||||
Call<CardVerifyResponse> call = tangemApi.getCardVerify("application/json", cardVerifyBody);
|
||||
Call<CardVerifyResponse> call = tangemApi.getCardVerify(cardVerifyBody);
|
||||
call.enqueue(new Callback<CardVerifyResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<CardVerifyResponse> call, @NonNull Response<CardVerifyResponse> response) {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ package com.tangem.data.network;
|
|||
|
||||
public class ServerURL {
|
||||
public static final String API_TANGEM = "https://verify.tangem.com/";
|
||||
public static final String API_COINMARKET = "https://api.coinmarketcap.com/";
|
||||
public static final String API_COINMARKETCAP = "https://api.coinmarketcap.com/";
|
||||
public static final String API_INFURA = "https://mainnet.infura.io/";
|
||||
public static final String API_ESTIMATEFEE = " https://estimatefee.com/";
|
||||
public static final String API_UPDATE_VERSION = "https://raw.githubusercontent.com/";
|
||||
}
|
||||
|
|
@ -6,9 +6,11 @@ import com.tangem.data.network.model.CardVerifyResponse;
|
|||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.Header;
|
||||
import retrofit2.http.Headers;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface TangemApi {
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST(Server.ApiTangem.Method.VERIFY)
|
||||
Call<CardVerifyResponse> getCardVerify(@Header("Content-Type") String contentType, @Body CardVerifyBody body);
|
||||
Call<CardVerifyResponse> getCardVerify(@Body CardVerifyBody body);
|
||||
}
|
||||
|
|
@ -47,14 +47,13 @@ public class FeeRequest {
|
|||
public static final int NORMAL = 3;
|
||||
public static final int MINIMAL = 6;
|
||||
private int blockCount = NORMAL;
|
||||
|
||||
public void setBlockCount(int count
|
||||
)
|
||||
{
|
||||
) {
|
||||
blockCount = count;
|
||||
}
|
||||
|
||||
public int getBlockCount()
|
||||
{
|
||||
public int getBlockCount() {
|
||||
return blockCount;
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +76,7 @@ public class FeeRequest {
|
|||
|
||||
public static FeeRequest GetFee(String wallet, long txSize, int blockCount) {
|
||||
FeeRequest request = new FeeRequest();
|
||||
request.WalletAddress=wallet;
|
||||
request.WalletAddress = wallet;
|
||||
request.txSize = txSize;
|
||||
request.setBlockCount(blockCount);
|
||||
return request;
|
||||
|
|
|
|||
|
|
@ -60,7 +60,8 @@ public class ElectrumTask extends AsyncTask<ElectrumRequest, Integer, List<Elect
|
|||
Log.v(logTag, "Connecting..." + Host);
|
||||
// Socket socket = new Socket(serverAddress, port);
|
||||
Socket socket = new Socket();
|
||||
socket.setSoTimeout(5000);
|
||||
// socket.setSoTimeout(5000);
|
||||
socket.setSoTimeout(10000);
|
||||
socket.bind(new InetSocketAddress(0));
|
||||
socket.connect(new InetSocketAddress(serverAddress, Port));
|
||||
// Log.i("effefefe", host);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.tangem.data.network.task;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import com.tangem.data.network.request.FeeRequest;
|
||||
import com.tangem.domain.wallet.SharedData;
|
||||
|
|
@ -40,6 +41,9 @@ public class FeeTask extends AsyncTask<FeeRequest, Void, List<FeeRequest>> {
|
|||
httpcon = (HttpURLConnection) url.openConnection();
|
||||
httpcon.setRequestMethod("GET");
|
||||
|
||||
|
||||
Log.i("scscsccsw222", String.valueOf(request.getBlockCount()));
|
||||
|
||||
httpcon.connect();
|
||||
|
||||
BufferedReader in = new BufferedReader(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue