Updated on 2026-08-14
This commit is contained in:
parent
0193926e46
commit
9f9c5db55e
14 changed files with 581 additions and 476 deletions
|
|
@ -3,6 +3,7 @@ package com.tangem.data.network;
|
|||
import com.tangem.data.network.model.BlockcypherBody;
|
||||
import com.tangem.data.network.model.BlockcypherResponse;
|
||||
import com.tangem.data.network.model.BlockcypherFee;
|
||||
import com.tangem.data.network.model.BlockcypherTx;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
|
|
@ -19,6 +20,9 @@ public interface BlockcypherApi {
|
|||
@GET(Server.ApiBlockcypher.Method.ADDRESS)
|
||||
Call<BlockcypherResponse> blockcypherAddress(@Path("blockchain") String blockchain, @Path("network") String network, @Path("address") String address);
|
||||
|
||||
@GET(Server.ApiBlockcypher.Method.TXS)
|
||||
Call<BlockcypherTx> blockcypherTxs(@Path("blockchain") String blockchain, @Path("network") String network, @Path("txHash") String txHash);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST(Server.ApiBlockcypher.Method.PUSH)
|
||||
Call<BlockcypherResponse> blockcypherPush(@Path("blockchain") String blockchain, @Path("network") String network, @Body BlockcypherBody blockcypherBody, @Query("token") String token);
|
||||
|
|
|
|||
|
|
@ -114,6 +114,7 @@ public class Server {
|
|||
public static class Method {
|
||||
static final String MAIN = URL_BLOCKCYPHER + V1_MAIN;
|
||||
static final String ADDRESS = MAIN + "/addrs/{address}?unspentOnly=true&includeScript=true";
|
||||
static final String TXS = MAIN + "/txs/{txHash}?includeHex=true";
|
||||
static final String PUSH = MAIN + "/txs/push";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import com.tangem.data.Blockchain;
|
|||
import com.tangem.data.network.model.BlockcypherBody;
|
||||
import com.tangem.data.network.model.BlockcypherFee;
|
||||
import com.tangem.data.network.model.BlockcypherResponse;
|
||||
import com.tangem.data.network.model.BlockcypherTx;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
|
|
@ -20,6 +21,7 @@ public class ServerApiBlockcypher {
|
|||
|
||||
public static final String BLOCKCYPHER_ADDRESS = "blockcypher_address";
|
||||
public static final String BLOCKCYPHER_FEE = "blockcypher_fee";
|
||||
public static final String BLOCKCYPHER_TXS = "blockcypher_txs";
|
||||
public static final String BLOCKCYPHER_SEND = "blockcypher_send";
|
||||
|
||||
private int requestsCount = 0;
|
||||
|
|
@ -31,6 +33,8 @@ public class ServerApiBlockcypher {
|
|||
|
||||
private ResponseListener responseListener;
|
||||
|
||||
private TxResponseListener txResponseListener;
|
||||
|
||||
public interface ResponseListener {
|
||||
void onSuccess(String method, BlockcypherResponse blockcypherResponse);
|
||||
|
||||
|
|
@ -39,10 +43,20 @@ public class ServerApiBlockcypher {
|
|||
void onFail(String method, String message);
|
||||
}
|
||||
|
||||
public interface TxResponseListener {
|
||||
void onSuccess(BlockcypherTx blockcypherTx);
|
||||
|
||||
void onFail(String message);
|
||||
}
|
||||
|
||||
public void setResponseListener(ResponseListener listener) {
|
||||
responseListener = listener;
|
||||
}
|
||||
|
||||
public void setTxResponseListener(TxResponseListener txListener) {
|
||||
txResponseListener = txListener;
|
||||
}
|
||||
|
||||
public void requestData(String blockchainID, String method, String wallet, String tx) {
|
||||
requestsCount++;
|
||||
String blockchain = blockchainID.toLowerCase();
|
||||
|
|
@ -60,8 +74,8 @@ public class ServerApiBlockcypher {
|
|||
addressCall.enqueue(new Callback<BlockcypherResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<BlockcypherResponse> call, @NonNull Response<BlockcypherResponse> response) {
|
||||
requestsCount--;
|
||||
if (response.code() == 200) {
|
||||
requestsCount--;
|
||||
responseListener.onSuccess(method, response.body());
|
||||
Log.i(TAG, "requestData " + method + " onResponse " + response.code());
|
||||
} else {
|
||||
|
|
@ -72,6 +86,7 @@ public class ServerApiBlockcypher {
|
|||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<BlockcypherResponse> call, @NonNull Throwable t) {
|
||||
requestsCount--;
|
||||
responseListener.onFail(method, String.valueOf(t.getMessage()));
|
||||
Log.e(TAG, "requestData " + method + " onFailure " + t.getMessage());
|
||||
}
|
||||
|
|
@ -83,8 +98,8 @@ public class ServerApiBlockcypher {
|
|||
feeCall.enqueue(new Callback<BlockcypherFee>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<BlockcypherFee> call, @NonNull Response<BlockcypherFee> response) {
|
||||
requestsCount--;
|
||||
if (response.code() == 200) {
|
||||
requestsCount--;
|
||||
responseListener.onSuccess(method, response.body());
|
||||
Log.i(TAG, "requestData " + method + " onResponse " + response.code());
|
||||
} else {
|
||||
|
|
@ -95,12 +110,37 @@ public class ServerApiBlockcypher {
|
|||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<BlockcypherFee> call, @NonNull Throwable t) {
|
||||
requestsCount--;
|
||||
responseListener.onFail(method, String.valueOf(t.getMessage()));
|
||||
Log.e(TAG, "requestData " + method + " onFailure " + t.getMessage());
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case BLOCKCYPHER_TXS:
|
||||
Call<BlockcypherTx> txsCall = blockcypherApi.blockcypherTxs(blockchain, network, tx);
|
||||
txsCall.enqueue(new Callback<BlockcypherTx>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<BlockcypherTx> call,@NonNull Response<BlockcypherTx> response) {
|
||||
requestsCount--;
|
||||
if (response.code() == 200) {
|
||||
txResponseListener.onSuccess(response.body());
|
||||
Log.i(TAG, "requestData " + method + " onResponse " + response.code());
|
||||
} else {
|
||||
txResponseListener.onFail(String.valueOf(response.code()));
|
||||
Log.e(TAG, "requestData " + method + " onResponse " + response.code());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<BlockcypherTx> call, @NonNull Throwable t) {
|
||||
requestsCount--;
|
||||
txResponseListener.onFail(String.valueOf(t.getMessage()));
|
||||
Log.e(TAG, "requestData " + method + " onFailure " + t.getMessage());
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case BLOCKCYPHER_SEND:
|
||||
BlockcypherToken blockcypherToken = BlockcypherToken.values()[new Random().nextInt(BlockcypherToken.values().length)];
|
||||
|
||||
|
|
@ -108,8 +148,8 @@ public class ServerApiBlockcypher {
|
|||
sendCall.enqueue(new Callback<BlockcypherResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<BlockcypherResponse> call, @NonNull Response<BlockcypherResponse> response) {
|
||||
requestsCount--;
|
||||
if (response.code() == 201) {
|
||||
requestsCount--;
|
||||
responseListener.onSuccess(method, response.body());
|
||||
Log.i(TAG, "requestData " + method + " onResponse " + response.code());
|
||||
} else {
|
||||
|
|
@ -120,6 +160,7 @@ public class ServerApiBlockcypher {
|
|||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<BlockcypherResponse> call, @NonNull Throwable t) {
|
||||
requestsCount--;
|
||||
responseListener.onFail(method, String.valueOf(t.getMessage()));
|
||||
Log.e(TAG, "requestData " + method + " onFailure " + t.getMessage());
|
||||
}
|
||||
|
|
@ -127,6 +168,7 @@ public class ServerApiBlockcypher {
|
|||
break;
|
||||
|
||||
default:
|
||||
requestsCount--;
|
||||
responseListener.onFail(method, "undeclared method");
|
||||
Log.e(TAG, "requestData " + method + " onFailure - undeclared method");
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@ import retrofit2.Response;
|
|||
|
||||
public class ServerApiSoChain {
|
||||
|
||||
public static String NETWORK_BTC = "BTC";
|
||||
|
||||
private static String TAG = ServerApiSoChain.class.getSimpleName();
|
||||
|
||||
private int requestsCount = 0;
|
||||
|
|
@ -86,9 +84,9 @@ public class ServerApiSoChain {
|
|||
call.enqueue(new Callback<SoChain.Response.AddressBalance>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SoChain.Response.AddressBalance> call, @NonNull Response<SoChain.Response.AddressBalance> response) {
|
||||
requestsCount--;
|
||||
Log.i(TAG, "requestAddressBalance onResponse " + response.code());
|
||||
if (response.code() == 200) {
|
||||
requestsCount--;
|
||||
addressInfoListener.onSuccess(response.body());
|
||||
} else {
|
||||
addressInfoListener.onFail(String.valueOf(response.code()));
|
||||
|
|
@ -97,6 +95,7 @@ public class ServerApiSoChain {
|
|||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<SoChain.Response.AddressBalance> call, @NonNull Throwable t) {
|
||||
requestsCount--;
|
||||
Log.e(TAG, "requestAddressBalance onFailure " + t.getMessage());
|
||||
addressInfoListener.onFail(String.valueOf(t.getMessage()));
|
||||
}
|
||||
|
|
@ -111,9 +110,9 @@ public class ServerApiSoChain {
|
|||
call.enqueue(new Callback<SoChain.Response.TxUnspent>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SoChain.Response.TxUnspent> call, @NonNull Response<SoChain.Response.TxUnspent> response) {
|
||||
requestsCount--;
|
||||
Log.i(TAG, "requestAddressBalance onResponse " + response.code());
|
||||
if (response.code() == 200) {
|
||||
requestsCount--;
|
||||
addressInfoListener.onSuccess(response.body());
|
||||
} else {
|
||||
addressInfoListener.onFail(String.valueOf(response.code()));
|
||||
|
|
@ -122,6 +121,7 @@ public class ServerApiSoChain {
|
|||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<SoChain.Response.TxUnspent> call, @NonNull Throwable t) {
|
||||
requestsCount--;
|
||||
Log.e(TAG, "requestAddressBalance onFailure " + t.getMessage());
|
||||
addressInfoListener.onFail(String.valueOf(t.getMessage()));
|
||||
}
|
||||
|
|
@ -138,9 +138,9 @@ public class ServerApiSoChain {
|
|||
call.enqueue(new Callback<SoChain.Response.SendTx>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SoChain.Response.SendTx> call, @NonNull Response<SoChain.Response.SendTx> response) {
|
||||
requestsCount--;
|
||||
Log.i(TAG, "requestAddressBalance onResponse " + response.code());
|
||||
if (response.code() == 200) {
|
||||
requestsCount--;
|
||||
sendTxListener.onSuccess(response.body());
|
||||
} else {
|
||||
sendTxListener.onFail(String.valueOf(response.code()));
|
||||
|
|
@ -149,6 +149,7 @@ public class ServerApiSoChain {
|
|||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<SoChain.Response.SendTx> call, @NonNull Throwable t) {
|
||||
requestsCount--;
|
||||
Log.e(TAG, "requestAddressBalance onFailure " + t.getMessage());
|
||||
sendTxListener.onFail(String.valueOf(t.getMessage()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,11 @@ data class BlockcypherTxref(
|
|||
var script: String? = null
|
||||
)
|
||||
|
||||
data class BlockcypherTx(
|
||||
@SerializedName("hex")
|
||||
var hex: String? = null
|
||||
)
|
||||
|
||||
data class BlockcypherFee(
|
||||
@SerializedName("low_fee_per_kb")
|
||||
var low_fee_per_kb: Long? = null,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue