Updated on 2026-08-14

This commit is contained in:
Tangem 2018-10-11 13:26:25 +03:00
parent 3b04da7388
commit 5a5c15ee23
9 changed files with 1 additions and 626 deletions

View file

@ -1,8 +1,6 @@
package com.tangem.data.network;
import com.tangem.data.network.model.CardVerifyAndGetInfo;
import com.tangem.data.network.model.CardVerifyBody;
import com.tangem.data.network.model.CardVerifyResponse;
import okhttp3.ResponseBody;
import retrofit2.Call;
@ -13,10 +11,6 @@ import retrofit2.http.POST;
import retrofit2.http.Query;
public interface TangemApi {
@Headers("Content-Type: application/json")
@POST(Server.ApiTangem.Method.VERIFY)
Call<CardVerifyResponse> getCardVerify(@Body CardVerifyBody body);
@Headers("Content-Type: application/json")
@POST(Server.ApiTangem.Method.VERIFY_AND_GET_INFO)
Call<CardVerifyAndGetInfo.Response> getCardVerifyAndGetInfo(@Body CardVerifyAndGetInfo.Request requestBody);
@ -24,5 +18,4 @@ public interface TangemApi {
@GET(Server.ApiTangem.Method.ARTWORK)
Call<ResponseBody> getArtwork(@Query("artworkId") String artworkId, @Query("CID") String CID, @Query("publicKey") String publicKey);
}

View file

@ -1,14 +1,8 @@
package com.tangem.data.network;
import com.tangem.data.network.model.CardVerifyBody;
import com.tangem.data.network.model.CardVerifyResponse;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.POST;
public interface UpdateVersionApi {
@GET(Server.ApiUpdateVersion.Method.LAST_VERSION)

View file

@ -1,10 +0,0 @@
package com.tangem.data.network.model;
public class CardVerifyBody {
private CardVerify[] requests;
public CardVerifyBody(CardVerify[] requests) {
this.requests = requests;
}
}

View file

@ -1,18 +0,0 @@
package com.tangem.data.network.model
import com.google.gson.annotations.SerializedName
data class CardVerifyResponse(
@SerializedName("results")
var results: List<Verify>? = null
) {
data class Verify(
@SerializedName("CID")
var CID: String = "",
@SerializedName("passed")
var passed: Boolean = false
)
}

View file

@ -1,92 +0,0 @@
package com.tangem.data.network.request;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Created by dvol on 16.07.2017.
*/
public class ExchangeRequest {
public JSONObject jsRequestData;
public String answerData;
public String error;
public String WalletAddress;
public String currency;
public String currencyAlter;
private ExchangeRequest() {
}
public ExchangeRequest(JSONObject jsRequest) {
try {
jsRequestData = new JSONObject(jsRequest.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
public JSONObject getAnswer() {
try {
return new JSONObject(answerData);
} catch (Exception e) {
try {
return new JSONObject(String.format("[\"Error\":\"%s\"]", e.getMessage()));
} catch (JSONException e1) {
e1.printStackTrace();
return null;
}
}
}
public JSONArray getAnswerList() throws JSONException {
return new JSONArray(answerData);
}
public String getAsString() {
return jsRequestData.toString();
}
public void setID(int value) {
try {
jsRequestData.put("id", String.format("%d", value));
} catch (JSONException e) {
e.printStackTrace();
}
}
public int getID() {
try {
return jsRequestData.getInt("id");
} catch (JSONException e) {
e.printStackTrace();
return 0;
}
}
public static ExchangeRequest GetRate(String wallet, String currency, String alterCurrency) {
ExchangeRequest request = new ExchangeRequest();
request.WalletAddress=wallet;
request.currency = currency;
request.currencyAlter = alterCurrency;
return request;
}
public JSONArray getParams() throws JSONException {
return jsRequestData.getJSONArray("params");
}
public JSONObject getResult() throws JSONException {
return getAnswer().getJSONObject("result");
}
public String getResultString() throws JSONException {
return getAnswer().getString("result");
}
public JSONArray getResultArray() throws JSONException {
return getAnswer().getJSONArray("result");
}
}

View file

@ -1,101 +0,0 @@
package com.tangem.data.network.request;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Created by dvol on 16.07.2017.
*/
public class FeeRequest {
public JSONObject jsRequestData;
public String answerData;
public String error;
public String WalletAddress;
public long txSize = 0;
private FeeRequest() {
}
public FeeRequest(JSONObject jsRequest) {
try {
jsRequestData = new JSONObject(jsRequest.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
public JSONObject getAnswer() {
try {
return new JSONObject(answerData);
} catch (Exception e) {
try {
return new JSONObject(String.format("[\"Error\":\"%s\"]", e.getMessage()));
} catch (JSONException e1) {
e1.printStackTrace();
return null;
}
}
}
public String getAsString() {
return answerData;
}
public static final int PRIORITY = 2;
public static final int NORMAL = 3;
public static final int MINIMAL = 6;
private int blockCount = NORMAL;
public void setBlockCount(int count
) {
blockCount = count;
}
public int getBlockCount() {
return blockCount;
}
public void setID(int value) {
try {
jsRequestData.put("id", String.format("%d", value));
} catch (JSONException e) {
e.printStackTrace();
}
}
public int getID() {
try {
return jsRequestData.getInt("id");
} catch (JSONException e) {
e.printStackTrace();
return 0;
}
}
public static FeeRequest GetFee(String wallet, long txSize, int blockCount) {
FeeRequest request = new FeeRequest();
request.WalletAddress = wallet;
request.txSize = txSize;
request.setBlockCount(blockCount);
return request;
}
public JSONArray getParams() throws JSONException {
return jsRequestData.getJSONArray("params");
}
public JSONObject getResult() throws JSONException {
return getAnswer().getJSONObject("result");
}
public String getResultString() throws JSONException {
return getAnswer().getString("result");
}
public JSONArray getResultArray() throws JSONException {
return getAnswer().getJSONArray("result");
}
}

View file

@ -1,200 +0,0 @@
package com.tangem.data.network.request;
/**
* Created by Ilia on 19.12.2017.
*/
import android.util.Log;
import com.tangem.domain.wallet.Blockchain;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class InfuraRequest {
public static final String METHOD_ETH_GetBalance = "eth_getBalance";
public static final String METHOD_ETH_GetOutTransactionCount = "eth_getTransactionCount";
public static final String METHOD_ETH_GetGasPrice = "eth_gasPrice";
public static final String METHOD_ETH_SendRawTransaction = "eth_sendRawTransaction";
public static final String METHOD_ETH_Call = "eth_call";
public JSONObject jsRequestData;
public String answerData;
public String error;
public String WalletAddress;
public int Dec;
public String amount;
public Blockchain blockchain;
public void setBlockchain(Blockchain value) {
blockchain = value;
}
public Blockchain getBlockchain() {
return blockchain;
}
private InfuraRequest() {
}
public InfuraRequest(JSONObject jsRequest) {
try {
jsRequestData = new JSONObject(jsRequest.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
public JSONObject getAnswer() {
try {
return new JSONObject(answerData);
} catch (Exception e) {
try {
return new JSONObject(String.format("[\"Error\":\"%s\"]", e.getMessage()));
} catch (JSONException e1) {
e1.printStackTrace();
return null;
}
}
}
public String getAsString() {
return jsRequestData.toString();
}
public void setID(int value) {
try {
jsRequestData.put("id", value/*String.format("%d", value)*/);
} catch (JSONException e) {
e.printStackTrace();
}
}
public int getID() {
try {
return jsRequestData.getInt("id");
} catch (JSONException e) {
e.printStackTrace();
return 0;
}
}
public boolean isMethod(String methodName) throws JSONException {
return jsRequestData.getString("method").equals(methodName);
}
public static InfuraRequest GetBalance(String wallet) {
InfuraRequest request = new InfuraRequest();
try {
request.WalletAddress = wallet;
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_ETH_GetBalance + "\", \"params\":[\"" + wallet + "\", \"latest\"] }");
} catch (JSONException e) {
e.printStackTrace();
request.error = e.toString();
}
return request;
}
public static InfuraRequest GetTokenBalance(String wallet, String contract, int dec) {
InfuraRequest request = new InfuraRequest();
try {
request.WalletAddress = wallet;
request.Dec = dec;
String address = wallet.substring(2);
String dataValue = String.format("{\"data\": \"0x70a08231000000000000000000000000%s\", \"to\": \"%s\"}", address, contract);
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_ETH_Call + "\", \"params\":[" + dataValue + ", \"latest\"] }");
Log.i("swdwd", request.jsRequestData.toString());
Log.i("swdwd + address", address);
Log.i("swdwd + contract", contract);
} catch (JSONException e) {
e.printStackTrace();
request.error = e.toString();
}
return request;
}
public static InfuraRequest SendTransaction(String wallet, String tx) {
InfuraRequest request = new InfuraRequest();
try {
request.WalletAddress = wallet;
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_ETH_SendRawTransaction + "\", \"params\":[\"" + tx + "\"] }");
} catch (JSONException e) {
e.printStackTrace();
request.error = e.toString();
}
return request;
}
public static InfuraRequest GetOutTransactionCount(String wallet) {
InfuraRequest request = new InfuraRequest();
try {
request.WalletAddress = wallet;
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_ETH_GetOutTransactionCount + "\", \"params\":[\"" + wallet + "\", \"latest\"] }");
} catch (JSONException e) {
e.printStackTrace();
request.error = e.toString();
}
return request;
}
public static InfuraRequest GetPendingTransactionCount(String wallet) {
InfuraRequest request = new InfuraRequest();
try {
request.WalletAddress = wallet;
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_ETH_GetOutTransactionCount + "\", \"params\":[\"" + wallet + "\", \"pending\"] }");
} catch (JSONException e) {
e.printStackTrace();
request.error = e.toString();
}
return request;
}
public static InfuraRequest GetGasPrise(String wallet) {
InfuraRequest request = new InfuraRequest();
try {
request.WalletAddress = wallet;
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_ETH_GetGasPrice + "\", \"params\":[] }");
} catch (JSONException e) {
e.printStackTrace();
request.error = e.toString();
}
return request;
}
public static InfuraRequest SendTransactionCount(String wallet, String TX) {
InfuraRequest request = new InfuraRequest();
try {
request.WalletAddress = wallet;
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_ETH_SendRawTransaction + "\", \"params\":[\"" + TX + "\"] }");
} catch (JSONException e) {
e.printStackTrace();
request.error = e.toString();
}
return request;
}
//METHOD_ETH_GetOutTransactionCount
public JSONArray getParams() throws JSONException {
return jsRequestData.getJSONArray("params");
}
public JSONObject getResult() throws JSONException {
return getAnswer().getJSONObject("result");
}
public String getResultString() throws JSONException {
return getAnswer().getString("result");
}
public JSONArray getResultArray() throws JSONException {
return getAnswer().getJSONArray("result");
}
}

View file

@ -1,191 +0,0 @@
package com.tangem.data.network.request;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.tangem.domain.wallet.TangemCard;
import com.tangem.util.Util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.lang.reflect.Type;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;
public class VerificationServerProtocol {
public static class Request {
public Request(CustomCommand command, Class answerClass) {
this.command = command;
this.answerClass = answerClass;
}
public String error;
public CustomCommand command;
public CustomAnswer answer;
public Type answerClass;
public void doPost(String hostURL) throws IOException {
URL url = new URL(hostURL + "/" + command.getURL());
Log.i("isOnlineVerified", hostURL + "/" + command.getURL());
URLConnection con = url.openConnection();
HttpURLConnection http = (HttpURLConnection) con;
try {
http.setConnectTimeout(30000);
http.setReadTimeout(30000);
http.setRequestMethod("POST"); // PUT is another valid option
http.setDoOutput(true);
String sRequestBody = getGson().toJson(this.command);
byte[] out = sRequestBody.getBytes(StandardCharsets.UTF_8);
int length = out.length;
http.setFixedLengthStreamingMode(length);
http.setRequestProperty("Content-Type", "application/json");
http.connect();
try (OutputStream os = http.getOutputStream()) {
os.write(out);
}
try (InputStream is = http.getInputStream()) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
answer = getGson().fromJson(br, answerClass);
}
}
} finally {
http.disconnect();
}
}
}
static abstract class CustomCommand {
public abstract String getURL();
public byte[] toBytes() {
return getGson().toJson(this).getBytes(StandardCharsets.UTF_8);
}
@Override
public String toString() {
return getGson().toJson(this);
}
}
static class CustomAnswer {
public String error;
@Override
public String toString() {
return getGson().toJson(this);
}
}
public static class Verify {
static class RequestItem {
public String CID;
public String publicKey;
}
static class Command extends CustomCommand {
public RequestItem[] requests;
@Override
public String getURL() {
return "verify";
}
}
public static class ResultItem {
public ResultItem(RequestItem request) {
CID = request.CID;
}
public String error;
public String CID;
public Boolean passed;
}
public static class Answer extends CustomAnswer {
public ResultItem[] results;
}
public static Request prepare(TangemCard card) {
Command c = new Command();
c.requests = new RequestItem[1];
c.requests[0] = new RequestItem();
c.requests[0].CID = Util.bytesToHex(card.getCID());
c.requests[0].publicKey = Util.bytesToHex(card.getCardPublicKey());
return new Request(c, Answer.class);
}
}
public static class Validate {
static class RequestItem {
public String CID;
public int counter;
public String signature;
}
static class Command extends CustomCommand {
public RequestItem[] requests;
@Override
public String getURL() {
return "validate";
}
}
static class ResultItem {
public ResultItem(RequestItem request) {
CID = request.CID;
}
public String error;
public String CID;
public Integer previousCounter;
public Boolean passed;
}
static class Answer extends CustomAnswer {
public ResultItem[] results;
}
public Request prepare(TangemCard card, int ValidationCounter, byte[] ValidationSignature) {
Command c = new Command();
c.requests = new RequestItem[1];
c.requests[0].CID = Util.bytesToHex(card.getCID());
c.requests[0].counter = ValidationCounter;
c.requests[0].signature = Util.bytesToHex(ValidationSignature);
return new Request(new Command(), Answer.class);
}
}
public static Date strToDate(String date) throws ParseException {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
return new Date(formatter.parse(date).getTime());
}
public static String dateToStr(Date date) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
return formatter.format(date);
}
public static Gson getGson() {
return new GsonBuilder().create();
}
}