Updated on 2026-08-14
This commit is contained in:
parent
aed5a8558f
commit
bacb21c115
5 changed files with 61 additions and 28 deletions
|
|
@ -2,12 +2,10 @@ package com.tangem.data.network;
|
|||
|
||||
import android.util.Log;
|
||||
|
||||
import com.tangem.App;
|
||||
import com.tangem.data.network.model.RippleBody;
|
||||
import com.tangem.data.network.model.RippleResponse;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import retrofit2.Call;
|
||||
|
|
@ -23,8 +21,9 @@ public class ServerApiRipple {
|
|||
public static final String RIPPLE_ACCOUNT_UNCONFIRMED = "account_unconfirmed";
|
||||
public static final String RIPPLE_SUBMIT = "submit";
|
||||
public static final String RIPPLE_FEE = "fee";
|
||||
public static final String RIPPLE_SERVER_STATE = "server_state";
|
||||
|
||||
private int requestsCount=0;
|
||||
private int requestsCount = 0;
|
||||
|
||||
public static String lastNode;
|
||||
|
||||
|
|
@ -76,6 +75,10 @@ public class ServerApiRipple {
|
|||
rippleBody = new RippleBody(RIPPLE_ACCOUNT_INFO, paramsMap);
|
||||
break;
|
||||
|
||||
case RIPPLE_SERVER_STATE:
|
||||
rippleBody = new RippleBody(method, new HashMap<>());
|
||||
break;
|
||||
|
||||
case RIPPLE_FEE:
|
||||
rippleBody = new RippleBody(method, new HashMap<>());
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ data class RippleResult(
|
|||
|
||||
//for RIPPLE_FEE
|
||||
@SerializedName("drops")
|
||||
var drops: FeeDrops? = null,
|
||||
var drops: RippleFeeDrops? = null,
|
||||
|
||||
//for RIPPLE_SUBMIT
|
||||
@SerializedName("engine_result_code")
|
||||
|
|
@ -32,8 +32,11 @@ data class RippleResult(
|
|||
|
||||
//for RIPPLE_SUBMIT
|
||||
@SerializedName("error_exception")
|
||||
var error_exception: String? = null
|
||||
var error_exception: String? = null,
|
||||
|
||||
//for RIPPLE_SERVER_STATE
|
||||
@SerializedName("state")
|
||||
var state: RippleState? = null
|
||||
)
|
||||
|
||||
data class RippleAccountData(
|
||||
|
|
@ -47,7 +50,7 @@ data class RippleAccountData(
|
|||
var sequence: Long? = null
|
||||
)
|
||||
|
||||
data class FeeDrops(
|
||||
data class RippleFeeDrops(
|
||||
//enough to put tx to queue
|
||||
@SerializedName("minimum_fee")
|
||||
var minimum_fee: String? = null,
|
||||
|
|
@ -58,4 +61,14 @@ data class FeeDrops(
|
|||
|
||||
@SerializedName("median_fee")
|
||||
var median_fee: String? = null
|
||||
)
|
||||
|
||||
data class RippleState(
|
||||
@SerializedName("validated_ledger")
|
||||
var validated_ledger: RippleLedger? = null
|
||||
)
|
||||
|
||||
data class RippleLedger(
|
||||
@SerializedName("reserve_base")
|
||||
var reserve_base: Long? = null
|
||||
)
|
||||
|
|
@ -10,8 +10,8 @@ import com.tangem.data.local.PendingTransactionsStorage;
|
|||
import com.tangem.data.network.ServerApiAdalite;
|
||||
import com.tangem.data.network.model.AdaliteResponse;
|
||||
import com.tangem.data.network.model.AdaliteResponseUtxo;
|
||||
import com.tangem.data.network.model.TxData;
|
||||
import com.tangem.data.network.model.UtxoData;
|
||||
import com.tangem.data.network.model.AdaliteTxData;
|
||||
import com.tangem.data.network.model.AdaliteUtxoData;
|
||||
import com.tangem.domain.wallet.BTCUtils;
|
||||
import com.tangem.domain.wallet.BalanceValidator;
|
||||
import com.tangem.domain.wallet.Base58;
|
||||
|
|
@ -625,7 +625,7 @@ public class CardanoEngine extends CoinEngine {
|
|||
if (App.pendingTransactionsStorage.hasTransactions(ctx.getCard())) {
|
||||
for (PendingTransactionsStorage.TransactionInfo pendingTx : App.pendingTransactionsStorage.getTransactions(ctx.getCard()).getTransactions()) {
|
||||
String pendingId = CalculateTxHash(pendingTx.getTx());
|
||||
for (TxData walletTx : adaliteResponse.getRight().getCaTxList()) {
|
||||
for (AdaliteTxData walletTx : adaliteResponse.getRight().getCaTxList()) {
|
||||
if (walletTx.getCtbId().equals(pendingId)) {
|
||||
App.pendingTransactionsStorage.removeTransaction(ctx.getCard(), pendingTx.getTx());
|
||||
}
|
||||
|
|
@ -651,7 +651,7 @@ public class CardanoEngine extends CoinEngine {
|
|||
Log.i(TAG, "onSuccess: " + method);
|
||||
try {
|
||||
coinData.getUnspentOutputs().clear();
|
||||
for (UtxoData utxo : adaliteResponseUtxo.getRight()) {
|
||||
for (AdaliteUtxoData utxo : adaliteResponseUtxo.getRight()) {
|
||||
CardanoData.UnspentOutput unspentOutput = new CardanoData.UnspentOutput();
|
||||
unspentOutput.txID = utxo.getCuId();
|
||||
unspentOutput.Amount = utxo.getCuCoins().getGetCoin();
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ public class XrpData extends CoinData {
|
|||
}
|
||||
|
||||
private Long balanceConfirmed, balanceUnconfirmed, sequence;
|
||||
|
||||
private Long reserve = 20000000L;
|
||||
|
||||
@Override
|
||||
|
|
@ -22,10 +23,12 @@ public class XrpData extends CoinData {
|
|||
|
||||
if (B.containsKey("BalanceConfirmed")) balanceConfirmed = B.getLong("BalanceConfirmed");
|
||||
else balanceConfirmed = null;
|
||||
if (B.containsKey("BalanceUnconfirmed"))
|
||||
balanceUnconfirmed = B.getLong("BalanceUnconfirmed");
|
||||
if (B.containsKey("BalanceUnconfirmed")) balanceUnconfirmed = B.getLong("BalanceUnconfirmed");
|
||||
else balanceUnconfirmed = null;
|
||||
if (B.containsKey("Sequence")) sequence = B.getLong("Sequence");
|
||||
else sequence = null;
|
||||
if (B.containsKey("Reserve")) reserve = B.getLong("Reserve");
|
||||
else reserve = 20000000L;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -35,6 +38,7 @@ public class XrpData extends CoinData {
|
|||
if (balanceConfirmed != null) B.putLong("BalanceConfirmed", balanceConfirmed);
|
||||
if (balanceUnconfirmed != null) B.putLong("BalanceUnconfirmed", balanceUnconfirmed);
|
||||
if (sequence != null) B.putLong("Sequence", sequence);
|
||||
if (reserve != null) B.putLong("Reserve", reserve);
|
||||
} catch (Exception e) {
|
||||
Log.e("Can't save to bundle ", e.getMessage());
|
||||
}
|
||||
|
|
@ -46,6 +50,7 @@ public class XrpData extends CoinData {
|
|||
balanceConfirmed = null;
|
||||
balanceUnconfirmed = null;
|
||||
sequence = null;
|
||||
reserve = 20000000L;
|
||||
}
|
||||
|
||||
// balanceUnconfirmed is just the latest balance, it equals balanceConfirmed if no unconfirmed transaction present
|
||||
|
|
|
|||
|
|
@ -24,13 +24,7 @@ import com.tangem.util.CryptoUtil;
|
|||
import com.tangem.util.DecimalDigitsInputFilter;
|
||||
import com.tangem.wallet.R;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.NoSuchProviderException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class XrpEngine extends CoinEngine {
|
||||
|
||||
|
|
@ -450,7 +444,7 @@ public class XrpEngine extends CoinEngine {
|
|||
// for (PendingTransactionsStorage.TransactionInfo pendingTx : App.pendingTransactionsStorage.getTransactions(ctx.getCard()).getTransactions()) {
|
||||
// String pendingId = CalculateTxHash(pendingTx.getTx());
|
||||
// int x = 0;
|
||||
// for (TxData walletTx : adaliteResponse.getRight().getCaTxList()) {
|
||||
// for (AdaliteTxData walletTx : adaliteResponse.getRight().getCaTxList()) {
|
||||
// if (walletTx.getCtbId().equals(pendingId)) {
|
||||
// App.pendingTransactionsStorage.removeTransaction(ctx.getCard(), pendingTx.getTx());
|
||||
// }
|
||||
|
|
@ -464,6 +458,16 @@ public class XrpEngine extends CoinEngine {
|
|||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ServerApiRipple.RIPPLE_SERVER_STATE: {
|
||||
try {
|
||||
coinData.setReserve(rippleResponse.getResult().getState().getValidated_ledger().getReserve_base());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "FAIL RIPPLE_ACCOUNT_INFO Exception");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (serverApiRipple.isRequestsSequenceCompleted()) {
|
||||
|
|
@ -489,6 +493,7 @@ public class XrpEngine extends CoinEngine {
|
|||
|
||||
serverApiRipple.requestData(ServerApiRipple.RIPPLE_ACCOUNT_INFO, coinData.getWallet(), "");
|
||||
serverApiRipple.requestData(ServerApiRipple.RIPPLE_ACCOUNT_UNCONFIRMED, coinData.getWallet(), "");
|
||||
serverApiRipple.requestData(ServerApiRipple.RIPPLE_SERVER_STATE, "", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -498,15 +503,20 @@ public class XrpEngine extends CoinEngine {
|
|||
ServerApiRipple.ResponseListener rippleListener = new ServerApiRipple.ResponseListener() {
|
||||
@Override
|
||||
public void onSuccess(String method, RippleResponse rippleResponse) {
|
||||
InternalAmount minFee = new InternalAmount(Long.valueOf(rippleResponse.getResult().getDrops().getMinimum_fee()), "Drops");
|
||||
InternalAmount normalFee = new InternalAmount(Long.valueOf(rippleResponse.getResult().getDrops().getOpen_ledger_fee()), "Drops");
|
||||
InternalAmount maxFee = new InternalAmount(Long.valueOf(rippleResponse.getResult().getDrops().getMedian_fee()), "Drops");
|
||||
try {
|
||||
InternalAmount minFee = new InternalAmount(Long.valueOf(rippleResponse.getResult().getDrops().getMinimum_fee()), "Drops");
|
||||
InternalAmount normalFee = new InternalAmount(Long.valueOf(rippleResponse.getResult().getDrops().getOpen_ledger_fee()), "Drops");
|
||||
InternalAmount maxFee = new InternalAmount(Long.valueOf(rippleResponse.getResult().getDrops().getMedian_fee()), "Drops");
|
||||
|
||||
coinData.minFee = convertToAmount(minFee);
|
||||
coinData.normalFee = convertToAmount(normalFee);
|
||||
coinData.maxFee = convertToAmount(maxFee);
|
||||
coinData.minFee = convertToAmount(minFee);
|
||||
coinData.normalFee = convertToAmount(normalFee);
|
||||
coinData.maxFee = convertToAmount(maxFee);
|
||||
|
||||
blockchainRequestsCallbacks.onComplete(true);
|
||||
blockchainRequestsCallbacks.onComplete(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "FAIL RIPPLE_FEE Exception");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -524,7 +534,7 @@ public class XrpEngine extends CoinEngine {
|
|||
|
||||
@Override
|
||||
public void requestSendTransaction(BlockchainRequestsCallbacks blockchainRequestsCallbacks, byte[] txForSend) {
|
||||
final String txStr = BTCUtils.toHex(txForSend);
|
||||
final String txStr = BTCUtils.toHex(txForSend);
|
||||
|
||||
final ServerApiRipple serverApiRipple = new ServerApiRipple();
|
||||
|
||||
|
|
@ -568,7 +578,9 @@ public class XrpEngine extends CoinEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int pendingTransactionTimeoutInSeconds() { return 10; }
|
||||
public int pendingTransactionTimeoutInSeconds() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
public boolean needMultipleLinesForBalance() {
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue