Updated on 2026-08-14
This commit is contained in:
parent
a69588389a
commit
89c16fba70
4 changed files with 63 additions and 16 deletions
|
|
@ -9,6 +9,7 @@ import com.tangem.domain.wallet.bch.BitcoinCashNode;
|
|||
import com.tangem.domain.wallet.btc.BitcoinNode;
|
||||
import com.tangem.domain.wallet.btc.BitcoinNodeTestNet;
|
||||
import com.tangem.domain.wallet.ltc.LitecoinNode;
|
||||
import com.tangem.tangemcard.reader.CardProtocol;
|
||||
import com.tangem.wallet.R;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
|
|
@ -260,7 +261,15 @@ public class ServerApiElectrum {
|
|||
Log.e(TAG, "doElectrumRequestTcp " + electrumRequest.getMethod() + " ConnectException " + e.getMessage());
|
||||
} finally {
|
||||
Log.i(TAG, "doElectrumRequestTcp " + electrumRequest.getMethod() + " socket.close");
|
||||
socket.close();
|
||||
try {
|
||||
if( socket.isConnected() ) socket.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
Log.e(TAG,"Can't close socket");
|
||||
electrumRequest.setError(App.getInstance().getString(R.string.cannot_obtain_data_from_blockchain_communication_error));
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
//e.printStackTrace();
|
||||
|
|
@ -331,16 +340,24 @@ public class ServerApiElectrum {
|
|||
} catch (ConnectException e) {
|
||||
e.printStackTrace();
|
||||
electrumRequest.setError(App.getInstance().getString(R.string.cannot_obtain_data_from_blockchain_no_connection));
|
||||
Log.e(TAG, "doElectrumRequestTcp " + electrumRequest.getMethod() + " ConnectException " + e.getMessage());
|
||||
Log.e(TAG, "doElectrumRequestSsl " + electrumRequest.getMethod() + " ConnectException " + e.getMessage());
|
||||
} finally {
|
||||
Log.i(TAG, "doElectrumRequestTcp " + electrumRequest.getMethod() + " socket.close");
|
||||
sslSocket.close();
|
||||
Log.i(TAG, "doElectrumRequestSsl " + electrumRequest.getMethod() + " socket.close");
|
||||
try {
|
||||
if( sslSocket.isConnected() ) sslSocket.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
electrumRequest.setError(App.getInstance().getString(R.string.cannot_obtain_data_from_blockchain_communication_error));
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "Can't close ssl socket");
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
electrumRequest.setError(App.getInstance().getString(R.string.cannot_obtain_data_from_blockchain_communication_error));
|
||||
Log.e(TAG, "doElectrumRequestTcp " + electrumRequest.getMethod() + " IOException " + e.getMessage());
|
||||
Log.e(TAG, "doElectrumRequestSsl " + electrumRequest.getMethod() + " IOException " + e.getMessage());
|
||||
}
|
||||
} catch (NoSuchAlgorithmException | KeyManagementException e) {
|
||||
electrumRequest.setError(App.getInstance().getString(R.string.cannot_obtain_data_from_blockchain));
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import java.util.Arrays;
|
|||
|
||||
public class EthEngine extends CoinEngine {
|
||||
|
||||
private static final String TAG = EthEngine.class.getSimpleName();
|
||||
public EthData coinData = null;
|
||||
|
||||
public EthEngine(TangemContext ctx) throws Exception {
|
||||
|
|
@ -377,6 +378,9 @@ public class EthEngine extends CoinEngine {
|
|||
|
||||
@Override
|
||||
public SignTask.PaymentToSign constructPayment(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) throws Exception {
|
||||
|
||||
Log.e(TAG, "Construct payment "+amountValue.toString()+" with fee "+feeValue.toString()+(IncFee?" including":" excluding"));
|
||||
|
||||
BigInteger nonceValue = coinData.getConfirmedTXCount();
|
||||
byte[] pbKey = ctx.getCard().getWalletPublicKey();
|
||||
|
||||
|
|
@ -531,21 +535,29 @@ public class EthEngine extends CoinEngine {
|
|||
String gasPrice = infuraResponse.getResult();
|
||||
gasPrice = gasPrice.substring(2);
|
||||
// rounding gas price to integer gwei
|
||||
BigInteger l = new BigInteger(gasPrice, 16).divide(BigInteger.valueOf(1000000000L)).multiply(BigInteger.valueOf(1000000000L));
|
||||
BigInteger l = new BigInteger(gasPrice, 16);//.divide(BigInteger.valueOf(1000000000L)).multiply(BigInteger.valueOf(1000000000L));
|
||||
|
||||
//val m = if (ctx.blockchain==Blockchain.Token) BigInteger.valueOf(60000) else BigInteger.valueOf(21000)
|
||||
// BigInteger m;
|
||||
// if (amount.getCurrency().equals("ETH")) m = BigInteger.valueOf(60000);
|
||||
// else m = BigInteger.valueOf(21000);
|
||||
BigInteger m = BigInteger.valueOf(60000);
|
||||
Log.i(TAG, "Infura gas price: "+gasPrice+" ("+l.toString()+")");
|
||||
BigInteger m = BigInteger.valueOf(21000);
|
||||
|
||||
Log.e(TAG, "fee multiplier: "+m.toString());
|
||||
|
||||
CoinEngine.InternalAmount weiMinFee = new CoinEngine.InternalAmount(l.multiply(m), "wei");
|
||||
CoinEngine.InternalAmount weiNormalFee = new CoinEngine.InternalAmount(weiMinFee.multiply(BigDecimal.valueOf(12)).divide(BigDecimal.valueOf(10)), "wei");
|
||||
CoinEngine.InternalAmount weiMaxFee = new CoinEngine.InternalAmount(weiMinFee.multiply(BigDecimal.valueOf(15)).divide(BigDecimal.valueOf(10)), "wei");
|
||||
|
||||
Log.i(TAG, "min fee : "+weiMinFee.toValueString()+" wei");
|
||||
Log.i(TAG, "normal fee: "+weiNormalFee.toValueString()+" wei");
|
||||
Log.i(TAG, "max fee : "+weiMaxFee.toValueString()+" wei");
|
||||
|
||||
coinData.minFee = convertToAmount(weiMinFee);
|
||||
coinData.normalFee = convertToAmount(weiNormalFee);
|
||||
coinData.maxFee = convertToAmount(weiMaxFee);
|
||||
|
||||
Log.i(TAG, "min fee : "+coinData.minFee.toString());
|
||||
Log.i(TAG, "normal fee: "+coinData.normalFee.toString());
|
||||
Log.i(TAG, "max fee : "+coinData.maxFee.toString());
|
||||
|
||||
blockchainRequestsCallbacks.onComplete(true);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,9 @@ public class TokenData extends EthData {
|
|||
super.saveToBundle(B);
|
||||
|
||||
try {
|
||||
B.putString("BalanceDecimalAlter", balanceAlter.toString());
|
||||
if( balanceAlter!=null ) {
|
||||
B.putString("BalanceDecimalAlter", balanceAlter.toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e("Can't save to bundle ", e.getMessage());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import android.text.InputFilter;
|
|||
import android.util.Log;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.tangem.data.Blockchain;
|
||||
import com.tangem.data.network.ServerApiInfura;
|
||||
import com.tangem.data.network.model.InfuraResponse;
|
||||
import com.tangem.domain.wallet.BalanceValidator;
|
||||
|
|
@ -38,6 +39,7 @@ import java.util.Arrays;
|
|||
|
||||
public class TokenEngine extends CoinEngine {
|
||||
|
||||
private static final String TAG = TokenEngine.class.getSimpleName();
|
||||
public TokenData coinData = null;
|
||||
|
||||
public TokenEngine(TangemContext ctx) throws Exception {
|
||||
|
|
@ -442,6 +444,8 @@ public class TokenEngine extends CoinEngine {
|
|||
}
|
||||
|
||||
private SignTask.PaymentToSign constructPaymentETH(Amount feeValue, Amount amountValue, boolean IncFee, String targetAddress) throws Exception {
|
||||
Log.e(TAG, "Construct ETH payment "+amountValue.toString()+" with fee "+feeValue.toString()+(IncFee?" including":" excluding"));
|
||||
|
||||
BigInteger nonceValue = coinData.getConfirmedTXCount();
|
||||
byte[] pbKey = ctx.getCard().getWalletPublicKey();
|
||||
|
||||
|
|
@ -523,6 +527,8 @@ public class TokenEngine extends CoinEngine {
|
|||
}
|
||||
|
||||
private SignTask.PaymentToSign constructPaymentToken(Amount feeValue, Amount amountValue, boolean IncFee, String targetAddress) throws Exception {
|
||||
Log.e(TAG, "Construct TOKEN payment "+amountValue.toString()+" with fee "+feeValue.toString()+(IncFee?" including":" excluding"));
|
||||
|
||||
BigInteger nonceValue = coinData.getConfirmedTXCount();
|
||||
byte[] pbKey = ctx.getCard().getWalletPublicKey();
|
||||
// boolean flag = (ctx.getCard().getSigningMethod() == TangemCard.SigningMethod.Sign_Hash_Validated_By_Issuer);
|
||||
|
|
@ -724,22 +730,32 @@ public class TokenEngine extends CoinEngine {
|
|||
public void onSuccess(String method, InfuraResponse infuraResponse) {
|
||||
String gasPrice = infuraResponse.getResult();
|
||||
gasPrice = gasPrice.substring(2);
|
||||
// rounding gas price to integer gwei
|
||||
BigInteger l = new BigInteger(gasPrice, 16);//.divide(BigInteger.valueOf(1000000000L)).multiply(BigInteger.valueOf(1000000000L));
|
||||
|
||||
//val m = if (ctx.blockchain==Blockchain.Token) BigInteger.valueOf(60000) else BigInteger.valueOf(21000)
|
||||
// rounding gas price to integer gwei
|
||||
BigInteger l = new BigInteger(gasPrice, 16);
|
||||
|
||||
Log.i(TAG, "Infura gas price: "+gasPrice+" ("+l.toString()+")");
|
||||
BigInteger m;
|
||||
if (amount.getCurrency().equals("ETH")) m = BigInteger.valueOf(60000);
|
||||
if (!amount.getCurrency().equals(Blockchain.Ethereum.getCurrency())) m = BigInteger.valueOf(60000);
|
||||
else m = BigInteger.valueOf(21000);
|
||||
|
||||
Log.i(TAG, "fee multiplier: "+m.toString());
|
||||
|
||||
|
||||
CoinEngine.InternalAmount weiMinFee = new CoinEngine.InternalAmount(l.multiply(m), "wei");
|
||||
CoinEngine.InternalAmount weiNormalFee = new CoinEngine.InternalAmount(weiMinFee.multiply(BigDecimal.valueOf(12)).divide(BigDecimal.valueOf(10)), "wei");
|
||||
CoinEngine.InternalAmount weiMaxFee = new CoinEngine.InternalAmount(weiMinFee.multiply(BigDecimal.valueOf(15)).divide(BigDecimal.valueOf(10)), "wei");
|
||||
Log.i(TAG, "min fee : "+weiMinFee.toValueString()+" wei");
|
||||
Log.i(TAG, "normal fee: "+weiNormalFee.toValueString()+" wei");
|
||||
Log.i(TAG, "max fee : "+weiMaxFee.toValueString()+" wei");
|
||||
|
||||
try {
|
||||
coinData.minFee = convertToAmount(weiMinFee);
|
||||
coinData.normalFee = convertToAmount(weiNormalFee);
|
||||
coinData.maxFee = convertToAmount(weiMaxFee);
|
||||
Log.i(TAG, "min fee : "+coinData.minFee.toString());
|
||||
Log.i(TAG, "normal fee: "+coinData.normalFee.toString());
|
||||
Log.i(TAG, "max fee : "+coinData.maxFee.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue