Updated on 2026-08-14
This commit is contained in:
parent
25e76dbb18
commit
5e91f8ffa6
14 changed files with 408 additions and 3 deletions
|
|
@ -20,7 +20,9 @@ public enum Blockchain {
|
|||
Cardano("CARDANO", "ADA", 1000000.0, R.drawable.tangem2, "Cardano"),
|
||||
Ripple ("XRP", "XRP", 1000000.0, R.drawable.tangem2, "XRP"),
|
||||
Binance("BINANCE", "BNB", 100000000.0, R.drawable.tangem2, "Binance"),
|
||||
BinanceTestNet("BINANCE/test", "BNB", 100000000.0, R.drawable.tangem2, "Binance Testnet");
|
||||
BinanceTestNet("BINANCE/test", "BNB", 100000000.0, R.drawable.tangem2, "Binance Testnet"),
|
||||
Matic("MATIC", "MTX", 1.0, R.drawable.tangem2, "Matic"),
|
||||
MaticTestNet("MATIC/test", "MTX", 1.0, R.drawable.tangem2, "Matic Testnet");
|
||||
|
||||
Blockchain(String ID, String currency, double multiplier, int imageResource, String officialName) {
|
||||
mID = ID;
|
||||
|
|
|
|||
15
app/src/main/java/com/tangem/data/network/MaticApi.java
Normal file
15
app/src/main/java/com/tangem/data/network/MaticApi.java
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
package com.tangem.data.network;
|
||||
|
||||
import com.tangem.data.network.model.InfuraBody;
|
||||
import com.tangem.data.network.model.InfuraResponse;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.Headers;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface MaticApi {
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST(Server.ApiMaticTesnet.Method.MAIN)
|
||||
Call<InfuraResponse> matic(@Body InfuraBody body);
|
||||
}
|
||||
|
|
@ -43,6 +43,17 @@ public class Server {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* https://testnet2.matic.network
|
||||
*/
|
||||
public static class ApiMaticTesnet {
|
||||
public static final String URL_MATIC_TESTNET = ServerURL.API_MATIC_TESTNET ;
|
||||
|
||||
public static class Method {
|
||||
static final String MAIN = URL_MATIC_TESTNET;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* https://estimatefee.com/
|
||||
*/
|
||||
|
|
|
|||
105
app/src/main/java/com/tangem/data/network/ServerApiMatic.java
Normal file
105
app/src/main/java/com/tangem/data/network/ServerApiMatic.java
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
package com.tangem.data.network;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
|
||||
import com.tangem.App;
|
||||
import com.tangem.data.network.model.InfuraBody;
|
||||
import com.tangem.data.network.model.InfuraResponse;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class ServerApiMatic {
|
||||
private static String TAG = ServerApiMatic.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* HTTP
|
||||
* Infura
|
||||
* <p>
|
||||
* eth_getBalance
|
||||
* eth_getTransactionCount
|
||||
* eth_call
|
||||
* eth_sendRawTransaction
|
||||
* eth_gasPrice
|
||||
*/
|
||||
public static final String MATIC_ETH_GET_BALANCE = "eth_getBalance";
|
||||
public static final String MATIC_ETH_GET_TRANSACTION_COUNT = "eth_getTransactionCount";
|
||||
public static final String MATIC_ETH_GET_PENDING_COUNT = "eth_getPendingCount";
|
||||
public static final String MATIC_ETH_CALL = "eth_call";
|
||||
public static final String MATIC_ETH_SEND_RAW_TRANSACTION = "eth_sendRawTransaction";
|
||||
public static final String MATIC_ETH_GAS_PRICE = "eth_gasPrice";
|
||||
|
||||
private int requestsCount=0;
|
||||
|
||||
public boolean isRequestsSequenceCompleted() {
|
||||
Log.i(TAG, String.format("isRequestsSequenceCompleted: %s (%d requests left)", String.valueOf(requestsCount <= 0), requestsCount));
|
||||
return requestsCount <= 0;
|
||||
}
|
||||
|
||||
private ResponseListener responseListener;
|
||||
|
||||
public interface ResponseListener {
|
||||
void onSuccess(String method, InfuraResponse infuraResponse);
|
||||
|
||||
void onFail(String method, String message);
|
||||
}
|
||||
|
||||
public void setResponseListener(ResponseListener listener) {
|
||||
responseListener = listener;
|
||||
}
|
||||
|
||||
public void requestData(String method, int id, String wallet, String contract, String tx) {
|
||||
requestsCount++;
|
||||
MaticApi maticApi = App.Companion.getNetworkComponent().getRetrofitMaticTesnet().create(MaticApi.class);
|
||||
|
||||
InfuraBody infuraBody;
|
||||
switch (method) {
|
||||
case MATIC_ETH_GET_BALANCE:
|
||||
case MATIC_ETH_GET_TRANSACTION_COUNT:
|
||||
infuraBody = new InfuraBody(method, new String[]{wallet, "latest"}, id);
|
||||
break;
|
||||
case MATIC_ETH_GET_PENDING_COUNT:
|
||||
infuraBody = new InfuraBody(MATIC_ETH_GET_TRANSACTION_COUNT, new String[]{wallet, "pending"}, id);
|
||||
break;
|
||||
case MATIC_ETH_CALL:
|
||||
String address = wallet.substring(2);
|
||||
infuraBody = new InfuraBody(method, new Object[]{new InfuraBody.EthCallParams("0x70a08231000000000000000000000000" + address, contract), "latest"}, id);
|
||||
break;
|
||||
|
||||
case MATIC_ETH_SEND_RAW_TRANSACTION:
|
||||
infuraBody = new InfuraBody(method, new String[]{tx}, id);
|
||||
break;
|
||||
|
||||
case MATIC_ETH_GAS_PRICE:
|
||||
infuraBody = new InfuraBody(method, id);
|
||||
break;
|
||||
|
||||
default:
|
||||
infuraBody = new InfuraBody();
|
||||
}
|
||||
|
||||
Call<InfuraResponse> call = maticApi.matic(infuraBody);
|
||||
call.enqueue(new Callback<InfuraResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<InfuraResponse> call, @NonNull Response<InfuraResponse> response) {
|
||||
if (response.code() == 200) {
|
||||
requestsCount--;
|
||||
responseListener.onSuccess(method, response.body());
|
||||
Log.i(TAG, "requestData " + method + " onResponse " + response.code());
|
||||
} else {
|
||||
responseListener.onFail(method, String.valueOf(response.code()));
|
||||
Log.e(TAG, "requestData " + method + " onResponse " + response.code());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<InfuraResponse> call, @NonNull Throwable t) {
|
||||
responseListener.onFail(method, String.valueOf(t.getMessage()));
|
||||
Log.e(TAG, "requestData " + method + " onFailure " + t.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -10,4 +10,5 @@ class ServerURL {
|
|||
static final String API_BLOCKCYPHER = "https://api.blockcypher.com/";
|
||||
static final String API_BINANCE = "https://dex.binance.org/";
|
||||
static final String API_BINANCE_TESTNET = "https://testnet-dex.binance.org/";
|
||||
static final String API_MATIC_TESTNET = "https://testnet2.matic.network";
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ public class InfuraBody {
|
|||
private String method;
|
||||
private Object[] params;
|
||||
private int id;
|
||||
private String jsonrpc = "2.0";
|
||||
|
||||
public InfuraBody() {
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue