Updated on 2026-08-14
This commit is contained in:
parent
bd8d84a85a
commit
6259944ff1
7 changed files with 161 additions and 85 deletions
|
|
@ -22,9 +22,9 @@ public enum Blockchain {
|
|||
Binance("BINANCE", "BNB", 100000000.0, R.drawable.tangem2, "Binance"),
|
||||
BinanceTestNet("BINANCE/test", "BNB", 100000000.0, R.drawable.tangem2, "Binance Testnet"),
|
||||
Matic("MATIC", "MTX", 1.0, R.drawable.tangem2, "Matic"),
|
||||
MaticTestNet("MATIC/test", "MTX", 1.0, R.drawable.tangem2, "Matic Testnet");
|
||||
Stellar("XLM", "XLM", R.drawable.ic_logo_stellar, "Stellar"),
|
||||
StellarTestNet("XLM/test", "XLM", R.drawable.ic_logo_stellar, "Stellar Testnet");
|
||||
MaticTestNet("MATIC/test", "MTX", 1.0, R.drawable.tangem2, "Matic Testnet"),
|
||||
Stellar("XLM", "XLM", 1000000.0, R.drawable.ic_logo_stellar, "Stellar"),
|
||||
StellarTestNet("XLM/test", "XLM", 1000000.0, R.drawable.ic_logo_stellar, "Stellar Testnet");
|
||||
|
||||
Blockchain(String ID, String currency, double multiplier, int imageResource, String officialName) {
|
||||
mID = ID;
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ package com.tangem.data.network;
|
|||
|
||||
import com.tangem.App;
|
||||
import com.tangem.data.Blockchain;
|
||||
import com.tangem.domain.wallet.TangemContext;
|
||||
import com.tangem.util.LOG;
|
||||
import com.tangem.wallet.R;
|
||||
import com.tangem.wallet.TangemContext;
|
||||
|
||||
import org.stellar.sdk.Network;
|
||||
import org.stellar.sdk.Server;
|
||||
|
|
@ -19,7 +19,7 @@ import io.reactivex.schedulers.Schedulers;
|
|||
|
||||
/**
|
||||
* Created by dvol on 7.01.2019.
|
||||
*
|
||||
* <p>
|
||||
* Request processor for Stellar Horizon Rest Api
|
||||
* Every request live cycle:
|
||||
* 1. In application create request and call {@link ServerApiStellar}.requestData(..)
|
||||
|
|
@ -141,10 +141,16 @@ public class ServerApiStellar {
|
|||
private void doStellarRequest(TangemContext ctx, StellarRequest.Base stellarRequest) throws IOException {
|
||||
stellarRequest.setError(null);
|
||||
try {
|
||||
if (ctx.getBlockchain() == Blockchain.StellarTestNet) {
|
||||
Server server;
|
||||
if (ctx.getBlockchain() == Blockchain.Stellar) {
|
||||
Network.usePublicNetwork();
|
||||
server = new Server(ServerURL.API_STELLAR);
|
||||
} else if (ctx.getBlockchain() == Blockchain.StellarTestNet) {
|
||||
Network.useTestNetwork();
|
||||
server = new Server(ServerURL.API_STELLAR_TESTNET);
|
||||
} else {
|
||||
throw new IOException("Wrong blockchain for ServerApiStellar");
|
||||
}
|
||||
Server server = new Server(ServerURL.API_STELLAR);
|
||||
try {
|
||||
LOG.e(TAG, "--- request " + stellarRequest.getClass().getSimpleName());
|
||||
stellarRequest.process(server);
|
||||
|
|
@ -155,7 +161,7 @@ public class ServerApiStellar {
|
|||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
stellarRequest.setError(App.getInstance().getString(R.string.cannot_obtain_data_from_blockchain_communication_error));
|
||||
stellarRequest.setError(App.Companion.getInstance().getString(R.string.cannot_obtain_data_from_blockchain_communication_error));
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,5 +11,6 @@ class ServerURL {
|
|||
static final String API_BINANCE = "https://dex.binance.org/";
|
||||
static final String API_BINANCE_TESTNET = "https://testnet-dex.binance.org/";
|
||||
static final String API_MATIC_TESTNET = "https://testnet2.matic.network";
|
||||
static final String API_STELLAR = "https://horizon-testnet.stellar.org";
|
||||
static final String API_STELLAR = "https://horizon.stellar.org/";
|
||||
static final String API_STELLAR_TESTNET = "https://horizon-testnet.stellar.org";
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ import org.stellar.sdk.Server;
|
|||
import org.stellar.sdk.Transaction;
|
||||
import org.stellar.sdk.requests.ErrorResponse;
|
||||
import org.stellar.sdk.responses.AccountResponse;
|
||||
import org.stellar.sdk.responses.LedgerResponse;
|
||||
import org.stellar.sdk.responses.SubmitTransactionResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -68,5 +69,16 @@ public class StellarRequest {
|
|||
}
|
||||
}
|
||||
|
||||
public static class Ledgers extends Base {
|
||||
public LedgerResponse ledgerResponse;
|
||||
|
||||
public Ledgers() {};
|
||||
|
||||
@Override
|
||||
public void process(Server server) throws IOException {
|
||||
int latestLedger = server.root().getCoreLatestLedger();
|
||||
ledgerResponse = server.ledgers().ledger(latestLedger);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@ import com.tangem.wallet.matic.MaticTokenEngine
|
|||
import com.tangem.wallet.nftToken.NftTokenEngine
|
||||
import com.tangem.wallet.rsk.RskEngine
|
||||
import com.tangem.wallet.rsk.RskTokenEngine
|
||||
import com.tangem.wallet.xlm.XlmEngine
|
||||
import com.tangem.wallet.xrp.XrpEngine
|
||||
|
||||
/**
|
||||
|
|
@ -43,6 +44,7 @@ object CoinEngineFactory {
|
|||
Blockchain.Ripple -> XrpEngine()
|
||||
Blockchain.Binance, Blockchain.BinanceTestNet -> BinanceEngine()
|
||||
Blockchain.Matic, Blockchain.MaticTestNet -> MaticTokenEngine()
|
||||
Blockchain.StellarTestNet, Blockchain.Stellar -> XlmEngine()
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
|
@ -73,9 +75,9 @@ object CoinEngineFactory {
|
|||
else if (Blockchain.Binance == context.blockchain || Blockchain.BinanceTestNet == context.blockchain)
|
||||
BinanceEngine(context)
|
||||
else if (Blockchain.Matic == context.blockchain || Blockchain.MaticTestNet == context.blockchain)
|
||||
MaticTokenEngine(context
|
||||
|
||||
)
|
||||
MaticTokenEngine(context)
|
||||
else if (Blockchain.Stellar == context.blockchain || Blockchain.StellarTestNet == context.blockchain)
|
||||
XlmEngine(context)
|
||||
else
|
||||
return null
|
||||
} catch (e: Exception) {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,17 @@
|
|||
package com.tangem.domain.wallet.xlm;
|
||||
package com.tangem.wallet.xlm;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.tangem.domain.wallet.CoinData;
|
||||
import com.tangem.domain.wallet.CoinEngine;
|
||||
import com.tangem.wallet.CoinData;
|
||||
import com.tangem.wallet.CoinEngine;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.stellar.sdk.KeyPair;
|
||||
import org.stellar.sdk.responses.AccountResponse;
|
||||
import org.stellar.sdk.responses.LedgerResponse;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/*
|
||||
* Created by dvol on 7.01.2019.
|
||||
|
|
@ -16,8 +20,7 @@ import org.stellar.sdk.responses.AccountResponse;
|
|||
public class XlmData extends CoinData {
|
||||
|
||||
|
||||
public static class AccountResponseEx extends AccountResponse
|
||||
{
|
||||
public static class AccountResponseEx extends AccountResponse {
|
||||
AccountResponseEx(String accountId, Long sequenceNumber) {
|
||||
super(KeyPair.fromAccountId(accountId), sequenceNumber);
|
||||
}
|
||||
|
|
@ -26,7 +29,8 @@ public class XlmData extends CoinData {
|
|||
private CoinEngine.Amount balance = null;
|
||||
|
||||
private Long sequenceNumber = 0L;
|
||||
|
||||
private CoinEngine.Amount baseReserve = new CoinEngine.Amount("0.5", "XLM");
|
||||
private CoinEngine.Amount baseFee = new CoinEngine.Amount("0.00001", "XLM");
|
||||
|
||||
@Override
|
||||
public void clearInfo() {
|
||||
|
|
@ -34,9 +38,20 @@ public class XlmData extends CoinData {
|
|||
balance = null;
|
||||
}
|
||||
|
||||
CoinEngine.Amount getBalanceXLM() {
|
||||
return balance;
|
||||
CoinEngine.Amount getBalance() {
|
||||
if (balance != null) {
|
||||
return new CoinEngine.Amount(balance.subtract(getReserve()), "XLM");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
CoinEngine.Amount getReserve() {
|
||||
return new CoinEngine.Amount(baseReserve.multiply(BigDecimal.valueOf(2)), "XLM");
|
||||
}
|
||||
|
||||
CoinEngine.Amount getBaseFee() {
|
||||
return baseFee;
|
||||
}
|
||||
|
||||
AccountResponse getAccountResponse() {
|
||||
|
|
@ -44,7 +59,7 @@ public class XlmData extends CoinData {
|
|||
}
|
||||
|
||||
void setAccountResponse(AccountResponse accountResponse) {
|
||||
if( accountResponse.getBalances().length>0 ) {
|
||||
if (accountResponse.getBalances().length > 0) {
|
||||
AccountResponse.Balance balanceResponse = accountResponse.getBalances()[0];
|
||||
balance = new CoinEngine.Amount(balanceResponse.getBalance(), "XLM");
|
||||
}
|
||||
|
|
@ -52,6 +67,12 @@ public class XlmData extends CoinData {
|
|||
setBalanceReceived(true);
|
||||
}
|
||||
|
||||
void setLedgerResponse(LedgerResponse ledgerResponse) {
|
||||
XlmEngine xlmEngine = new XlmEngine();
|
||||
baseReserve = xlmEngine.convertToAmount(new CoinEngine.InternalAmount(ledgerResponse.getBaseReserveInStroops(), "stroops"));
|
||||
baseFee = xlmEngine.convertToAmount(new CoinEngine.InternalAmount(ledgerResponse.getBaseFeeInStroops(), "stroops"));
|
||||
}
|
||||
|
||||
public void incSequenceNumber() {
|
||||
sequenceNumber++;
|
||||
}
|
||||
|
|
@ -61,8 +82,7 @@ public class XlmData extends CoinData {
|
|||
super.loadFromBundle(B);
|
||||
|
||||
if (B.containsKey("BalanceCurrency") && B.containsKey("BalanceDecimal")) {
|
||||
String currency = B.getString("BalanceCurrency");
|
||||
balance = new CoinEngine.Amount(B.getString("BalanceDecimal"), currency);
|
||||
balance = new CoinEngine.Amount(B.getString("BalanceDecimal"), B.getString("BalanceCurrency"));
|
||||
} else {
|
||||
balance = null;
|
||||
}
|
||||
|
|
@ -72,6 +92,18 @@ public class XlmData extends CoinData {
|
|||
} else {
|
||||
sequenceNumber = 0L;
|
||||
}
|
||||
|
||||
if (B.containsKey("BaseReserveCurrency") && B.containsKey("BaseReserveDecimal")) {
|
||||
baseReserve = new CoinEngine.Amount(B.getString("BaseReserveDecimal"), B.getString("BaseReserveCurrency"));
|
||||
} else {
|
||||
baseReserve = new CoinEngine.Amount("0.5", "XLM");
|
||||
}
|
||||
|
||||
if (B.containsKey("BaseFeeCurrency") && B.containsKey("BaseFeeDecimal")) {
|
||||
baseFee = new CoinEngine.Amount(B.getString("BaseFeeDecimal"), B.getString("BaseFeeCurrency"));
|
||||
} else {
|
||||
baseFee = new CoinEngine.Amount("0.00001", "XLM");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -87,10 +119,19 @@ public class XlmData extends CoinData {
|
|||
B.putLong("sequenceNumber", sequenceNumber);
|
||||
}
|
||||
|
||||
if (baseReserve != null) {
|
||||
B.putString("BaseReserveCurrency", baseReserve.getCurrency());
|
||||
B.putString("BaseReserveDecimal", baseReserve.toValueString());
|
||||
}
|
||||
|
||||
if (baseFee != null) {
|
||||
B.putString("BaseFeeCurrency", baseFee.getCurrency());
|
||||
B.putString("BaseFeeDecimal", baseFee.toValueString());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e("Can't save to bundle ", e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
package com.tangem.domain.wallet.xlm;
|
||||
package com.tangem.wallet.xlm;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.text.InputFilter;
|
||||
import android.util.Log;
|
||||
|
||||
import com.tangem.card_common.data.TangemCard;
|
||||
import com.tangem.card_common.tasks.SignTask;
|
||||
import com.tangem.card_common.util.Util;
|
||||
import com.tangem.data.Blockchain;
|
||||
import com.tangem.data.network.ServerApiStellar;
|
||||
import com.tangem.data.network.StellarRequest;
|
||||
import com.tangem.domain.wallet.BalanceValidator;
|
||||
import com.tangem.domain.wallet.CoinData;
|
||||
import com.tangem.domain.wallet.CoinEngine;
|
||||
import com.tangem.domain.wallet.TangemContext;
|
||||
import com.tangem.tangemcard.data.TangemCard;
|
||||
import com.tangem.tangemcard.tasks.SignTask;
|
||||
import com.tangem.tangemcard.util.Util;
|
||||
import com.tangem.util.DecimalDigitsInputFilter;
|
||||
import com.tangem.wallet.BalanceValidator;
|
||||
import com.tangem.wallet.CoinData;
|
||||
import com.tangem.wallet.CoinEngine;
|
||||
import com.tangem.wallet.R;
|
||||
import com.tangem.wallet.TangemContext;
|
||||
|
||||
import org.stellar.sdk.AssetTypeNative;
|
||||
import org.stellar.sdk.KeyPair;
|
||||
|
|
@ -27,10 +27,10 @@ import java.io.IOException;
|
|||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Created by dvol on 7.01.2019.
|
||||
*
|
||||
* PS. To create and fill testnet account just open https://friendbot.stellar.org/?addr=XXX in browser
|
||||
**/
|
||||
* Created by dvol on 7.01.2019.
|
||||
* <p>
|
||||
* PS. To create and fill testnet account just open https://friendbot.stellar.org/?addr=XXX in browser
|
||||
**/
|
||||
|
||||
public class XlmEngine extends CoinEngine {
|
||||
|
||||
|
|
@ -55,8 +55,7 @@ public class XlmEngine extends CoinEngine {
|
|||
}
|
||||
|
||||
private static int getDecimals() {
|
||||
//TODO - Is it's right?
|
||||
return 8;
|
||||
return 7;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -75,7 +74,7 @@ public class XlmEngine extends CoinEngine {
|
|||
public String getBalanceHTML() {
|
||||
Amount balance = getBalance();
|
||||
if (balance != null) {
|
||||
return balance.toDescriptionString(getDecimals());
|
||||
return " " + balance.toDescriptionString(getDecimals()) + "<br><small><small>+ " + coinData.getReserve().toDescriptionString(getDecimals()) + " reserve</small></small>";
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
|
@ -96,14 +95,14 @@ public class XlmEngine extends CoinEngine {
|
|||
@Override
|
||||
public boolean isBalanceNotZero() {
|
||||
if (coinData == null) return false;
|
||||
if (coinData.getBalanceXLM() == null) return false;
|
||||
return coinData.getBalanceXLM().notZero();
|
||||
if (coinData.getBalance() == null) return false;
|
||||
return coinData.getBalance().notZero();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBalanceInfo() {
|
||||
if (coinData == null) return false;
|
||||
return coinData.getBalanceXLM() != null;
|
||||
return coinData.getBalance() != null;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -147,17 +146,17 @@ public class XlmEngine extends CoinEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Uri getShareWalletUriExplorer() {
|
||||
return Uri.parse((ctx.getBlockchain() == Blockchain.Bitcoin ? "http://testnet.stellarchain.io/address/" : "http://testnet.stellarchain.io/address/") + ctx.getCoinData().getWallet());
|
||||
public Uri getWalletExplorerUri() {
|
||||
return Uri.parse((ctx.getBlockchain() == Blockchain.Stellar ? "http://stellarchain.io/address/" : "http://testnet.stellarchain.io/address/") + ctx.getCoinData().getWallet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uri getShareWalletUri() {
|
||||
//TODO - how to construct payment query intent for stellar?
|
||||
if (ctx.getCard().getDenomination() != null) {
|
||||
return Uri.parse("stellar:" + ctx.getCoinData().getWallet() + "?amount=" + convertToAmount(convertToInternalAmount(ctx.getCard().getDenomination())).toValueString());
|
||||
return Uri.parse(ctx.getCoinData().getWallet() + "?amount=" + convertToAmount(convertToInternalAmount(ctx.getCard().getDenomination())).toValueString());
|
||||
} else {
|
||||
return Uri.parse("stellar:" + ctx.getCoinData().getWallet());
|
||||
return Uri.parse(ctx.getCoinData().getWallet());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -169,7 +168,7 @@ public class XlmEngine extends CoinEngine {
|
|||
@Override
|
||||
public boolean checkNewTransactionAmount(Amount amount) {
|
||||
if (coinData == null) return false;
|
||||
if (amount.compareTo(coinData.getBalanceXLM()) > 0) {
|
||||
if (amount.compareTo(coinData.getBalance()) > 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
@ -190,10 +189,10 @@ public class XlmEngine extends CoinEngine {
|
|||
if (feeValue.isZero() || amountValue.isZero())
|
||||
return false;
|
||||
|
||||
if (isIncludeFee && (amountValue.compareTo(coinData.getBalanceXLM()) > 0 || amountValue.compareTo(feeValue) < 0))
|
||||
if (isIncludeFee && (amountValue.compareTo(coinData.getBalance()) > 0 || amountValue.compareTo(feeValue) < 0))
|
||||
return false;
|
||||
|
||||
if (!isIncludeFee && amountValue.add(feeValue).compareTo(coinData.getBalanceXLM()) > 0)
|
||||
if (!isIncludeFee && amountValue.add(feeValue).compareTo(coinData.getBalance()) > 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -228,7 +227,7 @@ public class XlmEngine extends CoinEngine {
|
|||
balanceValidator.setScore(100);
|
||||
balanceValidator.setFirstLine("Verified balance");
|
||||
balanceValidator.setSecondLine("Balance confirmed in blockchain");
|
||||
if (coinData.getBalanceXLM().isZero()) {
|
||||
if (coinData.getBalance().isZero()) {
|
||||
balanceValidator.setFirstLine("Empty wallet");
|
||||
balanceValidator.setSecondLine("");
|
||||
}
|
||||
|
|
@ -243,7 +242,7 @@ public class XlmEngine extends CoinEngine {
|
|||
// return;
|
||||
// }
|
||||
|
||||
if ((ctx.getCard().getOfflineBalance() != null) && !coinData.isBalanceReceived() && (ctx.getCard().getRemainingSignatures() == ctx.getCard().getMaxSignatures()) && coinData.getBalanceXLM().notZero()) {
|
||||
if ((ctx.getCard().getOfflineBalance() != null) && !coinData.isBalanceReceived() && (ctx.getCard().getRemainingSignatures() == ctx.getCard().getMaxSignatures()) && coinData.getBalance().notZero()) {
|
||||
balanceValidator.setScore(80);
|
||||
balanceValidator.setFirstLine("Verified offline balance");
|
||||
balanceValidator.setSecondLine("Can't obtain balance from blockchain. Restore internet connection to be more confident. ");
|
||||
|
|
@ -274,7 +273,7 @@ public class XlmEngine extends CoinEngine {
|
|||
@Override
|
||||
public Amount getBalance() {
|
||||
if (!hasBalanceInfo()) return null;
|
||||
return coinData.getBalanceXLM();
|
||||
return coinData.getBalance();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -349,22 +348,20 @@ public class XlmEngine extends CoinEngine {
|
|||
|
||||
|
||||
@Override
|
||||
public SignTask.PaymentToSign constructPayment(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) throws Exception {
|
||||
public SignTask.TransactionToSign constructTransaction(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) throws Exception {
|
||||
checkBlockchainDataExists();
|
||||
|
||||
if( IncFee )
|
||||
{
|
||||
amountValue=new Amount(amountValue.subtract(feeValue), amountValue.getCurrency());
|
||||
if (IncFee) {
|
||||
amountValue = new Amount(amountValue.subtract(feeValue), amountValue.getCurrency());
|
||||
}
|
||||
|
||||
TransactionEx transaction = TransactionEx.buildEx(60, coinData.getAccountResponse(), new PaymentOperation.Builder(KeyPair.fromAccountId(targetAddress), new AssetTypeNative(), amountValue.toValueString()).build());
|
||||
TransactionEx transaction = TransactionEx.buildEx(60, coinData.getAccountResponse(), new PaymentOperation.Builder(KeyPair.fromAccountId(targetAddress), new AssetTypeNative(), amountValue.toValueString()).build());
|
||||
|
||||
if( transaction.getFee()!=convertToInternalAmount(feeValue).intValueExact() )
|
||||
{
|
||||
if (transaction.getFee() != convertToInternalAmount(feeValue).intValueExact()) {
|
||||
throw new Exception("Invalid fee!");
|
||||
}
|
||||
|
||||
return new SignTask.PaymentToSign() {
|
||||
return new SignTask.TransactionToSign() {
|
||||
|
||||
@Override
|
||||
public boolean isSigningMethodSupported(TangemCard.SigningMethod signingMethod) {
|
||||
|
|
@ -399,7 +396,7 @@ public class XlmEngine extends CoinEngine {
|
|||
transaction.setSign(signFromCard);
|
||||
|
||||
byte[] txForSend = transaction.toEnvelopeXdrBase64().getBytes();
|
||||
notifyOnNeedSendPayment(txForSend);
|
||||
notifyOnNeedSendTransaction(txForSend);
|
||||
return txForSend;
|
||||
}
|
||||
};
|
||||
|
|
@ -413,18 +410,30 @@ public class XlmEngine extends CoinEngine {
|
|||
@Override
|
||||
public void onSuccess(StellarRequest.Base request) {
|
||||
Log.i(TAG, "onSuccess: " + request.getClass().getSimpleName());
|
||||
if (!StellarRequest.Balance.class.isInstance(request)) {
|
||||
|
||||
if (request instanceof StellarRequest.Balance) {
|
||||
StellarRequest.Balance balanceRequest = (StellarRequest.Balance) request;
|
||||
|
||||
coinData.setAccountResponse(balanceRequest.accountResponse);
|
||||
|
||||
if (serverApi.isRequestsSequenceCompleted()) {
|
||||
blockchainRequestsCallbacks.onComplete(!ctx.hasError());
|
||||
} else {
|
||||
blockchainRequestsCallbacks.onProgress();
|
||||
}
|
||||
} else if (request instanceof StellarRequest.Ledgers) {
|
||||
StellarRequest.Ledgers ledgersRequest = (StellarRequest.Ledgers) request;
|
||||
|
||||
coinData.setLedgerResponse(ledgersRequest.ledgerResponse);
|
||||
|
||||
if (serverApi.isRequestsSequenceCompleted()) {
|
||||
blockchainRequestsCallbacks.onComplete(!ctx.hasError());
|
||||
} else {
|
||||
blockchainRequestsCallbacks.onProgress();
|
||||
}
|
||||
} else {
|
||||
ctx.setError("Invalid request logic");
|
||||
blockchainRequestsCallbacks.onComplete(false);
|
||||
return;
|
||||
}
|
||||
StellarRequest.Balance balanceRequest = (StellarRequest.Balance) request;
|
||||
|
||||
coinData.setAccountResponse(balanceRequest.accountResponse);
|
||||
if (serverApi.isRequestsSequenceCompleted()) {
|
||||
blockchainRequestsCallbacks.onComplete(!ctx.hasError());
|
||||
} else {
|
||||
blockchainRequestsCallbacks.onProgress();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -444,19 +453,13 @@ public class XlmEngine extends CoinEngine {
|
|||
serverApi.setListener(listener);
|
||||
|
||||
serverApi.requestData(ctx, new StellarRequest.Balance(coinData.getWallet()));
|
||||
serverApi.requestData(ctx, new StellarRequest.Ledgers());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestFee(BlockchainRequestsCallbacks blockchainRequestsCallbacks, String targetAddress, Amount amount) throws Exception {
|
||||
final int calcSize = 0;
|
||||
// todo - take BASE_FEE from last leger
|
||||
Log.e(TAG, String.format("Estimated tx size %d", calcSize));
|
||||
coinData.minFee = null;
|
||||
coinData.maxFee = null;
|
||||
coinData.normalFee = null;
|
||||
coinData.minFee = new Amount("0.00001", getFeeCurrency());
|
||||
coinData.normalFee = new Amount("0.00001", getFeeCurrency());
|
||||
coinData.maxFee = new Amount("0.00001", getFeeCurrency());
|
||||
// TODO: get fee stats?
|
||||
coinData.minFee = coinData.normalFee = coinData.maxFee = coinData.getBaseFee();
|
||||
blockchainRequestsCallbacks.onComplete(true);
|
||||
}
|
||||
|
||||
|
|
@ -468,19 +471,20 @@ public class XlmEngine extends CoinEngine {
|
|||
@Override
|
||||
public void onSuccess(StellarRequest.Base request) {
|
||||
try {
|
||||
if (!StellarRequest.SubmitTransaction.class.isInstance(request)) throw new Exception("Invalid request logic");
|
||||
if (!StellarRequest.SubmitTransaction.class.isInstance(request))
|
||||
throw new Exception("Invalid request logic");
|
||||
StellarRequest.SubmitTransaction submitTransactionRequest = (StellarRequest.SubmitTransaction) request;
|
||||
if (submitTransactionRequest.response.isSuccess()) {
|
||||
ctx.setError(null);
|
||||
blockchainRequestsCallbacks.onComplete(true);
|
||||
} else {
|
||||
if( submitTransactionRequest.response.getExtras()!=null && submitTransactionRequest.response.getExtras().getResultCodes()!=null ) {
|
||||
if (submitTransactionRequest.response.getExtras() != null && submitTransactionRequest.response.getExtras().getResultCodes() != null) {
|
||||
String trResult = submitTransactionRequest.response.getExtras().getResultCodes().getTransactionResultCode();
|
||||
if( submitTransactionRequest.response.getExtras().getResultCodes().getOperationsResultCodes()!=null && submitTransactionRequest.response.getExtras().getResultCodes().getOperationsResultCodes().size()>0 ) {
|
||||
trResult+="/"+submitTransactionRequest.response.getExtras().getResultCodes().getOperationsResultCodes().get(0);
|
||||
if (submitTransactionRequest.response.getExtras().getResultCodes().getOperationsResultCodes() != null && submitTransactionRequest.response.getExtras().getResultCodes().getOperationsResultCodes().size() > 0) {
|
||||
trResult += "/" + submitTransactionRequest.response.getExtras().getResultCodes().getOperationsResultCodes().get(0);
|
||||
}
|
||||
ctx.setError(trResult);
|
||||
}else{
|
||||
} else {
|
||||
ctx.setError("transaction failed");
|
||||
}
|
||||
blockchainRequestsCallbacks.onComplete(false);
|
||||
|
|
@ -511,4 +515,14 @@ public class XlmEngine extends CoinEngine {
|
|||
|
||||
}
|
||||
|
||||
public boolean needMultipleLinesForBalance() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean allowSelectFeeLevel() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int pendingTransactionTimeoutInSeconds() { return 10; }
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue