Updated on 2026-08-14

This commit is contained in:
Tangem 2019-04-18 00:20:24 +03:00
parent 6fd870bc9a
commit 5f3d316ab7
10 changed files with 230 additions and 105 deletions

View file

@ -1,29 +0,0 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<Objective-C-extensions>
<file>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
</file>
<class>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
</class>
<extensions>
<pair source="cpp" header="h" fileNamingConvention="NONE" />
<pair source="c" header="h" fileNamingConvention="NONE" />
</extensions>
</Objective-C-extensions>
</code_scheme>
</component>

View file

@ -5,7 +5,7 @@ apply plugin: 'kotlin-kapt'
static def generateVersionName() {
def gitCommitsCount = "git rev-list HEAD --count".execute().text.trim()
def gitCurrentBranch = "git rev-parse --abbrev-ref HEAD".execute().text.trim()
// def gitCurrentBranch = "git rev-parse --abbrev-ref HEAD".execute().text.trim()
return gitCommitsCount.toInteger() + 831// + "\\n" + gitCurrentBranch
}

View file

@ -24,9 +24,7 @@ public class ServerApiSoChain {
return requestsCount <= 0;
}
private ResponseListener responseListener;
public interface ResponseListener {
public interface AddressInfoListener {
void onSuccess(SoChain.Response.AddressBalance response);
void onSuccess(SoChain.Response.TxUnspent response);
@ -34,8 +32,22 @@ public class ServerApiSoChain {
void onFail(String message);
}
public void setResponseListener(ResponseListener listener) {
responseListener = listener;
private AddressInfoListener addressInfoListener;
public void setAddressInfoListener(AddressInfoListener listener) {
addressInfoListener = listener;
}
public interface SendTxListener {
void onSuccess(SoChain.Response.SendTx response);
void onFail(String message);
}
private SendTxListener sendTxListener;
public void setSendTxListener(SendTxListener listener) {
sendTxListener = listener;
}
private String getNetwork(Blockchain blockchain) throws Exception {
@ -62,16 +74,16 @@ public class ServerApiSoChain {
Log.i(TAG, "requestAddressBalance onResponse " + response.code());
if (response.code() == 200) {
requestsCount--;
responseListener.onSuccess(response.body());
addressInfoListener.onSuccess(response.body());
} else {
responseListener.onFail(String.valueOf(response.code()));
addressInfoListener.onFail(String.valueOf(response.code()));
}
}
@Override
public void onFailure(@NonNull Call<SoChain.Response.AddressBalance> call, @NonNull Throwable t) {
Log.e(TAG, "requestAddressBalance onFailure " + t.getMessage());
responseListener.onFail(String.valueOf(t.getMessage()));
addressInfoListener.onFail(String.valueOf(t.getMessage()));
}
});
}
@ -87,16 +99,43 @@ public class ServerApiSoChain {
Log.i(TAG, "requestAddressBalance onResponse " + response.code());
if (response.code() == 200) {
requestsCount--;
responseListener.onSuccess(response.body());
addressInfoListener.onSuccess(response.body());
} else {
responseListener.onFail(String.valueOf(response.code()));
addressInfoListener.onFail(String.valueOf(response.code()));
}
}
@Override
public void onFailure(@NonNull Call<SoChain.Response.TxUnspent> call, @NonNull Throwable t) {
Log.e(TAG, "requestAddressBalance onFailure " + t.getMessage());
responseListener.onFail(String.valueOf(t.getMessage()));
addressInfoListener.onFail(String.valueOf(t.getMessage()));
}
});
}
public void requestSendTransaction(Blockchain blockchain, String txHEX) throws Exception {
requestsCount++;
SoChainApi api = App.Companion.getNetworkComponent().getRetrofitSoChain().create(SoChainApi.class);
SoChain.Request.SendTx tx=new SoChain.Request.SendTx();
tx.setTx_hex(txHEX);
Call<SoChain.Response.SendTx> call = api.sendTransaction(getNetwork(blockchain), tx);
call.enqueue(new Callback<SoChain.Response.SendTx>() {
@Override
public void onResponse(@NonNull Call<SoChain.Response.SendTx> call, @NonNull Response<SoChain.Response.SendTx> response) {
Log.i(TAG, "requestAddressBalance onResponse " + response.code());
if (response.code() == 200) {
requestsCount--;
sendTxListener.onSuccess(response.body());
} else {
sendTxListener.onFail(String.valueOf(response.code()));
}
}
@Override
public void onFailure(@NonNull Call<SoChain.Response.SendTx> call, @NonNull Throwable t) {
Log.e(TAG, "requestAddressBalance onFailure " + t.getMessage());
sendTxListener.onFail(String.valueOf(t.getMessage()));
}
});
}

View file

@ -19,5 +19,5 @@ public interface SoChainApi {
@Headers("Content-Type: application/json")
@POST(Server.ApiSoChain.Method.SEND_TRANSACTION)
Call<SoChain.Response> sendTransaction(@Path("network") String network, @Body SoChain.Request.SendTx body);
Call<SoChain.Response.SendTx> sendTransaction(@Path("network") String network, @Body SoChain.Request.SendTx body);
}

View file

@ -42,5 +42,15 @@ class SoChain {
var data: Data? = null
}
class SendTx {
class Data {
var network: String? = null
var txid: String? = null
var tx_hex: String? = null
}
var status: String? = null
var data: Data? = null
}
}
}

View file

@ -13,6 +13,7 @@ import com.tangem.data.Blockchain;
import com.tangem.data.local.PendingTransactionsStorage;
import com.tangem.data.network.ElectrumRequest;
import com.tangem.data.network.Server;
import com.tangem.data.network.ServerApiCommon;
import com.tangem.data.network.ServerApiElectrum;
import com.tangem.data.network.ServerApiSoChain;
import com.tangem.data.network.model.SoChain;
@ -639,7 +640,7 @@ public class BtcEngine extends CoinEngine {
} else {
final ServerApiSoChain serverApi = new ServerApiSoChain();
ServerApiSoChain.ResponseListener responseListener = new ServerApiSoChain.ResponseListener() {
ServerApiSoChain.AddressInfoListener addressInfoListener = new ServerApiSoChain.AddressInfoListener() {
@Override
public void onSuccess(SoChain.Response.AddressBalance response) {
try {
@ -738,7 +739,7 @@ public class BtcEngine extends CoinEngine {
};
serverApi.setResponseListener(responseListener);
serverApi.setAddressInfoListener(addressInfoListener);
serverApi.requestAddressBalance(ctx.getBlockchain(), coinData.getWallet());
serverApi.requestUnspentTx(ctx.getBlockchain(), coinData.getWallet());
@ -888,71 +889,177 @@ public class BtcEngine extends CoinEngine {
coinData.maxFee = null;
coinData.normalFee = null;
final ServerApiElectrum serverApiElectrum = new ServerApiElectrum();
if (useElectrum) {
final ServerApiElectrum.ResponseListener electrumListener = new ServerApiElectrum.ResponseListener() {
@Override
public void onSuccess(ElectrumRequest electrumRequest) {
BigDecimal kbFee;
if (electrumRequest.isMethod(ElectrumRequest.METHOD_GetFee)) {
try {
kbFee = new BigDecimal(electrumRequest.getResultString()); //fee per KB
final ServerApiElectrum serverApiElectrum = new ServerApiElectrum();
if (kbFee.equals(BigDecimal.ZERO)) {
serverApiElectrum.requestData(ctx, ElectrumRequest.getFee());
}
final ServerApiElectrum.ResponseListener electrumListener = new ServerApiElectrum.ResponseListener() {
@Override
public void onSuccess(ElectrumRequest electrumRequest) {
BigDecimal kbFee;
if (electrumRequest.isMethod(ElectrumRequest.METHOD_GetFee)) {
try {
kbFee = new BigDecimal(electrumRequest.getResultString()); //fee per KB
BigDecimal minByteFee = kbFee.divide(new BigDecimal(1024)); // per KB -> per byte
BigDecimal normalByteFee = minByteFee.add(new BigDecimal(0.00000010));
BigDecimal maxByteFee = minByteFee.add(new BigDecimal(0.00000025));
if (kbFee.equals(BigDecimal.ZERO)) {
serverApiElectrum.requestData(ctx, ElectrumRequest.getFee());
}
BigDecimal minFee = minByteFee.multiply(new BigDecimal(calcSize)).setScale(8, RoundingMode.DOWN);
BigDecimal normalFee = normalByteFee.multiply(new BigDecimal(calcSize)).setScale(8, RoundingMode.DOWN);
BigDecimal maxFee = maxByteFee.multiply(new BigDecimal(calcSize)).setScale(8, RoundingMode.DOWN);
BigDecimal minByteFee = kbFee.divide(new BigDecimal(1024)); // per KB -> per byte
BigDecimal normalByteFee = minByteFee.add(new BigDecimal(0.00000010));
BigDecimal maxByteFee = minByteFee.add(new BigDecimal(0.00000025));
CoinEngine.Amount minAmount = new CoinEngine.Amount(minFee, ctx.getBlockchain().getCurrency());
CoinEngine.Amount normalAmount = new CoinEngine.Amount(normalFee, ctx.getBlockchain().getCurrency());
CoinEngine.Amount maxAmount = new CoinEngine.Amount(maxFee, ctx.getBlockchain().getCurrency());
BigDecimal minFee = minByteFee.multiply(new BigDecimal(calcSize)).setScale(8, RoundingMode.DOWN);
BigDecimal normalFee = normalByteFee.multiply(new BigDecimal(calcSize)).setScale(8, RoundingMode.DOWN);
BigDecimal maxFee = maxByteFee.multiply(new BigDecimal(calcSize)).setScale(8, RoundingMode.DOWN);
coinData.minFee = minAmount;
coinData.normalFee = normalAmount;
coinData.maxFee = maxAmount;
CoinEngine.Amount minAmount = new CoinEngine.Amount(minFee, ctx.getBlockchain().getCurrency());
CoinEngine.Amount normalAmount = new CoinEngine.Amount(normalFee, ctx.getBlockchain().getCurrency());
CoinEngine.Amount maxAmount = new CoinEngine.Amount(maxFee, ctx.getBlockchain().getCurrency());
coinData.minFee = minAmount;
coinData.normalFee = normalAmount;
coinData.maxFee = maxAmount;
// if (coinData.minFee != null && coinData.normalFee != null && coinData.maxFee != null) {
blockchainRequestsCallbacks.onComplete(true);
blockchainRequestsCallbacks.onComplete(true);
// } else {
// blockchainRequestsCallbacks.onProgress();
// }
} catch (JSONException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
@Override
public void onFail(ElectrumRequest electrumRequest) {
ctx.setError(electrumRequest.getError());
blockchainRequestsCallbacks.onComplete(false);
}
};
serverApiElectrum.setResponseListener(electrumListener);
@Override
public void onFail(ElectrumRequest electrumRequest) {
ctx.setError(electrumRequest.getError());
blockchainRequestsCallbacks.onComplete(false);
}
};
serverApiElectrum.setResponseListener(electrumListener);
serverApiElectrum.requestData(ctx, ElectrumRequest.getFee());
serverApiElectrum.requestData(ctx, ElectrumRequest.getFee());
} else {
final ServerApiCommon serverApiCommon = new ServerApiCommon();
final ServerApiCommon.EstimatedFeeListener estimatedFeeListener = new ServerApiCommon.EstimatedFeeListener() {
@Override
public void onSuccess(int blockCount, String estimateFeeResponse) {
BigDecimal fee = new BigDecimal(estimateFeeResponse); // BTC per 1 kb
if (fee.equals(BigDecimal.ZERO)) {
if (blockchainRequestsCallbacks.allowAdvance()) {
serverApiCommon.requestBtcEstimatedFee(blockCount);
}
return;
}
if (calcSize != 0) {
fee = fee.multiply(new BigDecimal(calcSize)).divide(new BigDecimal(1024), BigDecimal.ROUND_DOWN); // per Kb -> per byte
} else {
if (blockchainRequestsCallbacks.allowAdvance()) {
serverApiCommon.requestBtcEstimatedFee(blockCount);
}
return;
}
fee = fee.setScale(8, RoundingMode.DOWN);
switch (blockCount) {
case ServerApiCommon.ESTIMATE_FEE_MINIMAL:
coinData.minFee = new CoinEngine.Amount(fee, getFeeCurrency());
break;
case ServerApiCommon.ESTIMATE_FEE_NORMAL:
coinData.normalFee = new CoinEngine.Amount(fee, getFeeCurrency());
break;
case ServerApiCommon.ESTIMATE_FEE_PRIORITY:
coinData.maxFee = new CoinEngine.Amount(fee, getFeeCurrency());
break;
}
if (coinData.minFee != null && coinData.normalFee != null && coinData.maxFee != null) {
blockchainRequestsCallbacks.onComplete(true);
} else {
blockchainRequestsCallbacks.onProgress();
}
}
@Override
public void onFail(int blockCount, String message) {
// TODO - add fail counter to terminate after NNN tries
if (blockchainRequestsCallbacks.allowAdvance()) {
serverApiCommon.requestBtcEstimatedFee(blockCount);
return;
}
ctx.setError(ctx.getContext().getString(R.string.cannot_calculate_fee_wrong_data_received_from_node));
blockchainRequestsCallbacks.onComplete(false);
}
};
serverApiCommon.setBtcEstimatedFeeListener(estimatedFeeListener);
serverApiCommon.requestBtcEstimatedFee(ServerApiCommon.ESTIMATE_FEE_PRIORITY);
serverApiCommon.requestBtcEstimatedFee(ServerApiCommon.ESTIMATE_FEE_NORMAL);
serverApiCommon.requestBtcEstimatedFee(ServerApiCommon.ESTIMATE_FEE_MINIMAL);
}
}
@Override
public void requestSendTransaction(BlockchainRequestsCallbacks blockchainRequestsCallbacks, byte[] txForSend) {
final ServerApiElectrum serverApiElectrum = new ServerApiElectrum();
public void requestSendTransaction(BlockchainRequestsCallbacks blockchainRequestsCallbacks, byte[] txForSend) throws Exception {
final String txStr = BTCUtils.toHex(txForSend);
if (useElectrum) {
final ServerApiElectrum serverApiElectrum = new ServerApiElectrum();
ServerApiElectrum.ResponseListener electrumListener = new ServerApiElectrum.ResponseListener() {
@Override
public void onSuccess(ElectrumRequest electrumRequest) {
if (electrumRequest.isMethod(ElectrumRequest.METHOD_SendTransaction)) {
ServerApiElectrum.ResponseListener electrumListener = new ServerApiElectrum.ResponseListener() {
@Override
public void onSuccess(ElectrumRequest electrumRequest) {
if (electrumRequest.isMethod(ElectrumRequest.METHOD_SendTransaction)) {
try {
String resultString = electrumRequest.getResultString();
if (resultString == null || resultString.isEmpty()) {
ctx.setError("Rejected by node: " + electrumRequest.getError());
blockchainRequestsCallbacks.onComplete(false);
} else {
ctx.setError(null);
blockchainRequestsCallbacks.onComplete(true);
}
} catch (Exception e) {
if (e.getMessage() != null) {
ctx.setError(e.getMessage());
blockchainRequestsCallbacks.onComplete(false);
} else {
ctx.setError(e.getClass().getName());
blockchainRequestsCallbacks.onComplete(false);
}
}
}
}
@Override
public void onFail(ElectrumRequest electrumRequest) {
ctx.setError(electrumRequest.getError());
blockchainRequestsCallbacks.onComplete(false);
}
};
serverApiElectrum.setResponseListener(electrumListener);
serverApiElectrum.requestData(ctx, ElectrumRequest.broadcast(ctx.getCoinData().getWallet(), txStr));
} else {
final ServerApiSoChain serverApi = new ServerApiSoChain();
ServerApiSoChain.SendTxListener listener = new ServerApiSoChain.SendTxListener() {
@Override
public void onSuccess(SoChain.Response.SendTx response) {
try {
String resultString = electrumRequest.getResultString();
if (resultString == null || resultString.isEmpty()) {
ctx.setError("Rejected by node: " + electrumRequest.getError());
if (response.getStatus() == null || response.getData() == null) {
ctx.setError("Rejected by node: invalid answer received");
blockchainRequestsCallbacks.onComplete(false);
} else if (response.getStatus().equals("fail") || response.getData().getTxid() == null) {
ctx.setError("Rejected by node: " + response.getData());
blockchainRequestsCallbacks.onComplete(false);
} else {
ctx.setError(null);
@ -968,19 +1075,17 @@ public class BtcEngine extends CoinEngine {
}
}
}
}
@Override
public void onFail(ElectrumRequest electrumRequest) {
ctx.setError(electrumRequest.getError());
blockchainRequestsCallbacks.onComplete(false);
}
};
serverApiElectrum.setResponseListener(electrumListener);
serverApiElectrum.requestData(ctx, ElectrumRequest.broadcast(ctx.getCoinData().getWallet(), txStr));
@Override
public void onFail(String message) {
ctx.setError(message);
blockchainRequestsCallbacks.onComplete(false);
}
};
serverApi.setSendTxListener(listener);
serverApi.requestSendTransaction(ctx.getBlockchain(), txStr);
}
}
}

View file

@ -1,11 +1,11 @@
buildscript {
ext.kotlin_version = '1.3.21'
ext.kotlin_version = '1.3.30'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.android.tools.build:gradle:3.4.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
}

View file

@ -29,7 +29,7 @@ dependencies {
implementation project(':card-common')
// implementation 'com.github.TangemCash.card_android-common:card_android-android:0.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.scottyab:rootbeer-lib:0.0.7'
testImplementation 'junit:junit:4.12'

View file

@ -1,6 +1,6 @@
#Fri Jan 18 12:06:47 MSK 2019
#Wed Apr 17 22:33:22 MSK 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

View file

@ -29,7 +29,7 @@ dependencies {
implementation project(':card-common')
// implementation 'com.github.TangemCash.card_android-common:card_android-android:0.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0-alpha03'
implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'