Updated on 2026-08-14

This commit is contained in:
Tangem 2018-09-08 15:20:41 +03:00
parent dfd8bd0594
commit 8780aca5e1
5 changed files with 71 additions and 18 deletions

View file

@ -114,10 +114,12 @@ public class ServerApiHelper {
* <p>
* eth_getBalance
* eth_getTransactionCount
* eth_call
* eth_gasPrice
*/
public static final String INFURA_ETH_GET_BALANCE = "eth_getBalance";
public static final String INFURA_ETH_GET_TRANSACTION_COUNT = "eth_getTransactionCount";
public static final String INFURA_ETH_CALL = "eth_call";
public static final String INFURA_ETH_GAS_PRICE = "eth_gasPrice";
private InfuraBodyListener infuraBodyListener;
@ -129,7 +131,7 @@ public class ServerApiHelper {
infuraBodyListener = listener;
}
public void infura(String method, int id, String wallet) {
public void infura(String method, int id, String wallet, String contract) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Server.ApiInfura.URL_INFURA)
.addConverterFactory(GsonConverterFactory.create())
@ -144,6 +146,11 @@ public class ServerApiHelper {
infuraBody = new InfuraBody(method, new String[]{wallet, "latest"}, id);
break;
case INFURA_ETH_CALL:
String address = wallet.substring(2);
infuraBody = new InfuraBody(method, new Object[]{new InfuraBody.EthCallParams("0x70a08231000000000000000000000000" + address, contract), "latest"}, id);
break;
case INFURA_ETH_GAS_PRICE:
infuraBody = new InfuraBody(method, id);
break;

View file

@ -2,12 +2,13 @@ package com.tangem.data.network.model;
public class InfuraBody {
private String method;
private String[] params;
private Object[] params;
private int id;
public InfuraBody() {
}
// body for eth gasPrice
public InfuraBody(String method, int id) {
this.method = method;
this.id = id;
@ -18,4 +19,21 @@ public class InfuraBody {
this.params = params;
this.id = id;
}
// body for eth call
public InfuraBody(String method, Object[] params, int id) {
this.method = method;
this.params = params;
this.id = id;
}
public static class EthCallParams {
private String data;
private String to;
public EthCallParams(String data, String to) {
this.data = data;
this.to = to;
}
}
}

View file

@ -4,6 +4,8 @@ package com.tangem.data.network.request;
* Created by Ilia on 19.12.2017.
*/
import android.util.Log;
import com.tangem.domain.wallet.Blockchain;
import org.json.JSONArray;
@ -102,6 +104,10 @@ public class InfuraRequest {
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\"] }");
Log.i("swdwd", request.jsRequestData.toString());
Log.i("swdwd + address", address);
Log.i("swdwd + contract", contract);
} catch (JSONException e) {
e.printStackTrace();
request.error = e.toString();