Updated on 2026-08-14

This commit is contained in:
Tangem 2018-12-19 00:15:53 +03:00
parent 87ec25e785
commit 3467a500a5
6 changed files with 68 additions and 427 deletions

View file

@ -171,6 +171,7 @@ public class ServerApiElectrum {
String host;
int port;
String proto;
// todo - get available URL list from coinEngine, remove if( ctx.getBlockchain()==...)
if (ctx.getBlockchain() == Blockchain.BitcoinTestNet) {
BitcoinNodeTestNet bitcoinNodeTestNet = BitcoinNodeTestNet.values()[new Random().nextInt(BitcoinNodeTestNet.values().length)];
host = bitcoinNodeTestNet.getHost();
@ -205,9 +206,9 @@ public class ServerApiElectrum {
this.port = port;
if (proto.equals("tcp")) {
return doElectrumRequestTcp(electrumRequest, host, port);
doElectrumRequestTcp(electrumRequest, host, port);
} else {
return doElectrumRequestSsl(electrumRequest, host, port);
doElectrumRequestSsl(electrumRequest, host, port);
}
} else if (ctx.getBlockchain() == Blockchain.Litecoin) {
LitecoinNode litecoinNode = LitecoinNode.values()[new Random().nextInt(LitecoinNode.values().length)];

View file

@ -663,140 +663,86 @@ public class BtcCashEngine extends CoinEngine {
serverApiElectrum.electrumRequestData(ctx, ElectrumRequest.listUnspent(convertToLegacyAddress(coinData.getWallet())));
}
private Integer buildSize(String outputAddress, String outFee, String outAmount) {
//todo - проверить, правильней было бы использовать constructPayment
private Integer calculateEstimatedTransactionSize(String outputAddress, String outAmount) {
try {
String myAddress = coinData.getWallet();
byte[] pbKey = ctx.getCard().getWalletPublicKey();
byte[] pbComprKey = ctx.getCard().getWalletPublicKeyRar();
SignTask.PaymentToSign ps=constructPayment(new Amount(outAmount, getBalanceCurrency()),new Amount("0.00",getFeeCurrency()), true, outputAddress );
OnNeedSendPayment onNeedSendPaymentBackup=onNeedSendPayment;
onNeedSendPayment=(tx)->{}; // empty function to bypass exception
// build script for our address
List<BtcData.UnspentTransaction> rawTxList = coinData.getUnspentTransactions();
byte[] outputScriptWeAreAbleToSpend = Transaction.Script.buildOutput(myAddress).bytes;
// collect unspent
ArrayList<UnspentOutputInfo> unspentOutputs = BTCUtils.getOutputs(rawTxList, outputScriptWeAreAbleToSpend);
Long fullAmount = 0L;
for (int i = 0; i < unspentOutputs.size(); i++) {
fullAmount += unspentOutputs.get(i).value;
}
// get first unspent
// val outPut = unspentOutputs[0]
// val outPutIndex = outPut.outputIndex
// get prev TX id;
// val prevTXID = rawTxList[0].txID//"f67b838d6e2c0c587f476f583843e93ff20368eaf96a798bdc25e01f53f8f5d2";
Long fees = FormatUtil.ConvertStringToLong(outFee);
Long amount = FormatUtil.ConvertStringToLong(outAmount);
amount -= fees;
Long change = fullAmount - fees - amount;
if (amount + fees > fullAmount) {
throw new Exception(String.format("Balance (%d) < amount (%d) + (%d)", fullAmount, change, amount));
}
byte[][] hashesForSign = new byte[unspentOutputs.size()][];
for (int i = 0; i < unspentOutputs.size(); i++) {
byte[] newTX = BTCUtils.buildTXForSign(myAddress, outputAddress, myAddress, unspentOutputs, i, amount, change);
byte[] hashData = Util.calculateSHA256(newTX);
byte[] doubleHashData = Util.calculateSHA256(hashData);
// Log.e("TX_BODY_1", BTCUtils.toHex(newTX))
// Log.e("TX_HASH_1", BTCUtils.toHex(hashData))
// Log.e("TX_HASH_2", BTCUtils.toHex(doubleHashData))
// unspentOutputs[i].bodyDoubleHash = doubleHashData
// unspentOutputs[i].bodyHash = hashData
hashesForSign[i] = doubleHashData;
}
byte[] signFromCard = new byte[64 * unspentOutputs.size()];
for (int i = 0; i < unspentOutputs.size(); i++) {
BigInteger r = new BigInteger(1, Arrays.copyOfRange(signFromCard, 0 + i * 64, 32 + i * 64));
BigInteger s = new BigInteger(1, Arrays.copyOfRange(signFromCard, 32 + i * 64, 64 + i * 64));
byte[] encodingSign = DerEncodingUtil.packSignDer(r, s, pbKey);
unspentOutputs.get(i).scriptForBuild = encodingSign;
}
byte[] realTX = BTCUtils.buildTXForSend(outputAddress, myAddress, unspentOutputs, amount, change);
return realTX.length;
}
catch (Exception e)
{
byte[][] hashesToSign=ps.getHashesToSign();
byte[] signFromCard = new byte[64 * hashesToSign.length];
byte[] txForSend=ps.onSignCompleted(signFromCard);
onNeedSendPayment=onNeedSendPaymentBackup;
Log.e(TAG,"txForSend.length="+String.valueOf(txForSend.length));
return txForSend.length;
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "Can't calculate transaction size -> use default!");
return 256;
}
}
private final static BigDecimal relayFee = new BigDecimal(0.00001);
@Override
public void requestFee(BlockchainRequestsCallbacks blockchainRequestsCallbacks, String targetAddress, Amount amount) throws Exception {
final int calcSize = buildSize(targetAddress, "0.00", amount.toValueString());
final int calcSize = calculateEstimatedTransactionSize(targetAddress, amount.toValueString());
Log.e(TAG, String.format("Estimated tx size %d", calcSize));
coinData.minFee=null;
coinData.maxFee=null;
coinData.normalFee=null;
final ServerApiCommon serverApiCommon = new ServerApiCommon();
final ServerApiElectrum serverApiElectrum = new ServerApiElectrum();
final ServerApiCommon.EstimateFeeListener estimateFeeListener = new ServerApiCommon.EstimateFeeListener() {
final ServerApiElectrum.ElectrumRequestDataListener electrumListener = new ServerApiElectrum.ElectrumRequestDataListener () {
@Override
public void onSuccess(int blockCount, String estimateFeeResponse) {
BigDecimal fee = new BigDecimal(estimateFeeResponse); // BTC per 1 kb
public void onSuccess(ElectrumRequest electrumRequest) {
BigDecimal fee;
if (electrumRequest.isMethod(ElectrumRequest.METHOD_GetFee)) {
try {
fee = new BigDecimal(electrumRequest.getResultString()); //fee per KB
if (fee.equals(BigDecimal.ZERO)) {
if (blockchainRequestsCallbacks.allowAdvance()) {
serverApiCommon.estimateFee(blockCount);
if (fee.equals(BigDecimal.ZERO)) {
serverApiElectrum.electrumRequestData(ctx, ElectrumRequest.getFee());
}
// if (calcSize != 0) {
fee = fee.multiply(new BigDecimal(calcSize)).divide(new BigDecimal(1024)); // (per KB -> per byte)*size
// } else {
// serverApiElectrum.electrumRequestData(ctx, ElectrumRequest.getFee());
// }
//compare fee to usual relay fee
if (fee.compareTo(relayFee) < 0) {
fee = relayFee;
}
fee = fee.setScale(8, RoundingMode.DOWN);
CoinEngine.Amount feeAmount = new CoinEngine.Amount(fee, ctx.getBlockchain().getCurrency());
coinData.minFee = feeAmount;
coinData.normalFee = feeAmount;
coinData.maxFee = feeAmount;
// if (coinData.minFee != null && coinData.normalFee != null && coinData.maxFee != null) {
blockchainRequestsCallbacks.onComplete(true);
// } else {
// blockchainRequestsCallbacks.onProgress();
// }
} catch (JSONException e) {
e.printStackTrace();
}
return;
}
if (calcSize != 0) {
fee = fee.multiply(new BigDecimal(calcSize)).divide(new BigDecimal(1024)); // per Kb -> per byte
} else {
if (blockchainRequestsCallbacks.allowAdvance()) {
serverApiCommon.estimateFee(blockCount);
}
return;
}
fee = fee.setScale(8, RoundingMode.DOWN);
switch (blockCount) {
case ServerApiCommon.ESTIMATE_FEE_MINIMAL:
coinData.minFee = new CoinEngine.Amount(fee, getFeeCurrency());
break;
case ServerApiCommon.ESTIMATE_FEE_NORMAL:
coinData.normalFee = new CoinEngine.Amount(fee, getFeeCurrency());
break;
case ServerApiCommon.ESTIMATE_FEE_PRIORITY:
coinData.maxFee = new CoinEngine.Amount(fee, getFeeCurrency());
break;
}
blockchainRequestsCallbacks.onComplete(true);
}
@Override
public void onFail(int blockCount, String message) {
// TODO - add fail counter to terminate after NNN tries
if (blockchainRequestsCallbacks.allowAdvance()) {
serverApiCommon.estimateFee(blockCount);
}
ctx.setError(ctx.getContext().getString(R.string.cannot_calculate_fee_wrong_data_received_from_node));
public void onFail(ElectrumRequest electrumRequest) {
ctx.setError(electrumRequest.getError());
blockchainRequestsCallbacks.onComplete(false);
}
};
serverApiCommon.setEstimateFee(estimateFeeListener);
serverApiCommon.estimateFee(ServerApiCommon.ESTIMATE_FEE_PRIORITY);
serverApiCommon.estimateFee(ServerApiCommon.ESTIMATE_FEE_NORMAL);
serverApiCommon.estimateFee(ServerApiCommon.ESTIMATE_FEE_MINIMAL);
serverApiElectrum.setElectrumRequestData(electrumListener);
serverApiElectrum.electrumRequestData(ctx, ElectrumRequest.getFee());
}
@Override

View file

@ -3,15 +3,14 @@ package com.tangem.domain.wallet.ltc;
import android.net.Uri;
import android.text.InputFilter;
import com.tangem.data.Blockchain;
import com.tangem.domain.wallet.BTCUtils;
import com.tangem.domain.wallet.BalanceValidator;
import com.tangem.domain.wallet.Base58;
import com.tangem.domain.wallet.CoinData;
import com.tangem.domain.wallet.CoinEngine;
import com.tangem.domain.wallet.TangemContext;
import com.tangem.domain.wallet.Transaction;
import com.tangem.domain.wallet.UnspentOutputInfo;
import com.tangem.domain.wallet.bch.BtcCashEngine;
import com.tangem.domain.wallet.btc.BtcData;
import com.tangem.tangemcard.data.TangemCard;
import com.tangem.tangemcard.reader.CardProtocol;
@ -32,7 +31,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class LtcEngine extends CoinEngine {
public class LtcEngine extends BtcCashEngine {
public BtcData coinData = null;
@ -356,7 +355,7 @@ public class LtcEngine extends CoinEngine {
}
@Override
public InternalAmount convertToInternalAmount(Amount amount) throws Exception {
public InternalAmount convertToInternalAmount(Amount amount) {
BigDecimal d = amount.multiply(new BigDecimal("100000000"));
return new InternalAmount(d, "Satoshi");
}
@ -370,7 +369,7 @@ public class LtcEngine extends CoinEngine {
}
@Override
public byte[] convertToByteArray(InternalAmount internalAmount) throws Exception {
public byte[] convertToByteArray(InternalAmount internalAmount) {
byte[] bytes = Util.longToByteArray(internalAmount.longValueExact());
byte[] reversed = new byte[bytes.length];
for (int i = 0; i < bytes.length; i++) reversed[i] = bytes[bytes.length - i - 1];
@ -473,7 +472,7 @@ public class LtcEngine extends CoinEngine {
}
@Override
public void onSignCompleted(byte[] signFromCard) throws Exception {
public byte[] onSignCompleted(byte[] signFromCard) throws Exception {
for (int i = 0; i < unspentOutputs.size(); ++i) {
BigInteger r = new BigInteger(1, Arrays.copyOfRange(signFromCard, i * 64, 32 + i * 64));
BigInteger s = new BigInteger(1, Arrays.copyOfRange(signFromCard, 32 + i * 64, 64 + i * 64));
@ -484,87 +483,8 @@ public class LtcEngine extends CoinEngine {
byte[] txForSend=BTCUtils.buildTXForSend(targetAddress, myAddress, unspentOutputs, amountFinal, changeFinal);
notifyOnNeedSendPayment(txForSend);
return txForSend;
}
};
}
// @Override
// public byte[] sign(Amount feeValue, Amount amountValue, boolean IncFee, String targetAddress, CardProtocol protocol) throws Exception {
//
// checkBlockchainDataExists();
//
// String myAddress = ctx.getCoinData().getWallet();
// byte[] pbKey = ctx.getCard().getWalletPublicKey();
//
// // Build script for our address
// List<BtcData.UnspentTransaction> rawTxList = coinData.getUnspentTransactions();
// byte[] outputScriptWeAreAbleToSpend = Transaction.Script.buildOutput(myAddress).bytes;
//
// // Collect unspent
// ArrayList<UnspentOutputInfo> unspentOutputs = BTCUtils.getOutputs(rawTxList, outputScriptWeAreAbleToSpend);
//
// long fullAmount = 0;
// for (int i = 0; i < unspentOutputs.size(); ++i) {
// fullAmount += unspentOutputs.get(i).value;
// }
//
//
// long fees = convertToInternalAmount(feeValue).longValueExact();
// long amount = convertToInternalAmount(amountValue).longValueExact();
// long change = fullAmount - amount;
// if (IncFee) {
// amount = amount - fees;
// } else {
// change = change - fees;
// }
//
// if (amount + fees > fullAmount) {
// throw new CardProtocol.TangemException_WrongAmount(String.format("Balance (%d) < change (%d) + amount (%d)", fullAmount, change, amount));
// }
//
// byte[][] dataForSign = new byte[unspentOutputs.size()][];
//
// for (int i = 0; i < unspentOutputs.size(); ++i) {
// byte[] newTX = BTCUtils.buildTXForSign(myAddress, targetAddress, myAddress, unspentOutputs, i, amount, change);
//
// byte[] hashData = Util.calculateSHA256(newTX);
// byte[] doubleHashData = Util.calculateSHA256(hashData);
//
// unspentOutputs.get(i).bodyDoubleHash = doubleHashData;
// unspentOutputs.get(i).bodyHash = hashData;
//
// if (ctx.getCard().getSigningMethod() == TangemCard.SigningMethod.Sign_Raw || ctx.getCard().getSigningMethod() == TangemCard.SigningMethod.Sign_Raw_Validated_By_Issuer) {
// dataForSign[i] = newTX;
// } else {
// dataForSign[i] = doubleHashData;
// }
// }
//
// byte[] signFromCard;
// if (ctx.getCard().getSigningMethod() == TangemCard.SigningMethod.Sign_Raw || ctx.getCard().getSigningMethod() == TangemCard.SigningMethod.Sign_Raw_Validated_By_Issuer) {
// ByteArrayOutputStream bs = new ByteArrayOutputStream();
// if (dataForSign.length > 10) throw new Exception("To much hashes in one transaction!");
// for (int i = 0; i < dataForSign.length; i++) {
// if (i != 0 && dataForSign[0].length != dataForSign[i].length)
// throw new Exception("Hashes length must be identical!");
// bs.write(dataForSign[i]);
// }
// signFromCard = protocol.run_SignRaw(PINStorage.getPIN2(), "sha-256x2",bs.toByteArray(),null,null,null).getTLV(TLV.Tag.TAG_Signature).Value;
// } else {
// //ctx.getCard().getSigningMethod() == TangemCard.SigningMethod.Sign_Hash_Validated_By_Issuer, null, ctx.getCard().getIssuer()
// signFromCard = protocol.run_SignHashes(PINStorage.getPIN2(), dataForSign, null, null, null).getTLV(TLV.Tag.TAG_Signature).Value;
// // TODO slice signFromCard to hashes.length parts
// }
//
// for (int i = 0; i < unspentOutputs.size(); ++i) {
// BigInteger r = new BigInteger(1, Arrays.copyOfRange(signFromCard, i * 64, 32 + i * 64));
// BigInteger s = new BigInteger(1, Arrays.copyOfRange(signFromCard, 32 + i * 64, 64 + i * 64));
// s = CryptoUtil.toCanonicalised(s);
//
// unspentOutputs.get(i).scriptForBuild = DerEncodingUtil.packSignDer(r, s, pbKey);
// }
//
// return BTCUtils.buildTXForSend(targetAddress, myAddress, unspentOutputs, amount, change);
// }
}

View file

@ -20,6 +20,7 @@ public class TokenData extends EthData {
return balanceAlter;
}
public void setBalanceAlterInInternalUnits(CoinEngine.InternalAmount value) {
balanceAlter = value;
}

View file

@ -88,7 +88,8 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
// feeRequestSuccess = false
// balanceRequestSuccess = false
if (ctx.blockchain == Blockchain.Ethereum || ctx.blockchain == Blockchain.EthereumTestNet || ctx.blockchain == Blockchain.Token) {
if (ctx.blockchain == Blockchain.Ethereum || ctx.blockchain == Blockchain.EthereumTestNet || ctx.blockchain == Blockchain.Token ||
ctx.blockchain == Blockchain.BitcoinCash || ctx.blockchain == Blockchain.Litecoin) {
rgFee.isEnabled = false
// requestInfura(ServerApiInfura.INFURA_ETH_GAS_PRICE)

View file

@ -92,8 +92,6 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
ctx = TangemContext.loadFromBundle(activity, activity?.intent?.extras)
lastTag = activity?.intent?.getParcelableExtra(Constant.EXTRA_LAST_DISCOVERED_TAG)
//localStorage = activity?.let { CardDataSubstitutionProvider(it) }!!
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
@ -206,201 +204,6 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
Toast.makeText(activity, getString(R.string.no_connection), Toast.LENGTH_SHORT).show()
}
// request electrum listener
// val electrumBodyListener: ServerApiElectrum.ElectrumRequestDataListener = object : ServerApiElectrum.ElectrumRequestDataListener {
// override fun onSuccess(electrumRequest: ElectrumRequest?) {
// if (electrumRequest!!.isMethod(ElectrumRequest.METHOD_GetBalance)) {
// try {
// val walletAddress = electrumRequest.params.getString(0)
// val confBalance = electrumRequest.result.getLong("confirmed")
// val unconfirmedBalance = electrumRequest.result.getLong("unconfirmed")
// ctx.coinData!!.isBalanceReceived = true
// (ctx.coinData!! as BtcData).setBalanceConfirmed(confBalance)
// (ctx.coinData!! as BtcData).balanceUnconfirmed = unconfirmedBalance
// (ctx.coinData!! as BtcData).validationNodeDescription = serverApiElectrum.validationNodeDescription
// } catch (e: JSONException) {
// e.printStackTrace()
// Log.e(TAG, "FAIL METHOD_GetBalance JSONException")
// }
// }
//
// if (electrumRequest.isMethod(ElectrumRequest.METHOD_ListUnspent)) {
// try {
// val walletAddress = electrumRequest.params.getString(0)
// val jsUnspentArray = electrumRequest.resultArray
// try {
// (ctx.coinData!! as BtcData).unspentTransactions.clear()
// for (i in 0 until jsUnspentArray.length()) {
// val jsUnspent = jsUnspentArray.getJSONObject(i)
// val trUnspent = BtcData.UnspentTransaction()
// trUnspent.txID = jsUnspent.getString("tx_hash")
// trUnspent.Amount = jsUnspent.getInt("value")
// trUnspent.Height = jsUnspent.getInt("height")
// (ctx.coinData!! as BtcData).unspentTransactions.add(trUnspent)
// }
// } catch (e: JSONException) {
// e.printStackTrace()
// Log.e(TAG, "FAIL METHOD_ListUnspent JSONException")
// }
//
// for (i in 0 until jsUnspentArray.length()) {
// val jsUnspent = jsUnspentArray.getJSONObject(i)
// val height = jsUnspent.getInt("height")
// val hash = jsUnspent.getString("tx_hash")
// if (height != -1) {
// requestElectrum(ElectrumRequest.getTransaction(walletAddress, hash))
// }
// }
// } catch (e: JSONException) {
// e.printStackTrace()
// }
// }
//
// if (electrumRequest.isMethod(ElectrumRequest.METHOD_GetTransaction)) {
// try {
// val txHash = electrumRequest.txHash
// val raw = electrumRequest.resultString
// val listTx = (ctx.coinData!! as BtcData).unspentTransactions
// for (tx in listTx) {
// if (tx.txID == txHash)
// tx.Raw = raw
// }
// } catch (e: JSONException) {
// e.printStackTrace()
// }
// }
//
// if (electrumRequest.isMethod(ElectrumRequest.METHOD_SendTransaction)) {
//
// }
//
// counterMinus()
// }
//
// override fun onFail(method: String?) {
//
// }
// }
// serverApiElectrum.setElectrumRequestData(electrumBodyListener)
// // request infura listener
// val infuraBodyListener: ServerApiInfura.InfuraBodyListener = object : ServerApiInfura.InfuraBodyListener {
// override fun onSuccess(method: String, infuraResponse: InfuraResponse) {
// when (method) {
// ServerApiInfura.INFURA_ETH_GET_BALANCE -> {
// var balanceCap = infuraResponse.result
// balanceCap = balanceCap.substring(2)
// val l = BigInteger(balanceCap, 16)
//// val d = l.divide(BigInteger("1000000000000000000", 10))
//// val balance = d.toLong()
//
//// (ctx.coinData!! as EthData).setBalanceConfirmed(balance)
//// (ctx.coinData!! as EthData).balanceUnconfirmed = 0L
// if (ctx.blockchain != Blockchain.Token) {
// (ctx.coinData!! as EthData).isBalanceReceived = true
// (ctx.coinData!! as EthData).balanceInInternalUnits = CoinEngine.InternalAmount(l.toBigDecimal(), "wei")
// } else {
// (ctx.coinData!! as TokenData).isBalanceReceived = true
// //(ctx.coinData!! as TokenData).balanceInInternalUnits = CoinEngine.InternalAmount(l.toBigDecimal(),ctx.card.tokenSymbol)
// (ctx.coinData!! as TokenData).balanceAlterInInternalUnits = CoinEngine.InternalAmount(l.toBigDecimal(), "wei")
// }
//
//// Log.i("$TAG eth_get_balance", balanceCap)
// }
//
// ServerApiInfura.INFURA_ETH_GET_TRANSACTION_COUNT -> {
// var nonce = infuraResponse.result
// nonce = nonce.substring(2)
// val count = BigInteger(nonce, 16)
// (ctx.coinData!! as EthData).confirmedTXCount = count
//
//
//// Log.i("$TAG eth_getTransCount", nonce)
// }
//
// ServerApiInfura.INFURA_ETH_GET_PENDING_COUNT -> {
// var pending = infuraResponse.result
// pending = pending.substring(2)
// val count = BigInteger(pending, 16)
// (ctx.coinData!! as EthData).unconfirmedTXCount = count
//
//// Log.i("$TAG eth_getPendingTxCount", pending)
// }
//
// ServerApiInfura.INFURA_ETH_CALL -> {
// try {
// var balanceCap = infuraResponse.result
// balanceCap = balanceCap.substring(2)
// val l = BigInteger(balanceCap, 16)
// val balance = l.toLong()
//// if (l.compareTo(BigInteger.ZERO) == 0) {
//// //ctx.card!!.blockchainID = Blockchain.Ethereum.id
//// ctx.card!!.addTokenToBlockchainName()
////
//// //TODO check
//// //ctx.blockchain=lBlockchain.Ethereum
////
//// requestCounter--
//// if (requestCounter == 0) srl!!.isRefreshing = false
////
//// requestInfura(ServerApiCommon.INFURA_ETH_GET_BALANCE, "")
//// requestInfura(ServerApiCommon.INFURA_ETH_GET_TRANSACTION_COUNT, "")
//// requestInfura(ServerApiCommon.INFURA_ETH_GET_PENDING_COUNT, "")
//// return
//// }
// (ctx.coinData!! as EthData).balanceInInternalUnits = CoinEngine.InternalAmount(l.toBigDecimal(), ctx.card.tokenSymbol)
//
//// Log.i("$TAG eth_call", balanceCap)
//
// requestInfura(ServerApiInfura.INFURA_ETH_GET_BALANCE, "")
// requestInfura(ServerApiInfura.INFURA_ETH_GET_TRANSACTION_COUNT, "")
// requestInfura(ServerApiInfura.INFURA_ETH_GET_PENDING_COUNT, "")
// } catch (e: JSONException) {
// e.printStackTrace()
// } catch (e: NumberFormatException) {
// e.printStackTrace()
// } catch (e: Exception) {
// e.printStackTrace()
// }
// }
//
// ServerApiInfura.INFURA_ETH_SEND_RAW_TRANSACTION -> {
// try {
// var hashTX: String
// try {
// val tmp = infuraResponse.result
// hashTX = tmp
// } catch (e: JSONException) {
// return
// }
//
// if (hashTX.startsWith("0x") || hashTX.startsWith("0X")) {
// hashTX = hashTX.substring(2)
// }
//
// Log.e("$TAG TX_RESULT", hashTX)
//
// val nonce = (ctx.coinData!! as EthData).confirmedTXCount
// nonce.add(BigInteger.valueOf(1))
// (ctx.coinData!! as EthData).confirmedTXCount = nonce
//
// Log.e("$TAG TX_RESULT", hashTX)
//
// } catch (e: Exception) {
// e.printStackTrace()
// }
// }
// }
//
// counterMinus()
// }
//
// override fun onFail(method: String, message: String) {
//
// }
// }
// serverApiInfura.setInfuraResponse(infuraBodyListener)
// request card verify and get info listener
val cardVerifyAndGetInfoListener: ServerApiTangem.CardVerifyAndGetInfoListener = object : ServerApiTangem.CardVerifyAndGetInfoListener {
override fun onSuccess(cardVerifyAndGetArtworkResponse: CardVerifyAndGetInfo.Response?) {
@ -842,12 +645,12 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
)
// TODO - move requestRateInfo to CoinEngine
// Bitcoin
if (ctx.blockchain == Blockchain.Bitcoin || ctx.blockchain == Blockchain.BitcoinTestNet) {
ctx.coinData.setIsBalanceEqual(true)
// requestElectrum(ElectrumRequest.checkBalance(ctx.coinData!!.wallet))
// requestElectrum(ElectrumRequest.listUnspent(ctx.coinData!!.wallet))
requestRateInfo("bitcoin")
}
@ -855,57 +658,26 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
if (ctx.blockchain == Blockchain.Litecoin) {
ctx.coinData.setIsBalanceEqual(true)
requestElectrum(ElectrumRequest.checkBalance(ctx.coinData!!.wallet))
requestElectrum(ElectrumRequest.listUnspent(ctx.coinData!!.wallet))
requestRateInfo("litecoin")
}
// BitcoinCash
else if (ctx.blockchain == Blockchain.BitcoinCash) {
ctx.coinData.setIsBalanceEqual(true)
// val engine = CoinEngineFactory.create(ctx)
//
// requestElectrum(ElectrumRequest.checkBalance((engine as BtcCashEngine).convertToLegacyAddress(ctx.coinData!!.wallet)))
// requestElectrum(ElectrumRequest.listUnspent(engine.convertToLegacyAddress(ctx.coinData!!.wallet)))
requestRateInfo("bitcoin-cash")
}
// Ethereum
else if (ctx.blockchain == Blockchain.Ethereum || ctx.blockchain == Blockchain.EthereumTestNet) {
// requestInfura(ServerApiInfura.INFURA_ETH_GET_BALANCE, "")
// requestInfura(ServerApiInfura.INFURA_ETH_GET_TRANSACTION_COUNT, "")
// requestInfura(ServerApiInfura.INFURA_ETH_GET_PENDING_COUNT, "")
requestRateInfo("ethereum")
}
// Token
else if (ctx.blockchain == Blockchain.Token) {
// val engine = CoinEngineFactory.create(ctx)
// requestInfura(ServerApiInfura.INFURA_ETH_CALL, (engine as TokenEngine).getContractAddress(ctx.card))
requestRateInfo("ethereum")
}
}
// private fun requestElectrum(electrumRequest: ElectrumRequest) {
// if (UtilHelper.isOnline(context as Activity)) {
// requestCounter++
// serverApiElectrum.electrumRequestData(ctx, electrumRequest)
// } else {
// Toast.makeText(activity, getString(R.string.no_connection), Toast.LENGTH_SHORT).show()
// srl?.isRefreshing = false
// }
// }
// private fun requestInfura(method: String, contract: String) {
// if (UtilHelper.isOnline(context as Activity)) {
// requestCounter++
// serverApiInfura.infura(method, 67, ctx.coinData!!.wallet, contract, "")
// } else {
// Toast.makeText(activity, getString(R.string.no_connection), Toast.LENGTH_SHORT).show()
// srl?.isRefreshing = false
// }
// }
private fun requestVerifyAndGetInfo() {
if (UtilHelper.isOnline(context as Activity)) {
if ((ctx.card!!.isOnlineVerified == null || !ctx.card!!.isOnlineVerified)) {