Updated on 2026-08-14
This commit is contained in:
parent
72ef6051fb
commit
f47fe3b993
8 changed files with 114 additions and 19 deletions
14
app/src/main/java/com/tangem/data/network/InfuraApi.java
Normal file
14
app/src/main/java/com/tangem/data/network/InfuraApi.java
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package com.tangem.data.network;
|
||||
|
||||
import com.tangem.data.network.model.InfuraEthGasPriceBody;
|
||||
import com.tangem.data.network.model.InfuraEthGasPriceResponse;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.Header;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface InfuraApi {
|
||||
@POST(Server.ApiInfura.Method.MAIN)
|
||||
Call<InfuraEthGasPriceResponse> ethGasPrice(@Header("Content-Type") String contentType, @Body InfuraEthGasPriceBody body);
|
||||
}
|
||||
|
|
@ -25,4 +25,16 @@ public class Server {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* https://infura.io/
|
||||
*/
|
||||
public static class ApiInfura {
|
||||
public static final String URL_INFURA = ServerURL.API_INFURA;
|
||||
|
||||
public static class Method {
|
||||
public static final String MAIN = URL_INFURA + "AfWg0tmYEX5Kukn2UkKV";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -11,6 +11,8 @@ import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
|||
import com.tangem.data.network.model.CardVerify;
|
||||
import com.tangem.data.network.model.CardVerifyBody;
|
||||
import com.tangem.data.network.model.CardVerifyResponse;
|
||||
import com.tangem.data.network.model.InfuraEthGasPriceBody;
|
||||
import com.tangem.data.network.model.InfuraEthGasPriceResponse;
|
||||
import com.tangem.data.network.model.RateInfoResponse;
|
||||
import com.tangem.data.network.request.ElectrumRequest;
|
||||
import com.tangem.domain.BitcoinNode;
|
||||
|
|
@ -48,6 +50,49 @@ import retrofit2.converter.gson.GsonConverterFactory;
|
|||
public class ServerApiHelper {
|
||||
private static String TAG = ServerApiHelper.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* HTTP
|
||||
* Infura
|
||||
*/
|
||||
private InfuraListener infuraListener;
|
||||
|
||||
public interface InfuraListener {
|
||||
void onInfura(CardVerifyResponse cardVerifyResponse);
|
||||
}
|
||||
|
||||
public void setInfura(InfuraListener listener) {
|
||||
infuraListener = listener;
|
||||
}
|
||||
|
||||
public void infura(String method, int id) {
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.baseUrl(Server.ApiInfura.URL_INFURA)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build();
|
||||
|
||||
InfuraApi infuraApi = retrofit.create(InfuraApi.class);
|
||||
|
||||
InfuraEthGasPriceBody infuraEthGasPriceBody = new InfuraEthGasPriceBody(method, id);
|
||||
|
||||
Call<InfuraEthGasPriceResponse> call = infuraApi.ethGasPrice("application/json", infuraEthGasPriceBody);
|
||||
|
||||
call.enqueue(new Callback<InfuraEthGasPriceResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<InfuraEthGasPriceResponse> call, @NonNull Response<InfuraEthGasPriceResponse> response) {
|
||||
if (response.code() == 200) {
|
||||
Log.i(TAG, "infura onResponse " + response.code());
|
||||
Log.i(TAG, "infura onResponse " + response.body().getResult());
|
||||
} else
|
||||
Log.e(TAG, "infura onResponse " + response.code());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<InfuraEthGasPriceResponse> call, @NonNull Throwable t) {
|
||||
Log.e(TAG, "infura onFailure " + t.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP
|
||||
* Card verify
|
||||
|
|
@ -83,13 +128,12 @@ public class ServerApiHelper {
|
|||
CardVerifyResponse cardVerifyResponse = response.body();
|
||||
cardVerifyListener.onCardVerify(cardVerifyResponse);
|
||||
Log.i(TAG, "cardVerify onResponse " + response.code());
|
||||
} else {
|
||||
} else
|
||||
Log.e(TAG, "cardVerify onResponse " + response.code());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<CardVerifyResponse> call, Throwable t) {
|
||||
public void onFailure(@NonNull Call<CardVerifyResponse> call, @NonNull Throwable t) {
|
||||
Log.e(TAG, "cardVerify onFailure " + t.getMessage());
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,4 +3,5 @@ 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_INFURA = "https://mainnet.infura.io/";
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package com.tangem.data.network.model;
|
||||
|
||||
public class InfuraEthGasPriceBody {
|
||||
private String method;
|
||||
private String[] params;
|
||||
private int id;
|
||||
|
||||
public InfuraEthGasPriceBody(String method, int id) {
|
||||
this.method = method;
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.tangem.data.network.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class InfuraEthGasPriceResponse(
|
||||
@SerializedName("jsonrpc")
|
||||
var jsonrpc: String = "",
|
||||
|
||||
@SerializedName("id")
|
||||
var id: Int? = null,
|
||||
|
||||
@SerializedName("result")
|
||||
var result: String = ""
|
||||
)
|
||||
|
|
@ -14,8 +14,8 @@ public class InfuraRequest {
|
|||
public static final String METHOD_ETH_GetBalance = "eth_getBalance";
|
||||
public static final String METHOD_ETH_GetOutTransactionCount = "eth_getTransactionCount";
|
||||
public static final String METHOD_ETH_GetGasPrice = "eth_gasPrice";
|
||||
public static final String METHOD_ETH_SendRawTransaction = "eth_sendRawTransaction";
|
||||
public static final String METHOD_ETH_Call = "eth_call";
|
||||
public static final String METHOD_ETH_SendRawTransaction = "eth_sendRawTransaction";
|
||||
public static final String METHOD_ETH_Call = "eth_call";
|
||||
|
||||
public JSONObject jsRequestData;
|
||||
public String answerData;
|
||||
|
|
@ -29,8 +29,7 @@ public class InfuraRequest {
|
|||
blockchain = value;
|
||||
}
|
||||
|
||||
public Blockchain getBlockchain()
|
||||
{
|
||||
public Blockchain getBlockchain() {
|
||||
return blockchain;
|
||||
}
|
||||
|
||||
|
|
@ -86,7 +85,7 @@ public class InfuraRequest {
|
|||
public static InfuraRequest GetBalance(String wallet) {
|
||||
InfuraRequest request = new InfuraRequest();
|
||||
try {
|
||||
request.WalletAddress=wallet;
|
||||
request.WalletAddress = wallet;
|
||||
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_ETH_GetBalance + "\", \"params\":[\"" + wallet + "\", \"latest\"] }");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -95,15 +94,14 @@ public class InfuraRequest {
|
|||
return request;
|
||||
}
|
||||
|
||||
public static InfuraRequest GetTokenBalance(String wallet, String contract, int dec)
|
||||
{
|
||||
public static InfuraRequest GetTokenBalance(String wallet, String contract, int dec) {
|
||||
InfuraRequest request = new InfuraRequest();
|
||||
try {
|
||||
request.WalletAddress=wallet;
|
||||
request.WalletAddress = wallet;
|
||||
request.Dec = dec;
|
||||
String address = wallet.substring(2);
|
||||
String dataValue = String.format("{\"data\": \"0x70a08231000000000000000000000000%s\", \"to\": \"%s\"}", address, contract);
|
||||
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_ETH_Call + "\", \"params\":[" +dataValue+", \"latest\"] }");
|
||||
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_ETH_Call + "\", \"params\":[" + dataValue + ", \"latest\"] }");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
request.error = e.toString();
|
||||
|
|
@ -114,7 +112,7 @@ public class InfuraRequest {
|
|||
public static InfuraRequest SendTransaction(String wallet, String tx) {
|
||||
InfuraRequest request = new InfuraRequest();
|
||||
try {
|
||||
request.WalletAddress=wallet;
|
||||
request.WalletAddress = wallet;
|
||||
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_ETH_SendRawTransaction + "\", \"params\":[\"" + tx + "\"] }");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -124,11 +122,10 @@ public class InfuraRequest {
|
|||
}
|
||||
|
||||
|
||||
|
||||
public static InfuraRequest GetOutTransactionCount(String wallet) {
|
||||
InfuraRequest request = new InfuraRequest();
|
||||
try {
|
||||
request.WalletAddress=wallet;
|
||||
request.WalletAddress = wallet;
|
||||
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_ETH_GetOutTransactionCount + "\", \"params\":[\"" + wallet + "\", \"latest\"] }");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -140,7 +137,7 @@ public class InfuraRequest {
|
|||
public static InfuraRequest GetPendingTransactionCount(String wallet) {
|
||||
InfuraRequest request = new InfuraRequest();
|
||||
try {
|
||||
request.WalletAddress=wallet;
|
||||
request.WalletAddress = wallet;
|
||||
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_ETH_GetOutTransactionCount + "\", \"params\":[\"" + wallet + "\", \"pending\"] }");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -152,7 +149,7 @@ public class InfuraRequest {
|
|||
public static InfuraRequest GetGasPrise(String wallet) {
|
||||
InfuraRequest request = new InfuraRequest();
|
||||
try {
|
||||
request.WalletAddress=wallet;
|
||||
request.WalletAddress = wallet;
|
||||
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_ETH_GetGasPrice + "\", \"params\":[] }");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -165,7 +162,7 @@ public class InfuraRequest {
|
|||
public static InfuraRequest SendTransactionCount(String wallet, String TX) {
|
||||
InfuraRequest request = new InfuraRequest();
|
||||
try {
|
||||
request.WalletAddress=wallet;
|
||||
request.WalletAddress = wallet;
|
||||
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_ETH_SendRawTransaction + "\", \"params\":[\"" + TX + "\"] }");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -175,7 +172,6 @@ public class InfuraRequest {
|
|||
}
|
||||
|
||||
|
||||
|
||||
//METHOD_ETH_GetOutTransactionCount
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -173,6 +173,8 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
}
|
||||
}
|
||||
|
||||
serverApiHelper!!.infura("eth_gasPrice", 67)
|
||||
|
||||
// request card verify listener
|
||||
serverApiHelper!!.setCardVerify {
|
||||
card!!.isOnlineVerified = it.results!![0].passed
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue