Updated on 2026-08-14

This commit is contained in:
Tangem 2019-01-06 20:40:20 +03:00
parent 07aaf3db47
commit 60fb1b56a3
4 changed files with 226 additions and 189 deletions

View file

@ -3,6 +3,8 @@ package com.tangem.data.network;
import com.tangem.data.network.model.InsightBody;
import com.tangem.data.network.model.InsightResponse;
import java.util.List;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
@ -16,13 +18,13 @@ public interface InsightApi {
Call<InsightResponse> insightAddress(@Path("address") String address);
@GET(ServerApiInsight.INSIGHT_UNSPENT_OUTPUTS)
Call<InsightResponse> insightUnspent(@Path("address") String address);
Call<List<InsightResponse>> insightUnspent(@Path("address") String address);
@GET(ServerApiInsight.INSIGHT_TRANSACTION)
Call<InsightResponse> insightTransaction(@Path("transaction") String transaction);
@GET(ServerApiInsight.INSIGHT_FEE)
Call<InsightResponse> insightFee(@Query("nbBlocks") int nbBlocks);
Call<InsightResponse> insightFee();
@Headers("Content-Type: application/json")
@POST(ServerApiInsight.INSIGHT_SEND)

View file

@ -6,6 +6,8 @@ import android.util.Log;
import com.tangem.data.network.model.InsightBody;
import com.tangem.data.network.model.InsightResponse;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
@ -17,13 +19,13 @@ public class ServerApiInsight {
public static final String INSIGHT_ADDRESS = "/addr/{address}";
public static final String INSIGHT_UNSPENT_OUTPUTS = "/addr/{address}/utxo";
public static final String INSIGHT_TRANSACTION = "/tx/{transaction}";
public static final String INSIGHT_FEE = "/utils/estimatefee";
public static final String INSIGHT_TRANSACTION = "/rawtx/{transaction}";
public static final String INSIGHT_FEE = "/utils/estimatefee?nbBlocks=2,3,6";
public static final String INSIGHT_SEND = "/tx/send";
private int requestsCount=0;
public String lastNode;
public static String lastNode;
public boolean isRequestsSequenceCompleted() {
Log.i(TAG, String.format("isRequestsSequenceCompleted: %s (%d requests left)", String.valueOf(requestsCount <= 0), requestsCount));
@ -34,7 +36,7 @@ public class ServerApiInsight {
public interface InsightBodyListener {
void onSuccess(String method, InsightResponse insightResponse);
void onSuccess(String method, List<InsightResponse> utxoList);
void onFail(String method, String message);
}
@ -42,7 +44,7 @@ public class ServerApiInsight {
insightBodyListener = listener;
}
public void insight(String method, String wallet, String tx, int nbBlocks) {
public void insight(String method, String wallet, String tx) {
requestsCount++;
String insightURL = "http://130.185.109.17:3001/insight-api"; //TODO: make random selection
this.lastNode = insightURL; //TODO: show node instead of URL
@ -54,51 +56,76 @@ public class ServerApiInsight {
// InsightApi insightApi = App.getNetworkComponent().getRetrofitInsight(insightURL).create(InsightApi.class);
InsightApi insightApi = retrofitInsight.create(InsightApi.class);
Call<InsightResponse> call;
switch (method) {
case INSIGHT_ADDRESS:
call = insightApi.insightAddress(wallet);
break;
case INSIGHT_UNSPENT_OUTPUTS:
call = insightApi.insightUnspent(wallet);
break;
case INSIGHT_TRANSACTION:
call = insightApi.insightTransaction(tx);
break;
case INSIGHT_FEE:
call = insightApi.insightFee(nbBlocks);
break;
case INSIGHT_SEND:
call = insightApi.insightSend(new InsightBody(tx));
break;
default:
call = insightApi.insightAddress(wallet);
break;
}
call.enqueue(new Callback<InsightResponse>() {
@Override
public void onResponse(@NonNull Call<InsightResponse> call, @NonNull Response<InsightResponse> response) {
if (response.code() == 200) {
requestsCount--;
insightBodyListener.onSuccess(method, response.body());
Log.i(TAG, "insight " + method + " onResponse " + response.code());
} else {
insightBodyListener.onFail(method, String.valueOf(response.code()));
Log.e(TAG, "insight " + method + " onResponse " + response.code());
if (method.equals(INSIGHT_UNSPENT_OUTPUTS)) {
Call<List<InsightResponse>> call = insightApi.insightUnspent(wallet);
call.enqueue(new Callback<List<InsightResponse>>() {
@Override
public void onResponse(@NonNull Call<List<InsightResponse>> call, @NonNull Response<List<InsightResponse>> response) {
if (response.code() == 200) {
requestsCount--;
insightBodyListener.onSuccess(method, response.body());
Log.i(TAG, "insight " + method + " onResponse " + response.code());
} else {
insightBodyListener.onFail(method, String.valueOf(response.code()));
Log.e(TAG, "insight " + method + " onResponse " + response.code());
}
}
}
@Override
public void onFailure(@NonNull Call<InsightResponse> call, @NonNull Throwable t) {
insightBodyListener.onFail(method, String.valueOf(t.getMessage()));
Log.e(TAG, "insight " + method + " onFailure " + t.getMessage());
@Override
public void onFailure(@NonNull Call<List<InsightResponse>> call, @NonNull Throwable t) {
insightBodyListener.onFail(method, String.valueOf(t.getMessage()));
Log.e(TAG, "insight " + method + " onFailure " + t.getMessage());
}
});
} else {
Call<InsightResponse> call = null;
switch (method) {
case INSIGHT_ADDRESS:
call = insightApi.insightAddress(wallet);
break;
case INSIGHT_UNSPENT_OUTPUTS:
break;
case INSIGHT_TRANSACTION:
call = insightApi.insightTransaction(tx);
break;
case INSIGHT_FEE:
call = insightApi.insightFee();
break;
case INSIGHT_SEND:
call = insightApi.insightSend(new InsightBody(tx));
break;
default:
call = insightApi.insightAddress(wallet);
break;
}
});
call.enqueue(new Callback<InsightResponse>() {
@Override
public void onResponse(@NonNull Call<InsightResponse> call, @NonNull Response<InsightResponse> response) {
if (response.code() == 200) {
requestsCount--;
insightBodyListener.onSuccess(method, response.body());
Log.i(TAG, "insight " + method + " onResponse " + response.code());
} else {
insightBodyListener.onFail(method, String.valueOf(response.code()));
Log.e(TAG, "insight " + method + " onResponse " + response.code());
}
}
@Override
public void onFailure(@NonNull Call<InsightResponse> call, @NonNull Throwable t) {
insightBodyListener.onFail(method, String.valueOf(t.getMessage()));
Log.e(TAG, "insight " + method + " onFailure " + t.getMessage());
}
});
}
}
}

View file

@ -3,21 +3,36 @@ package com.tangem.data.network.model
import com.google.gson.annotations.SerializedName
data class InsightResponse(
@SerializedName("jsonrpc")
var jsonrpc: String = "",
@SerializedName("id")
var id: Int? = null,
@SerializedName("balanceSat")
var balanceSat: Long = null,
var balanceSat: Long? = null,
@SerializedName("unconfirmedBalanceSat")
var unconfirmedBalanceSat: Long = null,
var unconfirmedBalanceSat: Long? = null,
@SerializedName("addrStr")
var addrStr: String = "",
@SerializedName("txid")
var txid: String = "",
@SerializedName("satoshis")
var satoshis: Int? = null,
@SerializedName("height")
var height: Int? = null,
@SerializedName("2")
var fee2: String = "",
@SerializedName("3")
var fee3: String = "",
@SerializedName("6")
var fee6: String = "",
@SerializedName("rawtx")
var rawtx: String = "",
@SerializedName("error")
var error: String = ""
)