Updated on 2026-08-14
This commit is contained in:
parent
6e4d1f0079
commit
ef0a5f379d
6 changed files with 338 additions and 108 deletions
|
|
@ -143,8 +143,8 @@ public class ElectrumRequest {
|
|||
return "";
|
||||
}
|
||||
|
||||
public boolean isMethod(String methodName) throws JSONException {
|
||||
return jsRequestData.getString("method").equals(methodName);
|
||||
public boolean isMethod(String methodName) {
|
||||
return getMethod().equals(methodName);
|
||||
}
|
||||
|
||||
public JSONArray getParams() throws JSONException {
|
||||
|
|
|
|||
|
|
@ -52,6 +52,21 @@ public class ServerApiElectrum {
|
|||
private String host;
|
||||
private int port;
|
||||
|
||||
private int requestsCount=0;
|
||||
|
||||
public boolean hasRequests() {
|
||||
return requestsCount>0;
|
||||
}
|
||||
|
||||
private String error=null;
|
||||
public boolean isErrorOccured() {
|
||||
return error!=null;
|
||||
}
|
||||
|
||||
public void setErrorOccured(String error) {
|
||||
this.error=error;
|
||||
}
|
||||
|
||||
public interface ElectrumRequestDataListener {
|
||||
void onSuccess(ElectrumRequest electrumRequest);
|
||||
|
||||
|
|
@ -63,6 +78,7 @@ public class ServerApiElectrum {
|
|||
}
|
||||
|
||||
public void electrumRequestData(TangemContext ctx, ElectrumRequest electrumRequest) {
|
||||
requestsCount++;
|
||||
Observable<ElectrumRequest> checkElectrumDataObserver = Observable.just(electrumRequest)
|
||||
.doOnNext(electrumRequest1 -> doElectrumRequest(ctx, electrumRequest))
|
||||
|
||||
|
|
@ -84,6 +100,7 @@ public class ServerApiElectrum {
|
|||
@Override
|
||||
public void onNext(ElectrumRequest v) {
|
||||
if (electrumRequest.answerData != null) {
|
||||
requestsCount--;
|
||||
electrumRequestDataListener.onSuccess(electrumRequest);
|
||||
// Log.i(TAG, "electrumRequestData " + electrumRequest.getMethod() + " onNext != null");
|
||||
} else {
|
||||
|
|
@ -282,4 +299,5 @@ public class ServerApiElectrum {
|
|||
return "Electrum, " + host + ":" + String.valueOf(port);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@ package com.tangem.domain.wallet;
|
|||
import android.net.Uri;
|
||||
import android.text.InputFilter;
|
||||
|
||||
import com.tangem.data.Blockchain;
|
||||
import com.tangem.tangemcard.reader.CardProtocol;
|
||||
import com.tangem.tangemcard.tasks.SignTask;
|
||||
|
||||
|
|
@ -236,12 +235,7 @@ public abstract class CoinEngine {
|
|||
|
||||
public void defineWallet() throws CardProtocol.TangemException {
|
||||
try {
|
||||
String wallet;
|
||||
if (ctx.getBlockchain() == Blockchain.BitcoinCash) {
|
||||
wallet = calculateAddress(ctx.getCard().getWalletPublicKeyRar());
|
||||
} else {
|
||||
wallet = calculateAddress(ctx.getCard().getWalletPublicKey());
|
||||
}
|
||||
String wallet = calculateAddress(ctx.getCard().getWalletPublicKey());
|
||||
ctx.getCoinData().setWallet(wallet);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
@ -270,4 +264,12 @@ public abstract class CoinEngine {
|
|||
onNeedSendPayment.onPaymentPrepared(txForSend);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public interface BlockchainRequestsNotifications
|
||||
{
|
||||
void onComplete(Boolean success);
|
||||
boolean needTerminate();
|
||||
}
|
||||
public abstract void requestBalanceAndUnspentTransactions(BlockchainRequestsNotifications blockchainRequestsNotifications);
|
||||
}
|
||||
|
|
@ -431,6 +431,19 @@ public class BtcCashEngine extends CoinEngine {
|
|||
// return mCard.getAmountDescription(Double.parseDouble(amount));
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void defineWallet() throws CardProtocol.TangemException {
|
||||
try {
|
||||
String wallet = calculateAddress(ctx.getCard().getWalletPublicKeyRar());
|
||||
ctx.getCoinData().setWallet(wallet);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ctx.getCoinData().setWallet("ERROR");
|
||||
throw new CardProtocol.TangemException("Can't define wallet address");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SignTask.PaymentToSign constructPayment(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) throws Exception {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.tangem.domain.wallet.btc;
|
|||
|
||||
import android.net.Uri;
|
||||
import android.text.InputFilter;
|
||||
import android.util.Log;
|
||||
|
||||
import com.tangem.tangemcard.reader.CardProtocol;
|
||||
import com.tangem.domain.wallet.BalanceValidator;
|
||||
|
|
@ -20,6 +21,13 @@ import com.tangem.util.DecimalDigitsInputFilter;
|
|||
import com.tangem.util.DerEncodingUtil;
|
||||
import com.tangem.tangemcard.util.Util;
|
||||
import com.tangem.wallet.R;
|
||||
import com.tangem.data.network.ElectrumRequest;
|
||||
import com.tangem.data.network.ServerApiElectrum;
|
||||
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.math.BigDecimal;
|
||||
|
|
@ -33,6 +41,8 @@ import java.util.List;
|
|||
|
||||
public class BtcEngine extends CoinEngine {
|
||||
|
||||
private static final String TAG = BtcEngine.class.getSimpleName();
|
||||
|
||||
public BtcData coinData = null;
|
||||
|
||||
public BtcEngine(TangemContext context) throws Exception {
|
||||
|
|
@ -431,8 +441,8 @@ public class BtcEngine extends CoinEngine {
|
|||
change = change - fees;
|
||||
}
|
||||
|
||||
final long amountFinal=amount;
|
||||
final long changeFinal=change;
|
||||
final long amountFinal = amount;
|
||||
final long changeFinal = change;
|
||||
|
||||
if (amount + fees > fullAmount) {
|
||||
throw new CardProtocol.TangemException_WrongAmount(String.format("Balance (%d) < change (%d) + amount (%d)", fullAmount, change, amount));
|
||||
|
|
@ -440,7 +450,7 @@ public class BtcEngine extends CoinEngine {
|
|||
|
||||
final byte[][] txForSign = new byte[unspentOutputs.size()][];
|
||||
final byte[][] bodyDoubleHash = new byte[unspentOutputs.size()][];
|
||||
final byte[][] bodyHash= new byte[unspentOutputs.size()][];
|
||||
final byte[][] bodyHash = new byte[unspentOutputs.size()][];
|
||||
|
||||
for (int i = 0; i < unspentOutputs.size(); ++i) {
|
||||
txForSign[i] = BTCUtils.buildTXForSign(myAddress, targetAddress, myAddress, unspentOutputs, i, amount, change);
|
||||
|
|
@ -452,12 +462,12 @@ public class BtcEngine 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];
|
||||
|
|
@ -497,12 +507,187 @@ public class BtcEngine extends CoinEngine {
|
|||
unspentOutputs.get(i).scriptForBuild = DerEncodingUtil.packSignDer(r, s, pbKey);
|
||||
}
|
||||
|
||||
byte[] txForSend=BTCUtils.buildTXForSend(targetAddress, myAddress, unspentOutputs, amountFinal, changeFinal);
|
||||
byte[] txForSend = BTCUtils.buildTXForSend(targetAddress, myAddress, unspentOutputs, amountFinal, changeFinal);
|
||||
notifyOnNeedSendPayment(txForSend);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestBalanceAndUnspentTransactions(BlockchainRequestsNotifications blockchainRequestsNotifications) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 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()));
|
||||
serverApiElectrum.electrumRequestData(ctx, ElectrumRequest.listUnspent(coinData.getWallet()));
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public byte[] sign(Amount feeValue, Amount amountValue, boolean IncFee, String targetAddress, CardProtocol protocol) throws Exception {
|
||||
//
|
||||
|
|
|
|||
|
|
@ -21,9 +21,7 @@ import android.view.ViewGroup
|
|||
import android.widget.Toast
|
||||
import com.tangem.App
|
||||
import com.tangem.Constant
|
||||
import com.tangem.data.network.ElectrumRequest
|
||||
import com.tangem.data.network.ServerApiCommon
|
||||
import com.tangem.data.network.ServerApiElectrum
|
||||
import com.tangem.data.network.ServerApiInfura
|
||||
import com.tangem.tangemserver.android.model.CardVerifyAndGetInfo
|
||||
import com.tangem.data.network.model.InfuraResponse
|
||||
|
|
@ -32,7 +30,6 @@ import com.tangem.tangemcard.reader.CardProtocol
|
|||
import com.tangem.tangemcard.android.reader.NfcManager
|
||||
import com.tangem.domain.wallet.*
|
||||
import com.tangem.domain.wallet.bch.BtcCashEngine
|
||||
import com.tangem.domain.wallet.btc.BtcData
|
||||
import com.tangem.domain.wallet.eth.EthData
|
||||
import com.tangem.domain.wallet.token.TokenData
|
||||
import com.tangem.domain.wallet.token.TokenEngine
|
||||
|
|
@ -42,6 +39,7 @@ import com.tangem.presentation.dialog.PINSwapWarningDialog
|
|||
import com.tangem.presentation.dialog.ShowQRCodeDialog
|
||||
import com.tangem.presentation.dialog.WaitSecurityDelayDialog
|
||||
import com.tangem.data.Blockchain
|
||||
import com.tangem.data.network.ElectrumRequest
|
||||
import com.tangem.tangemcard.android.reader.NfcReader
|
||||
import com.tangem.tangemcard.data.EXTRA_TANGEM_CARD
|
||||
import com.tangem.tangemcard.data.EXTRA_TANGEM_CARD_UID
|
||||
|
|
@ -66,7 +64,6 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
private var serverApiCommon: ServerApiCommon = ServerApiCommon()
|
||||
private var serverApiInfura: ServerApiInfura = ServerApiInfura()
|
||||
private var serverApiElectrum: ServerApiElectrum = ServerApiElectrum()
|
||||
private var serverApiTangem: ServerApiTangem = ServerApiTangem()
|
||||
|
||||
private var singleToast: Toast? = null
|
||||
|
|
@ -190,7 +187,6 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
if (cardProtocol != null)
|
||||
// openVerifyCard(cardProtocol!!)
|
||||
(activity as LoadedWalletActivity).navigator.showVerifyCard(context as Activity, ctx)
|
||||
|
||||
else
|
||||
showSingleToast(R.string.need_attach_card_again)
|
||||
}
|
||||
|
|
@ -212,81 +208,81 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
}
|
||||
|
||||
// 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)
|
||||
// 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 {
|
||||
|
|
@ -428,8 +424,8 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
// if (ctx.blockchain == Blockchain.Token || ctx.blockchain == Blockchain.Ethereum) {
|
||||
// ctx.card!!.setBlockchainIDFromCard(Blockchain.Ethereum.id)
|
||||
|
||||
//ctx.blockchain=Blockchain.Ethereum
|
||||
//engine=engine!!.swithToOtherEngine(Blockchain.Ethereum)
|
||||
//ctx.blockchain=Blockchain.Ethereum
|
||||
//engine=engine!!.swithToOtherEngine(Blockchain.Ethereum)
|
||||
// }
|
||||
refresh()
|
||||
}
|
||||
|
|
@ -807,12 +803,28 @@ 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()
|
||||
}
|
||||
|
||||
override fun needTerminate(): Boolean {
|
||||
return !UtilHelper.isOnline(context as Activity)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
// 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))
|
||||
// requestElectrum(ElectrumRequest.checkBalance(ctx.coinData!!.wallet))
|
||||
// requestElectrum(ElectrumRequest.listUnspent(ctx.coinData!!.wallet))
|
||||
requestRateInfo("bitcoin")
|
||||
}
|
||||
|
||||
|
|
@ -842,15 +854,15 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
}
|
||||
}
|
||||
|
||||
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 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)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue