Updated on 2026-08-14
This commit is contained in:
parent
6ebb46c2a5
commit
03ed4fbd92
4 changed files with 37 additions and 15 deletions
|
|
@ -156,11 +156,20 @@ public class ElectrumRequest {
|
|||
}
|
||||
|
||||
public JSONObject getError() throws JSONException {
|
||||
return getAnswer().getJSONObject("error");
|
||||
JSONObject answer = getAnswer();
|
||||
if (answer.has("error")) {
|
||||
return getAnswer().getJSONObject("error");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getResultString() throws JSONException {
|
||||
return getAnswer().getString("result");
|
||||
if (getAnswer().has("result")) {
|
||||
return getAnswer().getString("result");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public JSONArray getResultArray() throws JSONException {
|
||||
|
|
|
|||
|
|
@ -440,14 +440,14 @@ public class BtcEngine extends CoinEngine {
|
|||
throw new CardProtocol.TangemException_WrongAmount(String.format("Balance (%d) < change (%d) + amount (%d)", fullAmount, change, amount));
|
||||
}
|
||||
|
||||
byte[][] txForSign = new byte[unspentOutputs.size()][];
|
||||
byte[][] bodyDoubleHash = new byte[unspentOutputs.size()][];
|
||||
byte[][] bodyHash= new byte[unspentOutputs.size()][];
|
||||
final byte[][] txForSign = new byte[unspentOutputs.size()][];
|
||||
final byte[][] bodyDoubleHash = new byte[unspentOutputs.size()][];
|
||||
final byte[][] bodyHash= new byte[unspentOutputs.size()][];
|
||||
|
||||
for (int i = 0; i < unspentOutputs.size(); ++i) {
|
||||
txForSign[i] = BTCUtils.buildTXForSign(myAddress, targetAddress, myAddress, unspentOutputs, i, amount, change);
|
||||
bodyHash[i] = Util.calculateSHA256(txForSign[i]);
|
||||
bodyDoubleHash [i] = Util.calculateSHA256(bodyHash[i]);
|
||||
bodyDoubleHash[i] = Util.calculateSHA256(bodyHash[i]);
|
||||
}
|
||||
|
||||
return new SignTask.PaymentToSign() {
|
||||
|
|
@ -490,10 +490,10 @@ public class BtcEngine extends CoinEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onSignCompleted(byte[] signature) throws Exception {
|
||||
public void onSignCompleted(byte[] signFromCard) throws Exception {
|
||||
for (int i = 0; i < unspentOutputs.size(); ++i) {
|
||||
BigInteger r = new BigInteger(1, Arrays.copyOfRange(signature, i * 64, 32 + i * 64));
|
||||
BigInteger s = new BigInteger(1, Arrays.copyOfRange(signature, 32 + i * 64, 64 + i * 64));
|
||||
BigInteger r = new BigInteger(1, Arrays.copyOfRange(signFromCard, i * 64, 32 + i * 64));
|
||||
BigInteger s = new BigInteger(1, Arrays.copyOfRange(signFromCard, 32 + i * 64, 64 + i * 64));
|
||||
s = CryptoUtil.toCanonicalised(s);
|
||||
|
||||
unspentOutputs.get(i).scriptForBuild = DerEncodingUtil.packSignDer(r, s, pbKey);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import com.tangem.tangemcard.data.TangemCard
|
|||
import com.tangem.util.UtilHelper
|
||||
import com.tangem.wallet.R
|
||||
import java.io.IOException
|
||||
import java.lang.Exception
|
||||
import java.math.BigInteger
|
||||
|
||||
class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
||||
|
|
@ -58,10 +59,21 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
val electrumBodyListener: ServerApiElectrum.ElectrumRequestDataListener = object : ServerApiElectrum.ElectrumRequestDataListener {
|
||||
override fun onSuccess(electrumRequest: ElectrumRequest?) {
|
||||
if (electrumRequest!!.isMethod(ElectrumRequest.METHOD_SendTransaction)) {
|
||||
if (electrumRequest.resultString.isEmpty())
|
||||
finishWithError("Rejected by node: " + electrumRequest.getError())
|
||||
else
|
||||
finishWithSuccess()
|
||||
try {
|
||||
if (electrumRequest.resultString.isNullOrEmpty())
|
||||
finishWithError("Rejected by node: " + electrumRequest.getError())
|
||||
else
|
||||
finishWithSuccess()
|
||||
}
|
||||
catch (e: Exception)
|
||||
{
|
||||
if( e.message!=null )
|
||||
{
|
||||
finishWithError(e.message!!)
|
||||
}else{
|
||||
finishWithError(e.javaClass.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -137,7 +137,8 @@ class SignPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
}
|
||||
// signPaymentTask = SignPaymentTask(this, ctx, nfcManager, isoDep, this, amount, fee, isIncludeFee, outAddressStr)
|
||||
|
||||
val coinEngine= CoinEngineFactory.create(ctx) ?: throw CardProtocol.TangemException("Can't create CoinEngine!")
|
||||
coinEngine.setOnNeedSendPayment { tx->
|
||||
val coinEngine = CoinEngineFactory.create(ctx)
|
||||
?: throw CardProtocol.TangemException("Can't create CoinEngine!")
|
||||
coinEngine.setOnNeedSendPayment { tx ->
|
||||
if (tx != null) {
|
||||
// [REDACTED_TODO_COMMENT]
|
||||
Loading…
Add table
Add a link
Reference in a new issue