Updated on 2026-08-14
This commit is contained in:
parent
ef0a5f379d
commit
dae8c94c48
7 changed files with 442 additions and 250 deletions
|
|
@ -271,5 +271,5 @@ public abstract class CoinEngine {
|
|||
void onComplete(Boolean success);
|
||||
boolean needTerminate();
|
||||
}
|
||||
public abstract void requestBalanceAndUnspentTransactions(BlockchainRequestsNotifications blockchainRequestsNotifications);
|
||||
public abstract void requestBalanceAndUnspentTransactions(BlockchainRequestsNotifications blockchainRequestsNotifications) throws Exception;
|
||||
}
|
||||
|
|
@ -2,7 +2,10 @@ package com.tangem.domain.wallet.bch;
|
|||
|
||||
import android.net.Uri;
|
||||
import android.text.InputFilter;
|
||||
import android.util.Log;
|
||||
|
||||
import com.tangem.data.network.ElectrumRequest;
|
||||
import com.tangem.data.network.ServerApiElectrum;
|
||||
import com.tangem.domain.wallet.BCHUtils;
|
||||
import com.tangem.tangemcard.reader.CardProtocol;
|
||||
import com.tangem.domain.wallet.BalanceValidator;
|
||||
|
|
@ -21,6 +24,10 @@ import com.tangem.util.DerEncodingUtil;
|
|||
import com.tangem.tangemcard.util.Util;
|
||||
import com.tangem.wallet.R;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
|
|
@ -33,6 +40,7 @@ import java.util.List;
|
|||
|
||||
public class BtcCashEngine extends CoinEngine {
|
||||
|
||||
private static final String TAG = BtcCashEngine.class.getSimpleName();
|
||||
public BtcData coinData = null;
|
||||
|
||||
public BtcCashEngine(TangemContext context) throws Exception {
|
||||
|
|
@ -167,7 +175,7 @@ public class BtcCashEngine extends CoinEngine {
|
|||
//
|
||||
// return true;
|
||||
|
||||
if(CashAddr.isValidCashAddress(address))
|
||||
if (CashAddr.isValidCashAddress(address))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
|
@ -221,7 +229,7 @@ public class BtcCashEngine extends CoinEngine {
|
|||
if (fee.isZero() || amount.isZero())
|
||||
return false;
|
||||
|
||||
if (isIncludeFee && (amount.compareTo(coinData.getBalanceInInternalUnits()) > 0 || amount.compareTo(fee)<0))
|
||||
if (isIncludeFee && (amount.compareTo(coinData.getBalanceInInternalUnits()) > 0 || amount.compareTo(fee) < 0))
|
||||
return false;
|
||||
|
||||
if (!isIncludeFee && amount.add(fee).compareTo(coinData.getBalanceInInternalUnits()) > 0)
|
||||
|
|
@ -316,8 +324,8 @@ public class BtcCashEngine extends CoinEngine {
|
|||
@Override
|
||||
public String getBalanceEquivalent() {
|
||||
if (coinData == null || !coinData.getAmountEquivalentDescriptionAvailable()) return "";
|
||||
Amount balance=getBalance();
|
||||
if( balance==null ) return "";
|
||||
Amount balance = getBalance();
|
||||
if (balance == null) return "";
|
||||
return balance.toEquivalentString(coinData.getRate());
|
||||
}
|
||||
|
||||
|
|
@ -436,9 +444,7 @@ public class BtcCashEngine extends CoinEngine {
|
|||
try {
|
||||
String wallet = calculateAddress(ctx.getCard().getWalletPublicKeyRar());
|
||||
ctx.getCoinData().setWallet(wallet);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
ctx.getCoinData().setWallet("ERROR");
|
||||
throw new CardProtocol.TangemException("Can't define wallet address");
|
||||
}
|
||||
|
|
@ -482,9 +488,9 @@ public class BtcCashEngine extends CoinEngine {
|
|||
final long amountFinal = amount;
|
||||
final long changeFinal = change;
|
||||
|
||||
byte[][] txForSign= new byte[unspentOutputs.size()][];
|
||||
byte[][] bodyHash= new byte[unspentOutputs.size()][];
|
||||
byte[][] bodyDoubleHash= new byte[unspentOutputs.size()][];
|
||||
byte[][] txForSign = new byte[unspentOutputs.size()][];
|
||||
byte[][] bodyHash = new byte[unspentOutputs.size()][];
|
||||
byte[][] bodyDoubleHash = new byte[unspentOutputs.size()][];
|
||||
|
||||
for (int i = 0; i < unspentOutputs.size(); ++i) {
|
||||
txForSign[i] = BCHUtils.buildTXForSign(srcLegacyAddress, destLegacyAddress, srcLegacyAddress, unspentOutputs, i, amount, change);
|
||||
|
|
@ -496,12 +502,12 @@ public class BtcCashEngine extends CoinEngine {
|
|||
|
||||
@Override
|
||||
public boolean isSigningMethodSupported(TangemCard.SigningMethod signingMethod) {
|
||||
return signingMethod==TangemCard.SigningMethod.Sign_Hash || signingMethod==TangemCard.SigningMethod.Sign_Raw;
|
||||
return signingMethod == TangemCard.SigningMethod.Sign_Hash || signingMethod == TangemCard.SigningMethod.Sign_Raw;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[][] getHashesToSign() throws Exception {
|
||||
byte[][] dataForSign=new byte[unspentOutputs.size()][];
|
||||
byte[][] dataForSign = new byte[unspentOutputs.size()][];
|
||||
if (txForSign.length > 10) throw new Exception("To much hashes in one transaction!");
|
||||
for (int i = 0; i < unspentOutputs.size(); ++i) {
|
||||
dataForSign[i] = bodyDoubleHash[i];
|
||||
|
|
@ -541,10 +547,108 @@ public class BtcCashEngine extends CoinEngine {
|
|||
unspentOutputs.get(i).scriptForBuild = DerEncodingUtil.packSignDerBitcoinCash(r, s, pbKey);
|
||||
}
|
||||
|
||||
byte[] txForSend=BCHUtils.buildTXForSend(destLegacyAddress, srcLegacyAddress, unspentOutputs, amountFinal, changeFinal);
|
||||
byte[] txForSend = BCHUtils.buildTXForSend(destLegacyAddress, srcLegacyAddress, unspentOutputs, amountFinal, changeFinal);
|
||||
|
||||
notifyOnNeedSendPayment(txForSend);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestBalanceAndUnspentTransactions(BlockchainRequestsNotifications blockchainRequestsNotifications) throws Exception {
|
||||
final ServerApiElectrum serverApiElectrum = new ServerApiElectrum();
|
||||
|
||||
ServerApiElectrum.ElectrumRequestDataListener electrumBodyListener = new ServerApiElectrum.ElectrumRequestDataListener() {
|
||||
@Override
|
||||
public void onSuccess(ElectrumRequest electrumRequest) {
|
||||
if (electrumRequest.isMethod(ElectrumRequest.METHOD_GetBalance)) {
|
||||
try {
|
||||
String walletAddress = electrumRequest.getParams().getString(0);
|
||||
if (!walletAddress.equals(coinData.getWallet())) {
|
||||
// todo - check
|
||||
throw new Exception("Invalid wallet address in answer!");
|
||||
}
|
||||
Long confBalance = electrumRequest.getResult().getLong("confirmed");
|
||||
Long unconfirmedBalance = electrumRequest.getResult().getLong("unconfirmed");
|
||||
coinData.setBalanceReceived(true);
|
||||
coinData.setBalanceConfirmed(confBalance);
|
||||
coinData.setBalanceUnconfirmed(unconfirmedBalance);
|
||||
coinData.setValidationNodeDescription(serverApiElectrum.getValidationNodeDescription());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "FAIL METHOD_GetBalance JSONException");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "FAIL METHOD_GetBalance Exception");
|
||||
}
|
||||
}
|
||||
|
||||
if (electrumRequest.isMethod(ElectrumRequest.METHOD_ListUnspent)) {
|
||||
try {
|
||||
String walletAddress = electrumRequest.getParams().getString(0);
|
||||
JSONArray jsUnspentArray = electrumRequest.getResultArray();
|
||||
try {
|
||||
coinData.getUnspentTransactions().clear();
|
||||
for (int i = 0; i < jsUnspentArray.length(); i++) {
|
||||
JSONObject jsUnspent = jsUnspentArray.getJSONObject(i);
|
||||
BtcData.UnspentTransaction trUnspent = new BtcData.UnspentTransaction();
|
||||
trUnspent.txID = jsUnspent.getString("tx_hash");
|
||||
trUnspent.Amount = jsUnspent.getInt("value");
|
||||
trUnspent.Height = jsUnspent.getInt("height");
|
||||
coinData.getUnspentTransactions().add(trUnspent);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "FAIL METHOD_ListUnspent JSONException");
|
||||
}
|
||||
|
||||
for (int i = 0; i < jsUnspentArray.length(); i++) {
|
||||
JSONObject jsUnspent = jsUnspentArray.getJSONObject(i);
|
||||
Integer height = jsUnspent.getInt("height");
|
||||
String hash = jsUnspent.getString("tx_hash");
|
||||
if (height != -1) {
|
||||
if (!blockchainRequestsNotifications.needTerminate()) {
|
||||
serverApiElectrum.electrumRequestData(ctx, ElectrumRequest.getTransaction(walletAddress, hash));
|
||||
} else {
|
||||
serverApiElectrum.setErrorOccured("Terminated by user");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (electrumRequest.isMethod(ElectrumRequest.METHOD_GetTransaction)) {
|
||||
try {
|
||||
String txHash = electrumRequest.txHash;
|
||||
String raw = electrumRequest.getResultString();
|
||||
for (BtcData.UnspentTransaction tx : coinData.getUnspentTransactions()) {
|
||||
if (tx.txID.equals(txHash))
|
||||
tx.Raw = raw;
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (!serverApiElectrum.hasRequests()) {
|
||||
blockchainRequestsNotifications.onComplete(serverApiElectrum.isErrorOccured());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String method) {
|
||||
if (!serverApiElectrum.hasRequests()) {
|
||||
blockchainRequestsNotifications.onComplete(serverApiElectrum.isErrorOccured());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
serverApiElectrum.setElectrumRequestData(electrumBodyListener);
|
||||
|
||||
serverApiElectrum.electrumRequestData(ctx, ElectrumRequest.checkBalance(convertToLegacyAddress(coinData.getWallet())));
|
||||
serverApiElectrum.electrumRequestData(ctx, ElectrumRequest.listUnspent(convertToLegacyAddress(coinData.getWallet())));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -608,80 +608,6 @@ public class BtcEngine extends CoinEngine {
|
|||
}
|
||||
};
|
||||
|
||||
// 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);
|
||||
|
||||
serverApiElectrum.electrumRequestData(ctx, ElectrumRequest.checkBalance(coinData.getWallet()));
|
||||
|
|
|
|||
|
|
@ -62,8 +62,12 @@ public class EthData extends CoinData {
|
|||
public void loadFromBundle(Bundle B) {
|
||||
super.loadFromBundle(B);
|
||||
|
||||
String currency = B.getString("BalanceCurrency");
|
||||
balance = new CoinEngine.InternalAmount(B.getString("BalanceDecimal"), currency);
|
||||
if (B.containsKey("BalanceCurrency") && B.containsKey("BalanceDecimal")) {
|
||||
String currency = B.getString("BalanceCurrency");
|
||||
balance = new CoinEngine.InternalAmount(B.getString("BalanceDecimal"), currency);
|
||||
} else {
|
||||
balance = null;
|
||||
}
|
||||
|
||||
if (B.containsKey("confirmTx"))
|
||||
countConfirmedTX = new BigInteger(B.getString("confirmTx"), 16);
|
||||
|
|
@ -75,8 +79,10 @@ public class EthData extends CoinData {
|
|||
public void saveToBundle(Bundle B) {
|
||||
super.saveToBundle(B);
|
||||
try {
|
||||
B.putString("BalanceCurrency", balance.getCurrency());
|
||||
B.putString("BalanceDecimal", balance.toString());
|
||||
if (balance != null) {
|
||||
B.putString("BalanceCurrency", balance.getCurrency());
|
||||
B.putString("BalanceDecimal", balance.toString());
|
||||
}
|
||||
|
||||
B.putString("confirmTx", getConfirmedTXCount().toString(16));
|
||||
B.putString("unconfirmTx", getUnconfirmedTXCount().toString(16));
|
||||
|
|
|
|||
|
|
@ -1,22 +1,30 @@
|
|||
package com.tangem.domain.wallet.eth;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.net.Uri;
|
||||
import android.text.InputFilter;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.tangem.data.network.ServerApiInfura;
|
||||
import com.tangem.data.network.model.InfuraResponse;
|
||||
import com.tangem.domain.wallet.BalanceValidator;
|
||||
import com.tangem.data.Blockchain;
|
||||
import com.tangem.domain.wallet.CoinData;
|
||||
import com.tangem.domain.wallet.CoinEngine;
|
||||
import com.tangem.domain.wallet.CoinEngineFactory;
|
||||
import com.tangem.domain.wallet.ECDSASignatureETH;
|
||||
import com.tangem.domain.wallet.EthTransaction;
|
||||
import com.tangem.domain.wallet.Keccak256;
|
||||
import com.tangem.domain.wallet.token.TokenData;
|
||||
import com.tangem.domain.wallet.token.TokenEngine;
|
||||
import com.tangem.tangemcard.data.TangemCard;
|
||||
import com.tangem.domain.wallet.TangemContext;
|
||||
import com.tangem.domain.wallet.BTCUtils;
|
||||
import com.tangem.tangemcard.tasks.SignTask;
|
||||
import com.tangem.util.CryptoUtil;
|
||||
import com.tangem.util.DecimalDigitsInputFilter;
|
||||
import com.tangem.util.UtilHelper;
|
||||
import com.tangem.wallet.R;
|
||||
|
||||
import org.bitcoinj.core.ECKey;
|
||||
|
|
@ -57,7 +65,7 @@ public class EthEngine extends CoinEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean awaitingConfirmation(){
|
||||
public boolean awaitingConfirmation() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -71,10 +79,10 @@ public class EthEngine extends CoinEngine {
|
|||
|
||||
@Override
|
||||
public String getBalanceHTML() {
|
||||
Amount balance=getBalance();
|
||||
if( balance!=null ) {
|
||||
Amount balance = getBalance();
|
||||
if (balance != null) {
|
||||
return balance.toDescriptionString(getDecimals());
|
||||
}else{
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
@ -93,7 +101,7 @@ public class EthEngine extends CoinEngine {
|
|||
|
||||
@Override
|
||||
public boolean isBalanceNotZero() {
|
||||
if( coinData ==null ) return false;
|
||||
if (coinData == null) return false;
|
||||
if (coinData.getBalanceInInternalUnits() == null) return false;
|
||||
return coinData.getBalanceInInternalUnits().notZero();
|
||||
}
|
||||
|
|
@ -183,8 +191,8 @@ public class EthEngine extends CoinEngine {
|
|||
|
||||
@Override
|
||||
public String getBalanceEquivalent() {
|
||||
Amount balance=getBalance();
|
||||
if( balance==null ) return "";
|
||||
Amount balance = getBalance();
|
||||
if (balance == null) return "";
|
||||
return balance.toEquivalentString(coinData.getRate());
|
||||
}
|
||||
|
||||
|
|
@ -200,8 +208,8 @@ public class EthEngine extends CoinEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public InternalAmount convertToInternalAmount(Amount amount){
|
||||
return new InternalAmount(amount.multiply(new BigDecimal("1000000000000000000")),"wei");
|
||||
public InternalAmount convertToInternalAmount(Amount amount) {
|
||||
return new InternalAmount(amount.multiply(new BigDecimal("1000000000000000000")), "wei");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -218,7 +226,7 @@ public class EthEngine extends CoinEngine {
|
|||
|
||||
@Override
|
||||
public boolean hasBalanceInfo() {
|
||||
return coinData.getBalanceInInternalUnits()!=null;
|
||||
return coinData.getBalanceInInternalUnits() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -254,14 +262,14 @@ public class EthEngine extends CoinEngine {
|
|||
|
||||
@Override
|
||||
public InputFilter[] getAmountInputFilters() {
|
||||
return new InputFilter[] { new DecimalDigitsInputFilter(getDecimals()) };
|
||||
return new InputFilter[]{new DecimalDigitsInputFilter(getDecimals())};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkNewTransactionAmount(Amount amount){
|
||||
if( coinData ==null ) return false;
|
||||
Amount balance=getBalance();
|
||||
if (balance==null || amount.compareTo(balance) > 0) {
|
||||
public boolean checkNewTransactionAmount(Amount amount) {
|
||||
if (coinData == null) return false;
|
||||
Amount balance = getBalance();
|
||||
if (balance == null || amount.compareTo(balance) > 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
@ -292,7 +300,7 @@ public class EthEngine extends CoinEngine {
|
|||
try {
|
||||
BigDecimal cardBalance = getBalance();
|
||||
|
||||
if (isFeeIncluded && (amount.compareTo(cardBalance) > 0 || amount.compareTo(fee)<0))
|
||||
if (isFeeIncluded && (amount.compareTo(cardBalance) > 0 || amount.compareTo(fee) < 0))
|
||||
return false;
|
||||
|
||||
if (!isFeeIncluded && amount.add(fee).compareTo(cardBalance) > 0)
|
||||
|
|
@ -346,9 +354,7 @@ public class EthEngine extends CoinEngine {
|
|||
try {
|
||||
Amount feeValue = new Amount(fee, ctx.getBlockchain().getCurrency());
|
||||
return feeValue.toEquivalentString(coinData.getRate());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "";
|
||||
}
|
||||
|
|
@ -380,8 +386,8 @@ public class EthEngine extends CoinEngine {
|
|||
BigInteger nonceValue = coinData.getConfirmedTXCount();
|
||||
byte[] pbKey = ctx.getCard().getWalletPublicKey();
|
||||
|
||||
BigInteger weiFee=convertToInternalAmount(feeValue).toBigIntegerExact();
|
||||
BigInteger weiAmount=convertToInternalAmount(amountValue).toBigIntegerExact();
|
||||
BigInteger weiFee = convertToInternalAmount(feeValue).toBigIntegerExact();
|
||||
BigInteger weiAmount = convertToInternalAmount(amountValue).toBigIntegerExact();
|
||||
|
||||
if (IncFee) {
|
||||
weiAmount = weiAmount.subtract(weiFee);
|
||||
|
|
@ -403,7 +409,7 @@ public class EthEngine extends CoinEngine {
|
|||
return new SignTask.PaymentToSign() {
|
||||
@Override
|
||||
public boolean isSigningMethodSupported(TangemCard.SigningMethod signingMethod) {
|
||||
return signingMethod==TangemCard.SigningMethod.Sign_Hash;
|
||||
return signingMethod == TangemCard.SigningMethod.Sign_Hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -430,7 +436,7 @@ public class EthEngine extends CoinEngine {
|
|||
|
||||
@Override
|
||||
public void onSignCompleted(byte[] signFromCard) throws Exception {
|
||||
byte[] for_hash=tx.getRawHash();
|
||||
byte[] for_hash = tx.getRawHash();
|
||||
BigInteger r = new BigInteger(1, Arrays.copyOfRange(signFromCard, 0, 32));
|
||||
BigInteger s = new BigInteger(1, Arrays.copyOfRange(signFromCard, 32, 64));
|
||||
s = CryptoUtil.toCanonicalised(s);
|
||||
|
|
@ -455,6 +461,150 @@ public class EthEngine extends CoinEngine {
|
|||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestBalanceAndUnspentTransactions(BlockchainRequestsNotifications blockchainRequestsNotifications) throws Exception {
|
||||
final ServerApiInfura serverApiInfura = new ServerApiInfura();
|
||||
// request infura listener
|
||||
ServerApiInfura.InfuraBodyListener infuraBodyListener = new ServerApiInfura.InfuraBodyListener() {
|
||||
@Override
|
||||
public void onSuccess(String method, InfuraResponse infuraResponse) {
|
||||
switch (method) {
|
||||
case ServerApiInfura.INFURA_ETH_GET_BALANCE: {
|
||||
String balanceCap = infuraResponse.getResult();
|
||||
balanceCap = balanceCap.substring(2);
|
||||
BigInteger l = new BigInteger(balanceCap, 16);
|
||||
BigInteger d = l.divide(new BigInteger("1000000000000000000", 10));
|
||||
Long balance = d.longValue();
|
||||
|
||||
// (ctx.coinData!! as EthData).setBalanceConfirmed(balance)
|
||||
// (ctx.coinData!! as EthData).balanceUnconfirmed = 0L
|
||||
if (ctx.getBlockchain() != Blockchain.Token) {
|
||||
coinData.setBalanceReceived(true);
|
||||
coinData.setBalanceInInternalUnits(new CoinEngine.InternalAmount(l, "wei"));
|
||||
} else {
|
||||
coinData.setBalanceReceived(true);
|
||||
//(ctx.coinData!! as TokenData).balanceInInternalUnits = CoinEngine.InternalAmount(l.toBigDecimal(),ctx.card.tokenSymbol)
|
||||
((TokenData) coinData).setBalanceAlterInInternalUnits(new CoinEngine.InternalAmount(l, "wei"));
|
||||
}
|
||||
|
||||
// Log.i("$TAG eth_get_balance", balanceCap)
|
||||
}
|
||||
break;
|
||||
|
||||
case ServerApiInfura.INFURA_ETH_GET_TRANSACTION_COUNT: {
|
||||
String nonce = infuraResponse.getResult();
|
||||
nonce = nonce.substring(2);
|
||||
BigInteger count = new BigInteger(nonce, 16);
|
||||
coinData.setConfirmedTXCount(count);
|
||||
|
||||
|
||||
// Log.i("$TAG eth_getTransCount", nonce)
|
||||
}
|
||||
break;
|
||||
|
||||
case ServerApiInfura.INFURA_ETH_GET_PENDING_COUNT: {
|
||||
String pending = infuraResponse.getResult();
|
||||
pending = pending.substring(2);
|
||||
BigInteger count = new BigInteger(pending, 16);
|
||||
coinData.setUnconfirmedTXCount(count);
|
||||
|
||||
// Log.i("$TAG eth_getPendingTxCount", pending)
|
||||
}
|
||||
//
|
||||
case ServerApiInfura.INFURA_ETH_CALL: {
|
||||
try {
|
||||
String balanceCap = infuraResponse.getResult();
|
||||
balanceCap = balanceCap.substring(2);
|
||||
BigInteger l = new BigInteger(balanceCap, 16);
|
||||
Long balance = l.longValue();
|
||||
// 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
|
||||
// }
|
||||
coinData.setBalanceInInternalUnits(new CoinEngine.InternalAmount(l, ctx.getCard().tokenSymbol));
|
||||
|
||||
// Log.i("$TAG eth_call", balanceCap)
|
||||
|
||||
if (!blockchainRequestsNotifications.needTerminate()) {
|
||||
serverApiInfura.infura(ServerApiInfura.INFURA_ETH_GET_BALANCE, 67, coinData.getWallet(), "", "");
|
||||
serverApiInfura.infura(ServerApiInfura.INFURA_ETH_GET_TRANSACTION_COUNT, 67, coinData.getWallet(), "", "");
|
||||
serverApiInfura.infura(ServerApiInfura.INFURA_ETH_GET_PENDING_COUNT, 67, coinData.getWallet(), "", "");
|
||||
} else {
|
||||
serverApiInfura.setErrorOccured("Terminated by user");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
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()
|
||||
if (!serverApiInfura.hasRequests()) {
|
||||
blockchainRequestsNotifications.onComplete(serverApiInfura.isErrorOccured());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String method, String message) {
|
||||
if (!serverApiInfura.hasRequests()) {
|
||||
blockchainRequestsNotifications.onComplete(serverApiInfura.isErrorOccured());
|
||||
}
|
||||
}
|
||||
};
|
||||
serverApiInfura.setInfuraResponse(infuraBodyListener);
|
||||
|
||||
if (ctx.getBlockchain() == Blockchain.Ethereum || ctx.getBlockchain() == Blockchain.EthereumTestNet) {
|
||||
serverApiInfura.infura(ServerApiInfura.INFURA_ETH_GET_BALANCE, 67, coinData.getWallet(), "", "");
|
||||
serverApiInfura.infura(ServerApiInfura.INFURA_ETH_GET_TRANSACTION_COUNT, 67, coinData.getWallet(), "", "");
|
||||
serverApiInfura.infura(ServerApiInfura.INFURA_ETH_GET_PENDING_COUNT, 67, coinData.getWallet(), "", "");
|
||||
}
|
||||
|
||||
// Token
|
||||
else if (ctx.getBlockchain() == Blockchain.Token) {
|
||||
final CoinEngine engine = CoinEngineFactory.INSTANCE.create(ctx);
|
||||
serverApiInfura.infura(ServerApiInfura.INFURA_ETH_CALL, 67, coinData.getWallet(), ((TokenEngine) engine).getContractAddress(ctx.getCard()), "");
|
||||
}
|
||||
|
||||
|
||||
// @Override
|
||||
// public byte[] sign(Amount feeValue, Amount amountValue, boolean IncFee, String targetAddress, CardProtocol protocol) throws Exception {
|
||||
//
|
||||
|
|
@ -518,4 +668,4 @@ public class EthEngine extends CoinEngine {
|
|||
// byte[] realTX = tx.getEncoded();
|
||||
// return realTX;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -430,6 +430,11 @@ public class TokenEngine extends CoinEngine {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestBalanceAndUnspentTransactions(BlockchainRequestsNotifications blockchainRequestsNotifications) throws Exception {
|
||||
//TODO("NOT IMPLEMENTED")
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public byte[] sign(Amount feeValue, Amount amountValue, boolean IncFee, String targetAddress, CardProtocol protocol) throws Exception {
|
||||
// if (amountValue.getCurrency().equals("ETH")) {
|
||||
|
|
|
|||
|
|
@ -63,7 +63,6 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
private lateinit var nfcManager: NfcManager
|
||||
|
||||
private var serverApiCommon: ServerApiCommon = ServerApiCommon()
|
||||
private var serverApiInfura: ServerApiInfura = ServerApiInfura()
|
||||
private var serverApiTangem: ServerApiTangem = ServerApiTangem()
|
||||
|
||||
private var singleToast: Toast? = null
|
||||
|
|
@ -284,123 +283,123 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
// }
|
||||
// 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()
|
||||
// // 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()
|
||||
//
|
||||
// //TODO check
|
||||
// //ctx.blockchain=lBlockchain.Ethereum
|
||||
//// (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")
|
||||
// }
|
||||
//
|
||||
// requestCounter--
|
||||
// if (requestCounter == 0) srl!!.isRefreshing = false
|
||||
//// Log.i("$TAG eth_get_balance", balanceCap)
|
||||
// }
|
||||
//
|
||||
// requestInfura(ServerApiCommon.INFURA_ETH_GET_BALANCE, "")
|
||||
// requestInfura(ServerApiCommon.INFURA_ETH_GET_TRANSACTION_COUNT, "")
|
||||
// requestInfura(ServerApiCommon.INFURA_ETH_GET_PENDING_COUNT, "")
|
||||
// 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
|
||||
// }
|
||||
(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)
|
||||
//
|
||||
// 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 {
|
||||
|
|
@ -803,21 +802,23 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
requestVerifyAndGetInfo()
|
||||
|
||||
val coinEngine = CoinEngineFactory.create(ctx)
|
||||
requestCounter++
|
||||
coinEngine!!.requestBalanceAndUnspentTransactions (
|
||||
object : CoinEngine.BlockchainRequestsNotifications {
|
||||
override fun onComplete(success: Boolean?) {
|
||||
counterMinus()
|
||||
updateViews()
|
||||
}
|
||||
if (ctx.blockchain == Blockchain.Bitcoin || ctx.blockchain == Blockchain.BitcoinTestNet || ctx.blockchain == Blockchain.BitcoinCash) {
|
||||
val coinEngine = CoinEngineFactory.create(ctx)
|
||||
requestCounter++
|
||||
coinEngine!!.requestBalanceAndUnspentTransactions(
|
||||
object : CoinEngine.BlockchainRequestsNotifications {
|
||||
override fun onComplete(success: Boolean?) {
|
||||
counterMinus()
|
||||
updateViews()
|
||||
}
|
||||
|
||||
override fun needTerminate(): Boolean {
|
||||
return !UtilHelper.isOnline(context as Activity)
|
||||
}
|
||||
}
|
||||
)
|
||||
override fun needTerminate(): Boolean {
|
||||
return !UtilHelper.isOnline(context as Activity)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
// Bitcoin
|
||||
if (ctx.blockchain == Blockchain.Bitcoin || ctx.blockchain == Blockchain.BitcoinTestNet) {
|
||||
|
|
@ -831,25 +832,25 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
// 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)))
|
||||
// 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, "")
|
||||
// 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))
|
||||
// requestInfura(ServerApiInfura.INFURA_ETH_CALL, (engine as TokenEngine).getContractAddress(ctx.card))
|
||||
requestRateInfo("ethereum")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue