Updated on 2026-08-14
This commit is contained in:
parent
07bc724ecd
commit
75f19d41f4
278 changed files with 19571 additions and 206 deletions
|
|
@ -15,7 +15,7 @@ public enum Blockchain {
|
|||
BitcoinCash("BCH", "BCH", R.drawable.ic_logo_bitcoin_cash, "Bitcoin Cash"),
|
||||
Litecoin("LTC", "LTC", R.drawable.ic_logo_bitcoin, "Litecoin"),
|
||||
Stellar("XLM", "XLM", R.drawable.ic_logo_stellar, "Stellar Lumens"),
|
||||
StellarTestNet("XLM/test", "XLM", R.drawable.ic_logo_bitcoin, "Stellar Lumens");
|
||||
StellarTestNet("XLM/test", "XLM", R.drawable.ic_logo_stellar, "Stellar Lumens");
|
||||
Blockchain(String ID, String currency, int imageResource, String officialName) {
|
||||
mID = ID;
|
||||
mCurrency = currency;
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
package com.tangem.data.network;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
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 org.stellar.sdk.Network;
|
||||
import org.stellar.sdk.Server;
|
||||
import org.stellar.sdk.requests.ErrorResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
|
@ -18,15 +18,17 @@ import io.reactivex.observers.DefaultObserver;
|
|||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Request processor for Electrum Api
|
||||
* Created by dvol on 7.01.2019.
|
||||
*
|
||||
* Request processor for Stellar Horizon Rest Api
|
||||
* Every request live cycle:
|
||||
* 1. In application create request and call {@link ServerApiStellar}.requestData(..)
|
||||
* 2. Try send every request for max 4 times,
|
||||
* 3. If all 4 times fail call DefaultObserver<StellarRequest>.onError (defined in .requestData(..)) and than
|
||||
* {@link Listener}.onFail(...) callback
|
||||
* Error can be acquired with {@link StellarRequest}.getError() method
|
||||
* 4. If request network communication finished successfully then call DefaultObserver<StellarRequest>.onComplete (defined in .requestData) and than
|
||||
* {@link Listener}.onSuccess(...) callback
|
||||
* {@link Listener}.onFail(...) callback
|
||||
* Error can be acquired with {@link StellarRequest}.getError() method
|
||||
* 4. If request network communication finished successfully then call DefaultObserver<StellarRequest.Base>.onComplete (defined in .requestData) and than
|
||||
* {@link Listener}.onSuccess(...) callback
|
||||
*/
|
||||
public class ServerApiStellar {
|
||||
private static String TAG = ServerApiStellar.class.getSimpleName();
|
||||
|
|
@ -37,10 +39,10 @@ public class ServerApiStellar {
|
|||
*/
|
||||
private Listener listener;
|
||||
|
||||
private int requestsCount=0;
|
||||
private int requestsCount = 0;
|
||||
|
||||
public boolean isRequestsSequenceCompleted() {
|
||||
Log.i(TAG, String.format("isRequestsSequenceCompleted: %s (%d requests left)", String.valueOf(requestsCount <= 0), requestsCount));
|
||||
LOG.i(TAG, String.format("isRequestsSequenceCompleted: %s (%d requests left)", String.valueOf(requestsCount <= 0), requestsCount));
|
||||
return requestsCount <= 0;
|
||||
}
|
||||
|
||||
|
|
@ -51,11 +53,14 @@ public class ServerApiStellar {
|
|||
|
||||
/**
|
||||
* Notify that request processing was successful
|
||||
*
|
||||
* @param stellarRequest - processed request containing received answer {@see stellarRequest.getAnswer() method}
|
||||
*/
|
||||
void onSuccess(StellarRequest.Base stellarRequest);
|
||||
|
||||
/**
|
||||
* Notify that request processing was successful
|
||||
*
|
||||
* @param stellarRequest - processed request containing occurred error {@see stellarRequest.getError() method}
|
||||
*/
|
||||
void onFail(StellarRequest.Base stellarRequest);
|
||||
|
|
@ -63,6 +68,7 @@ public class ServerApiStellar {
|
|||
|
||||
/**
|
||||
* Set notificaion listener
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
public void setListener(Listener listener) {
|
||||
|
|
@ -72,25 +78,26 @@ public class ServerApiStellar {
|
|||
|
||||
/**
|
||||
* Start process request
|
||||
*
|
||||
* @param ctx
|
||||
* @param stellarRequest
|
||||
*/
|
||||
public void requestData(TangemContext ctx, StellarRequest.Base stellarRequest) {
|
||||
requestsCount++;
|
||||
Log.i(TAG, String.format("New request[%d]: %s", requestsCount,stellarRequest.getClass().getSimpleName()));
|
||||
LOG.i(TAG, String.format("New request[%d]: %s", requestsCount, stellarRequest.getClass().getSimpleName()));
|
||||
Observable<StellarRequest.Base> stellarObserver = Observable.just(stellarRequest)
|
||||
.doOnNext(stellarRequest1 -> doStellarRequest(ctx, stellarRequest))
|
||||
.doOnEach(stellarRequest1 -> doStellarRequest(ctx, stellarRequest))
|
||||
|
||||
// .flatMap(stellarRequest1 -> {
|
||||
// if (stellarRequest1.answerData == null) {
|
||||
// Log.e(TAG, "NullPointerException " + stellarRequest.getMethod());
|
||||
// return Observable.error(new NullPointerException());
|
||||
// } else
|
||||
// return Observable.just(stellarRequest1);
|
||||
// })
|
||||
//
|
||||
.flatMap(stellarRequest1 -> {
|
||||
if (stellarRequest1.errorResponse != null) {
|
||||
LOG.e(TAG, "Error response on " + stellarRequest.getClass().getSimpleName());
|
||||
return Observable.error(stellarRequest.errorResponse);
|
||||
} else
|
||||
return Observable.just(stellarRequest1);
|
||||
}
|
||||
)
|
||||
.retryWhen(errors -> errors
|
||||
.filter(throwable -> throwable instanceof IOException)
|
||||
.filter(throwable -> (throwable instanceof IOException) || (throwable instanceof ErrorResponse))
|
||||
.zipWith(Observable.range(1, 4), (n, i) -> i))
|
||||
|
||||
.subscribeOn(Schedulers.io())
|
||||
|
|
@ -99,14 +106,14 @@ public class ServerApiStellar {
|
|||
|
||||
@Override
|
||||
public void onNext(StellarRequest.Base stellarRequest) {
|
||||
|
||||
LOG.e(TAG, "requestData " + stellarRequest.getClass().getSimpleName() + " onNext ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
requestsCount--;
|
||||
Log.e(TAG, "requestData " + stellarRequest.getClass().getSimpleName() + " onError " + e.getMessage());
|
||||
Log.e(TAG, String.format("%d requests left in processing",requestsCount));
|
||||
LOG.e(TAG, "requestData " + stellarRequest.getClass().getSimpleName() + " onError " + e.getMessage());
|
||||
LOG.e(TAG, String.format("%d requests left in processing", requestsCount));
|
||||
stellarRequest.setError(ctx.getString(R.string.cannot_obtain_data_from_blockchain));
|
||||
//setErrorOccurred(e.getMessage());//;
|
||||
listener.onFail(stellarRequest);
|
||||
|
|
@ -118,12 +125,12 @@ public class ServerApiStellar {
|
|||
@Override
|
||||
public void onComplete() {
|
||||
requestsCount--;
|
||||
Log.e(TAG, String.format("%d requests left in processing",requestsCount));
|
||||
LOG.e(TAG, String.format("%d requests left in processing", requestsCount));
|
||||
if (stellarRequest.getError() != null) {
|
||||
Log.i(TAG, "requestData " + stellarRequest.getClass().getSimpleName() + " onComplete, error!=null");
|
||||
LOG.i(TAG, "requestData " + stellarRequest.getClass().getSimpleName() + " onComplete, error!=null");
|
||||
listener.onFail(stellarRequest);
|
||||
} else {
|
||||
Log.e(TAG, "requestData " + stellarRequest.getClass().getSimpleName() + " onComplete, error==null");
|
||||
LOG.e(TAG, "requestData " + stellarRequest.getClass().getSimpleName() + " onComplete, error==null");
|
||||
listener.onSuccess(stellarRequest);
|
||||
}
|
||||
}
|
||||
|
|
@ -134,14 +141,19 @@ public class ServerApiStellar {
|
|||
private void doStellarRequest(TangemContext ctx, StellarRequest.Base stellarRequest) throws IOException {
|
||||
stellarRequest.setError(null);
|
||||
try {
|
||||
if( ctx.getBlockchain()==Blockchain.StellarTestNet ) {
|
||||
if (ctx.getBlockchain() == Blockchain.StellarTestNet) {
|
||||
Network.useTestNetwork();
|
||||
}
|
||||
Server server = new Server(ServerURL.API_STELLAR);
|
||||
stellarRequest.process(server);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
try {
|
||||
LOG.e(TAG, "--- request " + stellarRequest.getClass().getSimpleName());
|
||||
stellarRequest.process(server);
|
||||
} catch (ErrorResponse errorResponse) {
|
||||
LOG.e(TAG, "--- error response: " + errorResponse.getMessage());
|
||||
stellarRequest.errorResponse = errorResponse;
|
||||
stellarRequest.setError(errorResponse.getMessage());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
stellarRequest.setError(App.getInstance().getString(R.string.cannot_obtain_data_from_blockchain_communication_error));
|
||||
throw e;
|
||||
|
|
|
|||
|
|
@ -3,19 +3,22 @@ package com.tangem.data.network;
|
|||
import org.stellar.sdk.KeyPair;
|
||||
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.SubmitTransactionResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by dvol on 16.07.2017.
|
||||
* Created by dvol on 7.01.2019.
|
||||
*/
|
||||
|
||||
public class StellarRequest {
|
||||
|
||||
public static abstract class Base {
|
||||
public ErrorResponse errorResponse;
|
||||
private String error = null;
|
||||
|
||||
public String getError() {
|
||||
return error;
|
||||
}
|
||||
|
|
@ -28,28 +31,25 @@ public class StellarRequest {
|
|||
}
|
||||
|
||||
public static class Balance extends Base {
|
||||
public KeyPair accountKeyPair;
|
||||
KeyPair accountKeyPair;
|
||||
public AccountResponse accountResponse;
|
||||
|
||||
public Balance(String walletAddress)
|
||||
{
|
||||
accountKeyPair=KeyPair.fromAccountId(walletAddress);
|
||||
public Balance(String walletAddress) {
|
||||
accountKeyPair = KeyPair.fromAccountId(walletAddress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(Server server) throws IOException {
|
||||
accountResponse=server.accounts().account(accountKeyPair);
|
||||
accountResponse = server.accounts().account(accountKeyPair);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SubmitTransaction extends Base {
|
||||
// public KeyPair sourceAccount;
|
||||
// public KeyPair targetAccount;
|
||||
public Transaction transaction;
|
||||
public SubmitTransactionResponse response;
|
||||
|
||||
public SubmitTransaction(Transaction transaction) {
|
||||
this.transaction=transaction;
|
||||
this.transaction = transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ object CoinEngineFactory {
|
|||
Blockchain.Ethereum, Blockchain.EthereumTestNet -> EthEngine()
|
||||
Blockchain.Token -> TokenEngine()
|
||||
Blockchain.Litecoin -> LtcEngine()
|
||||
Blockchain.StellarTestNet, Blockchain.Stellar -> XlmEngine()
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,15 +6,26 @@ import android.util.Log;
|
|||
import com.tangem.domain.wallet.CoinData;
|
||||
import com.tangem.domain.wallet.CoinEngine;
|
||||
|
||||
import org.stellar.sdk.Account;
|
||||
import org.stellar.sdk.KeyPair;
|
||||
import org.stellar.sdk.responses.AccountResponse;
|
||||
import org.stellar.sdk.responses.GsonSingleton;
|
||||
|
||||
import java.math.BigInteger;
|
||||
/*
|
||||
* Created by dvol on 7.01.2019.
|
||||
*/
|
||||
|
||||
public class XlmData extends CoinData {
|
||||
private CoinEngine.InternalAmount balance = null;
|
||||
private AccountResponse accountResponse = null;
|
||||
|
||||
|
||||
public static class AccountResponseEx extends AccountResponse
|
||||
{
|
||||
AccountResponseEx(String accountId, Long sequenceNumber) {
|
||||
super(KeyPair.fromAccountId(accountId), sequenceNumber);
|
||||
}
|
||||
}
|
||||
|
||||
private CoinEngine.Amount balance = null;
|
||||
|
||||
private Long sequenceNumber = 0L;
|
||||
|
||||
|
||||
@Override
|
||||
|
|
@ -23,21 +34,26 @@ public class XlmData extends CoinData {
|
|||
balance = null;
|
||||
}
|
||||
|
||||
public CoinEngine.InternalAmount getBalanceInInternalUnits() {
|
||||
CoinEngine.Amount getBalanceXLM() {
|
||||
return balance;
|
||||
|
||||
}
|
||||
|
||||
public void setBalanceInInternalUnits(CoinEngine.InternalAmount value) {
|
||||
balance = value;
|
||||
AccountResponse getAccountResponse() {
|
||||
return new AccountResponseEx(getWallet(), sequenceNumber);
|
||||
}
|
||||
|
||||
public AccountResponse getAccountResponse() {
|
||||
return accountResponse;
|
||||
void setAccountResponse(AccountResponse accountResponse) {
|
||||
if( accountResponse.getBalances().length>0 ) {
|
||||
AccountResponse.Balance balanceResponse = accountResponse.getBalances()[0];
|
||||
balance = new CoinEngine.Amount(balanceResponse.getBalance(), "XLM");
|
||||
}
|
||||
sequenceNumber = accountResponse.getSequenceNumber();
|
||||
setBalanceReceived(true);
|
||||
}
|
||||
|
||||
public void setAccountResponse(AccountResponse accountResponse) {
|
||||
this.accountResponse = accountResponse;
|
||||
public void incSequenceNumber() {
|
||||
sequenceNumber++;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -46,17 +62,16 @@ public class XlmData extends CoinData {
|
|||
|
||||
if (B.containsKey("BalanceCurrency") && B.containsKey("BalanceDecimal")) {
|
||||
String currency = B.getString("BalanceCurrency");
|
||||
balance = new CoinEngine.InternalAmount(B.getString("BalanceDecimal"), currency);
|
||||
balance = new CoinEngine.Amount(B.getString("BalanceDecimal"), currency);
|
||||
} else {
|
||||
balance = null;
|
||||
}
|
||||
|
||||
if (B.containsKey("accountResponse")) {
|
||||
accountResponse = GsonSingleton.getInstance().fromJson(B.getString("accountResponse"), AccountResponse.class);
|
||||
if (B.containsKey("sequenceNumber")) {
|
||||
sequenceNumber = B.getLong("sequenceNumber");
|
||||
} else {
|
||||
accountResponse = null;
|
||||
sequenceNumber = 0L;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -65,11 +80,11 @@ public class XlmData extends CoinData {
|
|||
try {
|
||||
if (balance != null) {
|
||||
B.putString("BalanceCurrency", balance.getCurrency());
|
||||
B.putString("BalanceDecimal", balance.toString());
|
||||
B.putString("BalanceDecimal", balance.toValueString());
|
||||
}
|
||||
|
||||
if (accountResponse != null) {
|
||||
B.putString("accountResponse", GsonSingleton.getInstance().toJson(accountResponse));
|
||||
if (sequenceNumber != null) {
|
||||
B.putLong("sequenceNumber", sequenceNumber);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
|
@ -77,5 +92,5 @@ public class XlmData extends CoinData {
|
|||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -19,17 +19,19 @@ import com.tangem.wallet.R;
|
|||
|
||||
import org.stellar.sdk.AssetTypeNative;
|
||||
import org.stellar.sdk.KeyPair;
|
||||
import org.stellar.sdk.Memo;
|
||||
import org.stellar.sdk.PaymentOperation;
|
||||
import org.stellar.sdk.Transaction;
|
||||
import org.stellar.sdk.responses.AccountResponse;
|
||||
import org.stellar.sdk.xdr.TransactionEnvelope;
|
||||
import org.stellar.sdk.xdr.XdrDataInputStream;
|
||||
import org.stellar.sdk.TransactionEx;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
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
|
||||
**/
|
||||
|
||||
public class XlmEngine extends CoinEngine {
|
||||
|
||||
private static final String TAG = XlmEngine.class.getSimpleName();
|
||||
|
|
@ -53,6 +55,7 @@ public class XlmEngine extends CoinEngine {
|
|||
}
|
||||
|
||||
private static int getDecimals() {
|
||||
//TODO - Is it's right?
|
||||
return 8;
|
||||
}
|
||||
|
||||
|
|
@ -93,14 +96,14 @@ public class XlmEngine extends CoinEngine {
|
|||
@Override
|
||||
public boolean isBalanceNotZero() {
|
||||
if (coinData == null) return false;
|
||||
if (coinData.getBalanceInInternalUnits() == null) return false;
|
||||
return coinData.getBalanceInInternalUnits().notZero();
|
||||
if (coinData.getBalanceXLM() == null) return false;
|
||||
return coinData.getBalanceXLM().notZero();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBalanceInfo() {
|
||||
if (coinData == null) return false;
|
||||
return coinData.getBalanceInInternalUnits() != null;
|
||||
return coinData.getBalanceXLM() != null;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -145,17 +148,16 @@ public class XlmEngine extends CoinEngine {
|
|||
|
||||
@Override
|
||||
public Uri getShareWalletUriExplorer() {
|
||||
//TODO - ?
|
||||
return Uri.parse((ctx.getBlockchain() == Blockchain.Bitcoin ? "https://blockchain.info/address/" : "https://testnet.blockchain.info/address/") + ctx.getCoinData().getWallet());
|
||||
return Uri.parse((ctx.getBlockchain() == Blockchain.Bitcoin ? "http://testnet.stellarchain.io/address/" : "http://testnet.stellarchain.io/address/") + ctx.getCoinData().getWallet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uri getShareWalletUri() {
|
||||
//TODO - ?
|
||||
//TODO - how to construct payment query intent for stellar?
|
||||
if (ctx.getCard().getDenomination() != null) {
|
||||
return Uri.parse("bitcoin:" + ctx.getCoinData().getWallet() + "?amount=" + convertToAmount(convertToInternalAmount(ctx.getCard().getDenomination())).toValueString(8));
|
||||
return Uri.parse("stellar:" + ctx.getCoinData().getWallet() + "?amount=" + convertToAmount(convertToInternalAmount(ctx.getCard().getDenomination())).toValueString());
|
||||
} else {
|
||||
return Uri.parse("bitcoin:" + ctx.getCoinData().getWallet());
|
||||
return Uri.parse("stellar:" + ctx.getCoinData().getWallet());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -167,7 +169,7 @@ public class XlmEngine extends CoinEngine {
|
|||
@Override
|
||||
public boolean checkNewTransactionAmount(Amount amount) {
|
||||
if (coinData == null) return false;
|
||||
if (amount.compareTo(convertToAmount(coinData.getBalanceInInternalUnits())) > 0) {
|
||||
if (amount.compareTo(coinData.getBalanceXLM()) > 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
@ -175,28 +177,23 @@ public class XlmEngine extends CoinEngine {
|
|||
|
||||
@Override
|
||||
public boolean checkNewTransactionAmountAndFee(Amount amountValue, Amount feeValue, Boolean isIncludeFee) {
|
||||
InternalAmount fee;
|
||||
InternalAmount amount;
|
||||
|
||||
try {
|
||||
checkBlockchainDataExists();
|
||||
amount = convertToInternalAmount(amountValue);
|
||||
fee = convertToInternalAmount(feeValue);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fee == null || amount == null)
|
||||
if (feeValue == null || amountValue == null)
|
||||
return false;
|
||||
|
||||
if (fee.isZero() || amount.isZero())
|
||||
if (feeValue.isZero() || amountValue.isZero())
|
||||
return false;
|
||||
|
||||
if (isIncludeFee && (amount.compareTo(coinData.getBalanceInInternalUnits()) > 0 || amount.compareTo(fee) < 0))
|
||||
if (isIncludeFee && (amountValue.compareTo(coinData.getBalanceXLM()) > 0 || amountValue.compareTo(feeValue) < 0))
|
||||
return false;
|
||||
|
||||
if (!isIncludeFee && amount.add(fee).compareTo(coinData.getBalanceInInternalUnits()) > 0)
|
||||
if (!isIncludeFee && amountValue.add(feeValue).compareTo(coinData.getBalanceXLM()) > 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -231,7 +228,7 @@ public class XlmEngine extends CoinEngine {
|
|||
balanceValidator.setScore(100);
|
||||
balanceValidator.setFirstLine("Verified balance");
|
||||
balanceValidator.setSecondLine("Balance confirmed in blockchain");
|
||||
if (coinData.getBalanceInInternalUnits().isZero()) {
|
||||
if (coinData.getBalanceXLM().isZero()) {
|
||||
balanceValidator.setFirstLine("Empty wallet");
|
||||
balanceValidator.setSecondLine("");
|
||||
}
|
||||
|
|
@ -246,7 +243,7 @@ public class XlmEngine extends CoinEngine {
|
|||
// return;
|
||||
// }
|
||||
|
||||
if ((ctx.getCard().getOfflineBalance() != null) && !coinData.isBalanceReceived() && (ctx.getCard().getRemainingSignatures() == ctx.getCard().getMaxSignatures()) && coinData.getBalanceInInternalUnits().notZero()) {
|
||||
if ((ctx.getCard().getOfflineBalance() != null) && !coinData.isBalanceReceived() && (ctx.getCard().getRemainingSignatures() == ctx.getCard().getMaxSignatures()) && coinData.getBalanceXLM().notZero()) {
|
||||
balanceValidator.setScore(80);
|
||||
balanceValidator.setFirstLine("Verified offline balance");
|
||||
balanceValidator.setSecondLine("Can't obtain balance from blockchain. Restore internet connection to be more confident. ");
|
||||
|
|
@ -277,7 +274,7 @@ public class XlmEngine extends CoinEngine {
|
|||
@Override
|
||||
public Amount getBalance() {
|
||||
if (!hasBalanceInfo()) return null;
|
||||
return convertToAmount(coinData.getBalanceInInternalUnits());
|
||||
return coinData.getBalanceXLM();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -305,7 +302,7 @@ public class XlmEngine extends CoinEngine {
|
|||
return kp.getAccountId();
|
||||
}
|
||||
|
||||
private static BigDecimal multiplier = new BigDecimal("1000000");
|
||||
private static BigDecimal multiplier = new BigDecimal("10000000");
|
||||
|
||||
@Override
|
||||
public Amount convertToAmount(InternalAmount internalAmount) {
|
||||
|
|
@ -350,16 +347,17 @@ public class XlmEngine extends CoinEngine {
|
|||
return "";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SignTask.PaymentToSign constructPayment(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) throws Exception {
|
||||
checkBlockchainDataExists();
|
||||
|
||||
Transaction transaction = new Transaction.Builder(coinData.getAccountResponse())
|
||||
.addOperation(new PaymentOperation.Builder(KeyPair.fromAccountId(targetAddress), new AssetTypeNative(), amountValue.toValueString()).build())
|
||||
// A memo allows you to add your own metadata to a transaction. It's
|
||||
// optional and does not affect how Stellar treats the transaction.
|
||||
.addMemo(Memo.text("TangemCard Transaction"))
|
||||
.build();
|
||||
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());
|
||||
|
||||
if( transaction.getFee()!=convertToInternalAmount(feeValue).intValueExact() )
|
||||
{
|
||||
|
|
@ -382,12 +380,12 @@ public class XlmEngine extends CoinEngine {
|
|||
|
||||
@Override
|
||||
public byte[] getRawDataToSign() throws Exception {
|
||||
throw new Exception("Hashes length must be identical!");
|
||||
return transaction.signatureBase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHashAlgToSign() {
|
||||
return "sha-256x2";
|
||||
return "sha-256";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -398,7 +396,7 @@ public class XlmEngine extends CoinEngine {
|
|||
@Override
|
||||
public byte[] onSignCompleted(byte[] signFromCard) throws Exception {
|
||||
// Sign the transaction to prove you are actually the person sending it.
|
||||
transaction.sign(signFromCard);
|
||||
transaction.setSign(signFromCard);
|
||||
|
||||
byte[] txForSend = transaction.toEnvelopeXdrBase64().getBytes();
|
||||
notifyOnNeedSendPayment(txForSend);
|
||||
|
|
@ -423,8 +421,6 @@ public class XlmEngine extends CoinEngine {
|
|||
StellarRequest.Balance balanceRequest = (StellarRequest.Balance) request;
|
||||
|
||||
coinData.setAccountResponse(balanceRequest.accountResponse);
|
||||
AccountResponse.Balance balance=balanceRequest.accountResponse.getBalances()[0];
|
||||
coinData.setBalanceInInternalUnits(new InternalAmount(balance.getBalance(), "stroops"));
|
||||
if (serverApi.isRequestsSequenceCompleted()) {
|
||||
blockchainRequestsCallbacks.onComplete(!ctx.hasError());
|
||||
} else {
|
||||
|
|
@ -453,6 +449,7 @@ public class XlmEngine extends CoinEngine {
|
|||
@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;
|
||||
|
|
@ -477,7 +474,15 @@ public class XlmEngine extends CoinEngine {
|
|||
ctx.setError(null);
|
||||
blockchainRequestsCallbacks.onComplete(true);
|
||||
} else {
|
||||
ctx.setError("Rejected by node");
|
||||
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);
|
||||
}
|
||||
ctx.setError(trResult);
|
||||
}else{
|
||||
ctx.setError("transaction failed");
|
||||
}
|
||||
blockchainRequestsCallbacks.onComplete(false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
@ -500,8 +505,8 @@ public class XlmEngine extends CoinEngine {
|
|||
};
|
||||
serverApi.setListener(listener);
|
||||
|
||||
TransactionEnvelope transactionEnvelope = TransactionEnvelope.decode(new XdrDataInputStream(new ByteArrayInputStream(txForSend)));
|
||||
org.stellar.sdk.Transaction transaction = org.stellar.sdk.Transaction.fromEnvelopeXdr(transactionEnvelope);
|
||||
Transaction transaction = TransactionEx.fromEnvelopeXdr(new String(txForSend));
|
||||
coinData.incSequenceNumber();
|
||||
serverApi.requestData(ctx, new StellarRequest.SubmitTransaction(transaction));
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,9 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
|
||||
btnSend.visibility = View.INVISIBLE
|
||||
|
||||
rgFee.isEnabled = !(ctx.blockchain == Blockchain.Ethereum || ctx.blockchain == Blockchain.EthereumTestNet || ctx.blockchain == Blockchain.Token || ctx.blockchain == Blockchain.BitcoinCash || ctx.blockchain == Blockchain.Litecoin)
|
||||
for (lol in rgFee.touchables) {
|
||||
lol.isEnabled = !(ctx.blockchain == Blockchain.Ethereum || ctx.blockchain == Blockchain.EthereumTestNet || ctx.blockchain == Blockchain.Token || ctx.blockchain == Blockchain.BitcoinCash || ctx.blockchain == Blockchain.Litecoin || ctx.blockchain == Blockchain.Stellar || ctx.blockchain == Blockchain.StellarTestNet)
|
||||
}
|
||||
|
||||
// set listeners
|
||||
rgFee.setOnCheckedChangeListener { _, checkedId -> doSetFee(checkedId) }
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
if (success)
|
||||
finishWithSuccess()
|
||||
else
|
||||
finishWithError(this@SendTransactionActivity.getString(R.string.try_again_failed_to_send_transaction))
|
||||
finishWithError(ctx.error)
|
||||
}
|
||||
|
||||
override fun onProgress() {
|
||||
|
|
|
|||
|
|
@ -622,7 +622,8 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
// Litecoin
|
||||
// BitcoinCash
|
||||
if (ctx.blockchain == Blockchain.Bitcoin || ctx.blockchain == Blockchain.BitcoinTestNet ||
|
||||
ctx.blockchain == Blockchain.Litecoin || ctx.blockchain == Blockchain.BitcoinCash) {
|
||||
ctx.blockchain == Blockchain.Litecoin || ctx.blockchain == Blockchain.BitcoinCash ||
|
||||
ctx.blockchain == Blockchain.Stellar || ctx.blockchain == Blockchain.StellarTestNet ) {
|
||||
ctx.coinData.setIsBalanceEqual(true)
|
||||
}
|
||||
|
||||
|
|
@ -705,6 +706,8 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
Blockchain.Token -> "ethereum"
|
||||
Blockchain.BitcoinCash -> "bitcoin-cash"
|
||||
Blockchain.Litecoin -> "litecoin"
|
||||
Blockchain.Stellar -> "stellar"
|
||||
Blockchain.StellarTestNet -> "stellar"
|
||||
else -> {
|
||||
throw Exception("Can''t get rate for blockchain " + ctx.blockchainName)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue