Updated on 2026-08-14

This commit is contained in:
Tangem 2019-06-18 18:53:38 +03:00
parent bd8d84a85a
commit 6259944ff1
7 changed files with 161 additions and 85 deletions

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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";
}

View file

@ -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);
}
}
}