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();

View file

@ -105,7 +105,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
if (card!!.blockchain == Blockchain.Ethereum || card!!.blockchain == Blockchain.EthereumTestNet || card!!.blockchain == Blockchain.Token) {
rgFee!!.isEnabled = false
serverApiHelper!!.infura(ServerApiHelper.INFURA_ETH_GAS_PRICE, 67, card!!.wallet)
serverApiHelper!!.infura(ServerApiHelper.INFURA_ETH_GAS_PRICE, 67, card!!.wallet, "")
} else {
rgFee!!.isEnabled = true

View file

@ -266,11 +266,35 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
// Log.i("eth_getTransactionCount", nonce)
}
if (method == ServerApiHelper.INFURA_ETH_CALL) {
var balanceCap = infuraResponse.result
balanceCap = balanceCap.substring(2)
val l = BigInteger(balanceCap, 16)
val balance = l.toLong()
if (l.compareTo(BigInteger.ZERO) == 0) {
card!!.blockchainID = Blockchain.Ethereum.id
card!!.addTokenToBlockchainName()
srlLoadedWallet!!.isRefreshing = false
// refresh()
return@setInfura
}
card!!.setBalanceConfirmed(balance)
card!!.balanceUnconfirmed = 0L
card!!.decimalBalance = l.toString(10)
// Log.i("eth_call", balanceCap)
}
updateViews()
}
}
private fun requestInfura(method: String) {
serverApiHelper!!.infura(method, 67, card!!.wallet)
private fun requestInfura(method: String, contract: String) {
serverApiHelper!!.infura(method, 67, card!!.wallet, contract)
}
private fun requestCardVerify() {
@ -681,8 +705,8 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
// Ethereum
else if (card!!.blockchain == Blockchain.Ethereum || card!!.blockchain == Blockchain.EthereumTestNet) {
requestInfura(ServerApiHelper.INFURA_ETH_GET_BALANCE)
requestInfura(ServerApiHelper.INFURA_ETH_GET_TRANSACTION_COUNT)
requestInfura(ServerApiHelper.INFURA_ETH_GET_BALANCE, "")
requestInfura(ServerApiHelper.INFURA_ETH_GET_TRANSACTION_COUNT, "")
// val updateETH = ETHRequestTask(this@LoadedWallet, card!!.blockchain)
@ -703,15 +727,15 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
// Token
else if (card!!.blockchain == Blockchain.Token) {
val updateETH = ETHRequestTask(this@LoadedWallet, card!!.blockchain)
// val updateETH = ETHRequestTask(this@LoadedWallet, card!!.blockchain)
//
// val reqETH = InfuraRequest.GetTokenBalance(card!!.wallet, engine!!.getContractAddress(card), engine.getTokenDecimals(card))
// reqETH.id = 67
// reqETH.setBlockchain(card!!.blockchain)
val reqETH = InfuraRequest.GetTokenBalance(card!!.wallet, engine!!.getContractAddress(card), engine.getTokenDecimals(card))
reqETH.id = 67
reqETH.setBlockchain(card!!.blockchain)
requestInfura(ServerApiHelper.INFURA_ETH_GET_BALANCE)
requestInfura(ServerApiHelper.INFURA_ETH_GET_TRANSACTION_COUNT)
requestInfura(ServerApiHelper.INFURA_ETH_GET_BALANCE, "")
requestInfura(ServerApiHelper.INFURA_ETH_GET_TRANSACTION_COUNT, "")
requestInfura(ServerApiHelper.INFURA_ETH_CALL, engine.getContractAddress(card))
// val reqBalance = InfuraRequest.GetBalance(card!!.wallet)
// reqBalance.id = 67
@ -722,7 +746,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
// reqNonce.setBlockchain(card!!.blockchain)
// updateETH.execute(reqETH, reqNonce, reqBalance)
updateETH.execute(reqETH)
// updateETH.execute(reqETH)
requestRateInfo("ethereum")
}
@ -730,8 +754,6 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
if (needResendTX)
sendTransaction(LastSignStorage.getTxForSend(card!!.wallet))
// requestInfura(ServerApiHelper.INFURA_ETH_GET_BALANCE)
}