Updated on 2026-08-14
This commit is contained in:
parent
5f3d316ab7
commit
c0826690b6
5 changed files with 96 additions and 2 deletions
|
|
@ -39,6 +39,7 @@ public class Server {
|
|||
public static class Method {
|
||||
public static final String ADDRESS_BALANCE = "api/v2/get_address_balance/{network}/{address}";
|
||||
public static final String UNSPENT_TX = "api/v2/get_tx_unspent/{network}/{address}";
|
||||
public static final String GET_TX = "api/v2/get_tx/{network}/{txid}";
|
||||
public static final String SEND_TRANSACTION = "api/v2/send_tx/{network}";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ public class ServerApiSoChain {
|
|||
return requestsCount <= 0;
|
||||
}
|
||||
|
||||
|
||||
public interface AddressInfoListener {
|
||||
void onSuccess(SoChain.Response.AddressBalance response);
|
||||
|
||||
|
|
@ -50,6 +51,20 @@ public class ServerApiSoChain {
|
|||
sendTxListener = listener;
|
||||
}
|
||||
|
||||
|
||||
public interface TransactionInfoListener {
|
||||
void onSuccess(SoChain.Response.GetTx response);
|
||||
|
||||
void onFail(String message);
|
||||
}
|
||||
|
||||
private TransactionInfoListener txInfoListener;
|
||||
|
||||
public void setTransactionInfoListener(TransactionInfoListener listener) {
|
||||
txInfoListener=listener;
|
||||
}
|
||||
|
||||
|
||||
private String getNetwork(Blockchain blockchain) throws Exception {
|
||||
switch (blockchain) {
|
||||
case Bitcoin:
|
||||
|
|
@ -140,4 +155,29 @@ public class ServerApiSoChain {
|
|||
});
|
||||
}
|
||||
|
||||
public void requestTransactionInfo(Blockchain blockchain, String txId) throws Exception {
|
||||
requestsCount++;
|
||||
SoChainApi api = App.Companion.getNetworkComponent().getRetrofitSoChain().create(SoChainApi.class);
|
||||
|
||||
Call<SoChain.Response.GetTx> call = api.getTx(getNetwork(blockchain), txId);
|
||||
call.enqueue(new Callback<SoChain.Response.GetTx>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SoChain.Response.GetTx> call, @NonNull Response<SoChain.Response.GetTx> response) {
|
||||
Log.i(TAG, "requestAddressBalance onResponse " + response.code());
|
||||
if (response.code() == 200) {
|
||||
requestsCount--;
|
||||
txInfoListener.onSuccess(response.body());
|
||||
} else {
|
||||
txInfoListener.onFail(String.valueOf(response.code()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<SoChain.Response.GetTx> call, @NonNull Throwable t) {
|
||||
Log.e(TAG, "requestAddressBalance onFailure " + t.getMessage());
|
||||
txInfoListener.onFail(String.valueOf(t.getMessage()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@ public interface SoChainApi {
|
|||
@GET(Server.ApiSoChain.Method.UNSPENT_TX)
|
||||
Call<SoChain.Response.TxUnspent> getUnspentTx(@Path("network") String network, @Path("address") String address);
|
||||
|
||||
@GET(Server.ApiSoChain.Method.GET_TX)
|
||||
Call<SoChain.Response.GetTx> getTx(@Path("network") String network, @Path("txid") String txId);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST(Server.ApiSoChain.Method.SEND_TRANSACTION)
|
||||
Call<SoChain.Response.SendTx> sendTransaction(@Path("network") String network, @Body SoChain.Request.SendTx body);
|
||||
|
|
|
|||
|
|
@ -52,5 +52,19 @@ class SoChain {
|
|||
var status: String? = null
|
||||
var data: Data? = null
|
||||
}
|
||||
|
||||
class GetTx {
|
||||
class Data {
|
||||
// restricted data
|
||||
var network: String? = null
|
||||
var address: String? = null
|
||||
var txid: String? = null
|
||||
var tx_hex: String? = null
|
||||
}
|
||||
|
||||
var status: String? = null
|
||||
var data: Data? = null
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -758,7 +758,7 @@ public class BtcEngine extends CoinEngine {
|
|||
Log.i(TAG, "onSuccess: " + electrumRequest.getMethod());
|
||||
try {
|
||||
if (electrumRequest.getResultString() != null) {
|
||||
App.pendingTransactionsStorage.removeTransaction(ctx.getCard(), electrumRequest.txHash);
|
||||
App.pendingTransactionsStorage.removeTransaction(ctx.getCard(), electrumRequest.txHash); //TODO Need remove transaction by RAW HEX
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
|
@ -789,7 +789,43 @@ public class BtcEngine extends CoinEngine {
|
|||
serverApiElectrum.requestData(ctx, ElectrumRequest.getTransaction(ctx.getCoinData().getWallet(), txHash));
|
||||
}
|
||||
} else {
|
||||
throw new Exception("Not supported!");
|
||||
ServerApiSoChain serverApi = new ServerApiSoChain();
|
||||
|
||||
ServerApiSoChain.TransactionInfoListener listener = new ServerApiSoChain.TransactionInfoListener() {
|
||||
@Override
|
||||
public void onSuccess(SoChain.Response.GetTx response) {
|
||||
Log.i(TAG, "onSuccess: GetTx");
|
||||
try {
|
||||
if (response.getData() != null && response.getData().getTx_hex() != null && response.getData().getTxid() != null) {
|
||||
App.pendingTransactionsStorage.removeTransaction(ctx.getCard(), response.getData().getTx_hex());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "onFail: GetTx" + response);
|
||||
}
|
||||
if (serverApi.isRequestsSequenceCompleted()) {
|
||||
blockchainRequestsCallbacks.onComplete(!ctx.hasError());
|
||||
} else {
|
||||
blockchainRequestsCallbacks.onProgress();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String message) {
|
||||
Log.i(TAG, "onFail: GetTx " + message);
|
||||
if (serverApi.isRequestsSequenceCompleted()) {
|
||||
blockchainRequestsCallbacks.onComplete(false);//serverApiElectrum.isErrorOccurred(), serverApiElectrum.getError());
|
||||
} else {
|
||||
blockchainRequestsCallbacks.onProgress();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
serverApi.setTransactionInfoListener(listener);
|
||||
for (PendingTransactionsStorage.TransactionInfo pendingTx : App.pendingTransactionsStorage.getTransactions(ctx.getCard()).getTransactions()) {
|
||||
String txId = BTCUtils.toHex(BTCUtils.reverse(CryptoUtil.doubleSha256(BTCUtils.fromHex(pendingTx.getTx()))));
|
||||
serverApi.requestTransactionInfo(ctx.getBlockchain(), txId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue