Updated on 2026-08-14
This commit is contained in:
parent
61c4f7047d
commit
52ce16bb09
86 changed files with 9207 additions and 9295 deletions
|
|
@ -8,7 +8,7 @@ import org.json.JSONObject;
|
|||
* Created by dvol on 16.07.2017.
|
||||
*/
|
||||
|
||||
public class Electrum_Request {
|
||||
public class ElectrumRequest {
|
||||
public static final String METHOD_GetBalance = "blockchain.address.get_balance";
|
||||
public static final String METHOD_ListUnspent = "blockchain.address.listunspent";
|
||||
public static final String METHOD_GetHistory = "blockchain.address.get_history";
|
||||
|
|
@ -25,10 +25,10 @@ public class Electrum_Request {
|
|||
public String Host;
|
||||
public int Port;
|
||||
|
||||
private Electrum_Request() {
|
||||
private ElectrumRequest() {
|
||||
}
|
||||
|
||||
public Electrum_Request(JSONObject jsRequest) {
|
||||
public ElectrumRequest(JSONObject jsRequest) {
|
||||
try {
|
||||
jsRequestData = new JSONObject(jsRequest.toString());
|
||||
} catch (JSONException e) {
|
||||
|
|
@ -70,8 +70,8 @@ public class Electrum_Request {
|
|||
}
|
||||
}
|
||||
|
||||
public static Electrum_Request CheckBalance(String wallet) {
|
||||
Electrum_Request request = new Electrum_Request();
|
||||
public static ElectrumRequest CheckBalance(String wallet) {
|
||||
ElectrumRequest request = new ElectrumRequest();
|
||||
try {
|
||||
request.WalletAddress=wallet;
|
||||
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_GetBalance + "\", \"params\":[\"" + wallet + "\"] }");
|
||||
|
|
@ -83,8 +83,8 @@ public class Electrum_Request {
|
|||
}
|
||||
|
||||
|
||||
public static Electrum_Request GetFee(String wallet) {
|
||||
Electrum_Request request = new Electrum_Request();
|
||||
public static ElectrumRequest GetFee(String wallet) {
|
||||
ElectrumRequest request = new ElectrumRequest();
|
||||
try{
|
||||
request.WalletAddress = wallet; //METHOD_GetFee
|
||||
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_GetFee + "\", \"params\":[\"" + 6 + "\"] }");
|
||||
|
|
@ -97,8 +97,8 @@ public class Electrum_Request {
|
|||
return request;
|
||||
}
|
||||
|
||||
public static Electrum_Request GetHeader(String wallet, String height) {
|
||||
Electrum_Request request = new Electrum_Request();
|
||||
public static ElectrumRequest GetHeader(String wallet, String height) {
|
||||
ElectrumRequest request = new ElectrumRequest();
|
||||
try {
|
||||
request.WalletAddress=wallet;
|
||||
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_GetHeader + "\", \"params\":[\"" + height + "\"] }");
|
||||
|
|
@ -109,8 +109,8 @@ public class Electrum_Request {
|
|||
return request;
|
||||
}
|
||||
|
||||
public static Electrum_Request ListUnspent(String wallet) {
|
||||
Electrum_Request request = new Electrum_Request();
|
||||
public static ElectrumRequest ListUnspent(String wallet) {
|
||||
ElectrumRequest request = new ElectrumRequest();
|
||||
try {
|
||||
request.WalletAddress=wallet;
|
||||
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_ListUnspent + "\", \"params\":[\"" + wallet + "\"] }");
|
||||
|
|
@ -121,8 +121,8 @@ public class Electrum_Request {
|
|||
return request;
|
||||
}
|
||||
|
||||
public static Electrum_Request Broadcast(String wallet, String tx) {
|
||||
Electrum_Request request = new Electrum_Request();
|
||||
public static ElectrumRequest Broadcast(String wallet, String tx) {
|
||||
ElectrumRequest request = new ElectrumRequest();
|
||||
try {
|
||||
request.WalletAddress=wallet;
|
||||
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_SendTransaction + "\", \"params\":[\"" + tx + "\"] }");
|
||||
|
|
@ -133,8 +133,8 @@ public class Electrum_Request {
|
|||
return request;
|
||||
}
|
||||
|
||||
public static Electrum_Request ListHistory(String wallet) {
|
||||
Electrum_Request request = new Electrum_Request();
|
||||
public static ElectrumRequest ListHistory(String wallet) {
|
||||
ElectrumRequest request = new ElectrumRequest();
|
||||
try {
|
||||
request.WalletAddress=wallet;
|
||||
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_GetHistory + "\", \"params\":[\"" + wallet + "\"] }");
|
||||
|
|
@ -145,8 +145,8 @@ public class Electrum_Request {
|
|||
return request;
|
||||
}
|
||||
|
||||
public static Electrum_Request GetTransaction(String wallet, String tx_hash) {
|
||||
Electrum_Request request = new Electrum_Request();
|
||||
public static ElectrumRequest GetTransaction(String wallet, String tx_hash) {
|
||||
ElectrumRequest request = new ElectrumRequest();
|
||||
try {
|
||||
request.WalletAddress=wallet;
|
||||
request.TxHash = tx_hash;
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
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");
|
||||
}
|
||||
}
|
||||
|
|
@ -3,8 +3,8 @@ package com.tangem.data.network.task;
|
|||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import com.tangem.data.network.request.Electrum_Request;
|
||||
import com.tangem.wallet.SharedData;
|
||||
import com.tangem.data.network.request.ElectrumRequest;
|
||||
import com.tangem.domain.wallet.SharedData;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
|
|
@ -20,7 +20,7 @@ import java.util.List;
|
|||
* Created by dvol on 16.07.2017.
|
||||
*/
|
||||
|
||||
public class Electrum_Task extends AsyncTask<Electrum_Request, Integer, List<Electrum_Request>> {
|
||||
public class ElectrumTask extends AsyncTask<ElectrumRequest, Integer, List<ElectrumRequest>> {
|
||||
public static final String logTag = "Electrum";
|
||||
//public static final String Host = /*"hsmiths.changeip.net";*/ "testnetnode.arihanc.com";
|
||||
//public static final int Port = /*8080*/51001;
|
||||
|
|
@ -33,13 +33,13 @@ public class Electrum_Task extends AsyncTask<Electrum_Request, Integer, List<Ele
|
|||
public SharedData sharedCounter = null;
|
||||
|
||||
|
||||
public Electrum_Task(String host, int port) {
|
||||
public ElectrumTask(String host, int port) {
|
||||
super();
|
||||
Host = host;
|
||||
Port = port;
|
||||
}
|
||||
|
||||
public Electrum_Task(String host, int port, SharedData sharedCounter) {
|
||||
public ElectrumTask(String host, int port, SharedData sharedCounter) {
|
||||
super();
|
||||
Host = host;
|
||||
Port = port;
|
||||
|
|
@ -47,8 +47,8 @@ public class Electrum_Task extends AsyncTask<Electrum_Request, Integer, List<Ele
|
|||
}
|
||||
|
||||
@Override
|
||||
protected List<Electrum_Request> doInBackground(Electrum_Request... requests) {
|
||||
List<Electrum_Request> result = new ArrayList<>();
|
||||
protected List<ElectrumRequest> doInBackground(ElectrumRequest... requests) {
|
||||
List<ElectrumRequest> result = new ArrayList<>();
|
||||
for (int i = 0; i < requests.length; i++) {
|
||||
result.add(requests[i]);
|
||||
}
|
||||
|
|
@ -89,7 +89,7 @@ public class Electrum_Task extends AsyncTask<Electrum_Request, Integer, List<Ele
|
|||
return result;
|
||||
}
|
||||
|
||||
private void doRequest(Electrum_Request request) {
|
||||
private void doRequest(ElectrumRequest request) {
|
||||
try {
|
||||
|
||||
Log.v(logTag, "<< " + request.getAsString());
|
||||
|
|
@ -2,8 +2,8 @@ package com.tangem.data.network.task;
|
|||
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import com.tangem.wallet.Fee_Request;
|
||||
import com.tangem.wallet.SharedData;
|
||||
import com.tangem.data.network.request.FeeRequest;
|
||||
import com.tangem.domain.wallet.SharedData;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
|
|
@ -16,21 +16,21 @@ import java.util.List;
|
|||
* Created by Ilia on 04.12.2017.
|
||||
*/
|
||||
|
||||
public class Fee_Task extends AsyncTask<Fee_Request, Void, List<Fee_Request>> {
|
||||
public class FeeTask extends AsyncTask<FeeRequest, Void, List<FeeRequest>> {
|
||||
|
||||
public SharedData sharedCounter = null;
|
||||
|
||||
public Fee_Task(SharedData sharedData)
|
||||
public FeeTask(SharedData sharedData)
|
||||
{
|
||||
sharedCounter = sharedData;
|
||||
}
|
||||
protected List<Fee_Request> doInBackground(Fee_Request... requests) {
|
||||
List<Fee_Request> result = new ArrayList<>();
|
||||
protected List<FeeRequest> doInBackground(FeeRequest... requests) {
|
||||
List<FeeRequest> result = new ArrayList<>();
|
||||
for (int i = 0; i < requests.length; i++) {
|
||||
result.add(requests[i]);
|
||||
}
|
||||
|
||||
for (Fee_Request request: result)
|
||||
for (FeeRequest request: result)
|
||||
{
|
||||
HttpURLConnection httpcon = null;
|
||||
|
||||
|
|
@ -6,8 +6,8 @@ package com.tangem.data.network.task;
|
|||
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import com.tangem.wallet.Blockchain;
|
||||
import com.tangem.wallet.Infura_Request;
|
||||
import com.tangem.domain.wallet.Blockchain;
|
||||
import com.tangem.domain.wallet.Infura_Request;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
|
|
@ -25,10 +25,10 @@ import javax.net.ssl.HttpsURLConnection;
|
|||
* Created by Ilia on 04.12.2017.
|
||||
*/
|
||||
|
||||
public class Infura_Task extends AsyncTask<Infura_Request, Void, List<Infura_Request>> {
|
||||
public class InfuraTask extends AsyncTask<Infura_Request, Void, List<Infura_Request>> {
|
||||
private Exception exception;
|
||||
private Blockchain blockchain;
|
||||
public Infura_Task(Blockchain blockchainNet)
|
||||
public InfuraTask(Blockchain blockchainNet)
|
||||
{
|
||||
blockchain = blockchainNet;
|
||||
}
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
package com.tangem.data.network.task;
|
||||
|
||||
import android.content.Context;
|
||||
import android.nfc.tech.IsoDep;
|
||||
import android.util.Log;
|
||||
|
||||
import com.tangem.domain.cardReader.CardProtocol;
|
||||
import com.tangem.domain.cardReader.NfcManager;
|
||||
import com.tangem.domain.wallet.PINStorage;
|
||||
import com.tangem.domain.wallet.TangemCard;
|
||||
|
||||
/**
|
||||
* Created by dvol on 04.02.2018.
|
||||
*/
|
||||
|
||||
public class VerifyCardTask extends Thread {
|
||||
|
||||
IsoDep mIsoDep;
|
||||
CardProtocol.Notifications mNotifications;
|
||||
private final String logTag = "VerifyCardTask";
|
||||
private boolean isCancelled = false;
|
||||
private Context mContext;
|
||||
private TangemCard mCard;
|
||||
private NfcManager mNfcManager;
|
||||
|
||||
public VerifyCardTask(Context context, TangemCard card, NfcManager nfcManager, IsoDep isoDep, CardProtocol.Notifications notifications) {
|
||||
mCard = card;
|
||||
mContext = context;
|
||||
mIsoDep = isoDep;
|
||||
mNotifications = notifications;
|
||||
mNfcManager = nfcManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (mIsoDep == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// for Samsung's bugs -
|
||||
// Workaround for the Samsung Galaxy S5 (since the
|
||||
// first connection always hangs on transceive).
|
||||
int timeout = mIsoDep.getTimeout();
|
||||
mIsoDep.connect();
|
||||
mIsoDep.close();
|
||||
mIsoDep.connect();
|
||||
mIsoDep.setTimeout(timeout);
|
||||
try {
|
||||
CardProtocol protocol = new CardProtocol(mContext, mIsoDep, mCard, mNotifications);
|
||||
mNotifications.OnReadStart(protocol);
|
||||
try {
|
||||
mNotifications.OnReadProgress(protocol, 5);
|
||||
|
||||
Log.i("VerifyCardTask", "[-- Start verify card --]");
|
||||
|
||||
if (isCancelled) return;
|
||||
|
||||
String PIN = mCard.getPIN();
|
||||
protocol.setPIN(PIN);
|
||||
protocol.run_Read();
|
||||
PINStorage.setLastUsedPIN(PIN);
|
||||
mNotifications.OnReadProgress(protocol, 30);
|
||||
if (isCancelled) return;
|
||||
protocol.run_VerifyCard();
|
||||
mNotifications.OnReadProgress(protocol, 60);
|
||||
Log.i("VerifyCardTask", "Manufacturer: " + protocol.getCard().getManufacturer().getOfficialName());
|
||||
if (isCancelled) return;
|
||||
if (protocol.getCard().getStatus() == TangemCard.Status.Loaded) {
|
||||
protocol.run_CheckWalletWithSignatureVerify();
|
||||
mNotifications.OnReadProgress(protocol, 90);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// if (isCancelled) return;
|
||||
// if (protocol.getCard().getStatus() == TangemCard.Status.Loaded) {
|
||||
// protocol.run_CheckWithSignatureVerify();
|
||||
// }
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
protocol.setError(e);
|
||||
|
||||
} finally {
|
||||
Log.i("VerifyCardTask", "[-- Finish verify card --]");
|
||||
mNotifications.OnReadFinish(protocol);
|
||||
}
|
||||
} finally {
|
||||
mNfcManager.IgnoreTag(mIsoDep.getTag());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
void cancel(Boolean AllowInterrupt) {
|
||||
try {
|
||||
if (this.isAlive()) {
|
||||
isCancelled = true;
|
||||
join(500);
|
||||
}
|
||||
if (this.isAlive() && AllowInterrupt) {
|
||||
interrupt();
|
||||
mNotifications.OnReadCancel();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue