Updated on 2026-08-14
This commit is contained in:
parent
17bb23ecfc
commit
e11275cb49
9 changed files with 233 additions and 58 deletions
|
|
@ -2,10 +2,12 @@ package com.tangem.data.network;
|
|||
|
||||
import com.tangem.data.network.model.BinanceFees;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.GET;
|
||||
|
||||
public interface BinanceApi {
|
||||
@GET("/fees")
|
||||
Call<BinanceFees> binanceFees();
|
||||
@GET("fees")
|
||||
Call<List<BinanceFees>> binanceFees();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public class Server {
|
|||
public static final String URL_BINANCE = ServerURL.API_BINANCE;
|
||||
|
||||
public static class Method {
|
||||
public static final String API_V1 = URL_BINANCE + "api/v1";
|
||||
public static final String API_V1 = URL_BINANCE + "api/v1/";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ public class Server {
|
|||
public static final String URL_BINANCE_TESTNET = ServerURL.API_BINANCE_TESTNET;
|
||||
|
||||
public static class Method {
|
||||
public static final String API_V1 = URL_BINANCE_TESTNET + "api/v1";
|
||||
public static final String API_V1 = URL_BINANCE_TESTNET + "api/v1/";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
116
app/src/main/java/com/tangem/data/network/ServerApiBinance.java
Normal file
116
app/src/main/java/com/tangem/data/network/ServerApiBinance.java
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
package com.tangem.data.network;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.tangem.wallet.TangemContext;
|
||||
import com.tangem.wallet.Transaction;
|
||||
import com.tangem.wallet.binance.BinanceData;
|
||||
import com.tangem.wallet.binance.client.BinanceDexApiRestClient;
|
||||
import com.tangem.wallet.binance.client.domain.Account;
|
||||
import com.tangem.wallet.binance.client.domain.Balance;
|
||||
import com.tangem.wallet.binance.client.domain.TransactionMetadata;
|
||||
import com.tangem.wallet.binance.client.encoding.message.TransactionRequestAssemblerExtSign;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.observers.DefaultObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public class ServerApiBinance {
|
||||
private static String TAG = ServerApiBinance.class.getSimpleName();
|
||||
|
||||
private ResponseListener responseListener;
|
||||
|
||||
public interface ResponseListener {
|
||||
void onSuccess();
|
||||
void onFail();
|
||||
}
|
||||
|
||||
public void setResponseListener(ResponseListener listener) {
|
||||
responseListener = listener;
|
||||
}
|
||||
|
||||
public void getBalance(TangemContext ctx, BinanceDexApiRestClient client) {
|
||||
Log.i(TAG, "new getBalance request");
|
||||
|
||||
Observable<Account> balanceObservable = Observable.just(new Account())
|
||||
.map(account -> client.getAccount(ctx.getCoinData().getWallet()))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
|
||||
balanceObservable.subscribe(new DefaultObserver<Account>() {
|
||||
@Override
|
||||
public void onNext(Account account) {
|
||||
Log.i(TAG, "getBalance onNext");
|
||||
// account = client.getAccount(ctx.getCoinData().getWallet());
|
||||
BinanceData binanceData = (BinanceData) ctx.getCoinData();
|
||||
|
||||
for (Balance balance : account.getBalances()) {
|
||||
if (balance.getSymbol().equals("BNB")) {
|
||||
binanceData.setBalanceReceived(true);
|
||||
binanceData.setBalance(balance.getFree());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
binanceData.setAccountNumber(account.getAccountNumber());
|
||||
binanceData.setSequence(account.getSequence());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e(TAG, "getBalance onError" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
ctx.setError(e.getMessage());
|
||||
responseListener.onFail();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.i(TAG, "getBalance onComplete");
|
||||
responseListener.onSuccess();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void sendTransaction (byte[] txForSend, BinanceDexApiRestClient client) {
|
||||
Log.i(TAG, "new sendTransaction request");
|
||||
|
||||
RequestBody requestBody = TransactionRequestAssemblerExtSign.createRequestBody(txForSend);
|
||||
|
||||
Observable<List<TransactionMetadata>> sendObservable = Observable.just(new ArrayList<>())
|
||||
.map(metadatas -> client.broadcastNoWallet(requestBody, true))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
|
||||
sendObservable.subscribe(new DefaultObserver<List<TransactionMetadata>>() {
|
||||
@Override
|
||||
public void onNext(List<TransactionMetadata> metadatas ) {
|
||||
// RequestBody requestBody = TransactionRequestAssemblerExtSign.createRequestBody(txForSend);
|
||||
// List<TransactionMetadata> metadatas = client.broadcastNoWallet(requestBody, true);
|
||||
if (!metadatas.isEmpty() && metadatas.get(0).isOk()) {
|
||||
responseListener.onSuccess();
|
||||
} else {
|
||||
Log.e(TAG, "Transaction send error");
|
||||
responseListener.onFail();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e(TAG, "sendTransaction onError" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
responseListener.onFail();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.i(TAG, "sendTransaction onComplete");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -12,5 +12,5 @@ data class BinanceFixedFee(
|
|||
var msg_type: String? = null,
|
||||
|
||||
@SerializedName("fee")
|
||||
var fee: Long? = null
|
||||
var fee: Int? = null
|
||||
)
|
||||
|
|
@ -32,7 +32,7 @@ public class BinanceData extends CoinData {
|
|||
if (balance != null) B.putString("Balance", balance);
|
||||
if (chainId != null) B.putString("ChainId", chainId);
|
||||
if (sequence != null) B.putLong("Sequence", sequence);
|
||||
if (accountNumber != null) B.putLong("AccountNumber", accountNumber);
|
||||
if (accountNumber != null) B.putInt("AccountNumber", accountNumber);
|
||||
} catch (Exception e) {
|
||||
Log.e("Can't save to bundle ", e.getMessage());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
package com.tangem.wallet.binance;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.StrictMode;
|
||||
import android.text.InputFilter;
|
||||
import android.util.Log;
|
||||
|
||||
|
|
@ -8,12 +11,14 @@ import androidx.annotation.NonNull;
|
|||
|
||||
import com.ripple.crypto.ecdsa.ECDSASignature;
|
||||
import com.tangem.card_common.data.TangemCard;
|
||||
import com.tangem.card_common.reader.CardCrypto;
|
||||
import com.tangem.card_common.reader.CardProtocol;
|
||||
import com.tangem.card_common.tasks.SignTask;
|
||||
import com.tangem.card_common.util.Util;
|
||||
import com.tangem.data.Blockchain;
|
||||
import com.tangem.data.network.BinanceApi;
|
||||
import com.tangem.data.network.Server;
|
||||
import com.tangem.data.network.ServerApiBinance;
|
||||
import com.tangem.data.network.model.BinanceFees;
|
||||
import com.tangem.util.CryptoUtil;
|
||||
import com.tangem.util.DecimalDigitsInputFilter;
|
||||
|
|
@ -33,6 +38,7 @@ import com.tangem.wallet.binance.client.domain.broadcast.TransactionOption;
|
|||
import com.tangem.wallet.binance.client.domain.broadcast.Transfer;
|
||||
import com.tangem.wallet.binance.client.encoding.Bech32;
|
||||
import com.tangem.wallet.binance.client.encoding.Crypto;
|
||||
import com.tangem.wallet.binance.client.encoding.message.MessageType;
|
||||
import com.tangem.wallet.binance.client.encoding.message.TransactionRequestAssemblerExtSign;
|
||||
import com.tangem.wallet.binance.client.encoding.message.TransferMessage;
|
||||
|
||||
|
|
@ -365,6 +371,13 @@ public class BinanceEngine extends CoinEngine {
|
|||
amount = amountValue.setScale(getDecimals(), RoundingMode.DOWN).toPlainString();
|
||||
}
|
||||
|
||||
byte[] pubKey = ctx.getCard().getWalletPublicKeyRar();
|
||||
byte[] pubKeyPrefix = MessageType.PubKey.getTypePrefixBytes();
|
||||
byte[] pubKeyForSign = new byte[pubKey.length + pubKeyPrefix.length + 1];
|
||||
System.arraycopy(pubKeyPrefix, 0, pubKeyForSign, 0, pubKeyPrefix.length);
|
||||
pubKeyForSign[pubKeyPrefix.length] = (byte) 33;
|
||||
System.arraycopy(pubKey, 0, pubKeyForSign, pubKeyPrefix.length + 1, pubKey.length);
|
||||
|
||||
Transfer transfer = new Transfer();
|
||||
transfer.setCoin("BNB");
|
||||
transfer.setFromAddress(ctx.getCoinData().getWallet());
|
||||
|
|
@ -373,11 +386,32 @@ public class BinanceEngine extends CoinEngine {
|
|||
|
||||
TransactionOption options = TransactionOption.DEFAULT_INSTANCE;
|
||||
|
||||
TransactionRequestAssemblerExtSign txAssembler = client.prepareTransfer(transfer, coinData, ctx.getCard().getWalletPublicKeyRar(), options, true);
|
||||
TransactionRequestAssemblerExtSign txAssembler = client.prepareTransfer(transfer, coinData, pubKeyForSign, options, true);
|
||||
// TransactionRequestAssembler.buildTransfer as reference
|
||||
TransferMessage msgBean = txAssembler.createTransferMessage(transfer);
|
||||
byte[] msg = txAssembler.encodeTransferMessage(msgBean);
|
||||
byte[] dataForSign = txAssembler.prepareForSign(msgBean);
|
||||
// byte[] dataForSign = Util.fromHexString("7b226163636f756e745f6e756d626572223a2231222c22636861696e5f6964223a22626e62636861696e2d31303030222c226d656d6f223a22222c226d736773223a5b7b226964223a22423635363144434331303431333030353941374330384634384336343631304331463646393036342d3130222c226f7264657274797065223a322c227072696365223a3130303030303030302c227175616e74697479223a313230303030303030302c2273656e646572223a22626e63316b6574706d6e71736779637174786e7570723667636572707073306b6c797279687a36667a6c222c2273696465223a312c2273796d626f6c223a224254432d3543345f424e42222c2274696d65696e666f726365223a317d5d2c2273657175656e6365223a2239227d");
|
||||
//
|
||||
// byte[] privateKey = Util.fromHexString("30c5e838578a29e3e9273edddd753d6c9b38aca2446dd84bdfe2e5988b0da0a1");
|
||||
//
|
||||
// byte[] signFromCard = CardCrypto.Signature(privateKey, dataForSign);
|
||||
//
|
||||
// int size = signFromCard.length / 2;
|
||||
// BigInteger r = new BigInteger(1, Arrays.copyOfRange(signFromCard, 0, size));
|
||||
// BigInteger s = new BigInteger(1, Arrays.copyOfRange(signFromCard, size, size * 2));
|
||||
// s = CryptoUtil.toCanonicalised(s);
|
||||
//// ECKey.ECDSASignature sig = new ECKey.ECDSASignature(r, s);
|
||||
//// byte[] sigDer = sig.encodeToDER();
|
||||
//// if (!ECDSASignature.isStrictlyCanonical(sigDer)) {
|
||||
//// throw new IllegalStateException("Signature is not strictly canonical");
|
||||
//// }
|
||||
// byte[] resultSig = new byte[64];
|
||||
// System.arraycopy(Utils.bigIntegerToBytes(r, 32), 0, resultSig, 0, 32);
|
||||
// System.arraycopy(Utils.bigIntegerToBytes(s, 32), 0, resultSig, 32, 32);
|
||||
//
|
||||
// String test = Util.byteArrayToHexString(resultSig);
|
||||
// int x = 1;
|
||||
|
||||
return new SignTask.TransactionToSign() {
|
||||
|
||||
|
|
@ -389,7 +423,7 @@ public class BinanceEngine extends CoinEngine {
|
|||
@Override
|
||||
public byte[][] getHashesToSign() {
|
||||
byte[][] hashForSign = new byte[1][];
|
||||
hashForSign[1] = CryptoUtil.doubleSha256(dataForSign);
|
||||
hashForSign[0] = CryptoUtil.doubleSha256(dataForSign);
|
||||
return hashForSign;
|
||||
}
|
||||
|
||||
|
|
@ -410,37 +444,47 @@ public class BinanceEngine extends CoinEngine {
|
|||
|
||||
@Override
|
||||
public byte[] onSignCompleted(byte[] signFromCard) throws Exception {
|
||||
int size = signFromCard.length / 2;
|
||||
BigInteger r = new BigInteger(1, Arrays.copyOfRange(signFromCard, 0, size));
|
||||
BigInteger s = new BigInteger(1, Arrays.copyOfRange(signFromCard, size, size * 2));
|
||||
s = CryptoUtil.toCanonicalised(s);
|
||||
ECKey.ECDSASignature sig = new ECKey.ECDSASignature(r, s);
|
||||
byte[] sigDer = sig.encodeToDER();
|
||||
if (!ECDSASignature.isStrictlyCanonical(sigDer)) {
|
||||
throw new IllegalStateException("Signature is not strictly canonical");
|
||||
}
|
||||
// int size = signFromCard.length / 2;
|
||||
// BigInteger r = new BigInteger(1, Arrays.copyOfRange(signFromCard, 0, size));
|
||||
// BigInteger s = new BigInteger(1, Arrays.copyOfRange(signFromCard, size, size * 2));
|
||||
//// s = CryptoUtil.toCanonicalised(s);
|
||||
//// ECKey.ECDSASignature sig = new ECKey.ECDSASignature(r, s);
|
||||
//// byte[] sigDer = sig.encodeToDER();
|
||||
//// if (!ECDSASignature.isStrictlyCanonical(sigDer)) {
|
||||
//// throw new IllegalStateException("Signature is not strictly canonical");
|
||||
//// }
|
||||
// byte[] resultSig = new byte[64];
|
||||
// System.arraycopy(Utils.bigIntegerToBytes(r, 32), 0, resultSig, 0, 32);
|
||||
// System.arraycopy(Utils.bigIntegerToBytes(s, 32), 0, resultSig, 32, 32);
|
||||
|
||||
// TransactionRequestAssembler.buildTransfer as reference
|
||||
byte[] signature = txAssembler.encodeSignature(sigDer);
|
||||
return txAssembler.encodeStdTx(msg, signature);
|
||||
byte[] signature = txAssembler.encodeSignature(signFromCard);
|
||||
byte[] txForSend = txAssembler.encodeStdTx(msg, signature);
|
||||
|
||||
notifyOnNeedSendTransaction(txForSend);
|
||||
return txForSend;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void requestBalanceAndUnspentTransactions(BlockchainRequestsCallbacks blockchainRequestsCallbacks) {
|
||||
try {
|
||||
Account account = client.getAccount(ctx.getCoinData().getWallet());
|
||||
ServerApiBinance serverApiBinance = new ServerApiBinance();
|
||||
|
||||
for (Balance balance : account.getBalances()) {
|
||||
if (balance.getSymbol().equals("BNB")) {
|
||||
coinData.setBalanceReceived(true);
|
||||
coinData.setBalance(balance.getFree());
|
||||
break;
|
||||
ServerApiBinance.ResponseListener responseListener = new ServerApiBinance.ResponseListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
blockchainRequestsCallbacks.onComplete(true);
|
||||
}
|
||||
}
|
||||
|
||||
coinData.setAccountNumber(account.getAccountNumber());
|
||||
coinData.setSequence(account.getSequence());
|
||||
@Override
|
||||
public void onFail() {
|
||||
blockchainRequestsCallbacks.onComplete(false);
|
||||
}
|
||||
};
|
||||
|
||||
serverApiBinance.setResponseListener(responseListener);
|
||||
serverApiBinance.getBalance(ctx, client);
|
||||
|
||||
if (ctx.getBlockchain() == Blockchain.Binance) {
|
||||
coinData.setValidationNodeDescription(Server.ApiBinance.URL_BINANCE);
|
||||
|
|
@ -450,7 +494,6 @@ public class BinanceEngine extends CoinEngine {
|
|||
throw new Exception("Invalid blockchain for BinanceEngine");
|
||||
}
|
||||
|
||||
blockchainRequestsCallbacks.onComplete(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "FAIL Binance balance exception");
|
||||
|
|
@ -461,7 +504,7 @@ public class BinanceEngine extends CoinEngine {
|
|||
|
||||
public void requestFee(BlockchainRequestsCallbacks blockchainRequestsCallbacks, String targetAddress, Amount amount) {
|
||||
try {
|
||||
String baseUrl = null;
|
||||
String baseUrl;
|
||||
|
||||
if (ctx.getBlockchain() == Blockchain.Binance) {
|
||||
baseUrl = Server.ApiBinance.Method.API_V1;
|
||||
|
|
@ -477,16 +520,20 @@ public class BinanceEngine extends CoinEngine {
|
|||
.build();
|
||||
|
||||
BinanceApi binanceApi = retrofitBinance.create(BinanceApi.class);
|
||||
Call<BinanceFees> call = binanceApi.binanceFees();
|
||||
call.enqueue(new Callback<BinanceFees>() {
|
||||
Call<List<BinanceFees>> call = binanceApi.binanceFees();
|
||||
call.enqueue(new Callback<List<BinanceFees>>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<BinanceFees> call, @NonNull Response<BinanceFees> response) {
|
||||
public void onResponse(@NonNull Call<List<BinanceFees>> call, @NonNull Response<List<BinanceFees>> response) {
|
||||
if (response.code() == 200) {
|
||||
Long fee = response.body().getFixed_fee_params().getFee();
|
||||
Amount feeAmount = new Amount(BigDecimal.valueOf(fee).divide(BigDecimal.valueOf(100000000)).setScale(8, RoundingMode.DOWN), getFeeCurrency());
|
||||
coinData.minFee = coinData.normalFee = coinData.maxFee = feeAmount;
|
||||
Log.i(TAG, "requestFee onResponse " + response.code());
|
||||
blockchainRequestsCallbacks.onComplete(true);
|
||||
for (BinanceFees fee : response.body()) {
|
||||
if (fee.getFixed_fee_params() != null) {
|
||||
Long longFee = Long.valueOf(fee.getFixed_fee_params().getFee());
|
||||
Amount feeAmount = new Amount(BigDecimal.valueOf(longFee).divide(BigDecimal.valueOf(100000000)).setScale(8, RoundingMode.DOWN), getFeeCurrency());
|
||||
coinData.minFee = coinData.normalFee = coinData.maxFee = feeAmount;
|
||||
Log.i(TAG, "requestFee onResponse " + response.code());
|
||||
blockchainRequestsCallbacks.onComplete(true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ctx.setError(response.code());
|
||||
Log.e(TAG, "requestFee onResponse " + response.code());
|
||||
|
|
@ -495,7 +542,7 @@ public class BinanceEngine extends CoinEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<BinanceFees> call, @NonNull Throwable t) {
|
||||
public void onFailure(@NonNull Call<List<BinanceFees>> call, @NonNull Throwable t) {
|
||||
ctx.setError(t.getMessage());
|
||||
Log.e(TAG, "requestFee onFailure " + t.getMessage());
|
||||
blockchainRequestsCallbacks.onComplete(false);
|
||||
|
|
@ -510,17 +557,27 @@ public class BinanceEngine extends CoinEngine {
|
|||
}
|
||||
|
||||
public void requestSendTransaction(BlockchainRequestsCallbacks blockchainRequestsCallbacks, byte[] txForSend) {
|
||||
RequestBody requestBody = TransactionRequestAssemblerExtSign.createRequestBody(txForSend);
|
||||
// RequestBody requestBody = TransactionRequestAssemblerExtSign.createRequestBody(txForSend);
|
||||
try {
|
||||
List<TransactionMetadata> metadatas = client.broadcastNoWallet(requestBody, true);
|
||||
if (!metadatas.isEmpty() && metadatas.get(0).isOk()) {
|
||||
ctx.setError(null);
|
||||
blockchainRequestsCallbacks.onComplete(true);
|
||||
} else {
|
||||
Log.e(TAG, "Transaction send error");
|
||||
ctx.setError("Transaction send error");
|
||||
blockchainRequestsCallbacks.onComplete(false);
|
||||
}
|
||||
ServerApiBinance serverApiBinance = new ServerApiBinance();
|
||||
|
||||
ServerApiBinance.ResponseListener responseListener = new ServerApiBinance.ResponseListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
ctx.setError(null);
|
||||
blockchainRequestsCallbacks.onComplete(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail() {
|
||||
ctx.setError("Transaction send error");
|
||||
blockchainRequestsCallbacks.onComplete(false);
|
||||
}
|
||||
};
|
||||
|
||||
serverApiBinance.setResponseListener(responseListener);
|
||||
serverApiBinance.sendTransaction(txForSend, client);
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Transaction send error");
|
||||
ctx.setError("Transaction send error");
|
||||
|
|
@ -528,7 +585,7 @@ public class BinanceEngine extends CoinEngine {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean allowSelectFeeInclusion() {
|
||||
public boolean allowSelectFeeLevel() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public interface BinanceDexApiRestClient {
|
|||
List<TransactionMetadata> transfer(Transfer transfer, Wallet wallet, TransactionOption options, boolean sync)
|
||||
throws IOException, NoSuchAlgorithmException;
|
||||
|
||||
TransactionRequestAssemblerExtSign prepareTransfer(Transfer transfer, BinanceData binanceData, byte[] pubKey, TransactionOption options, boolean sync)
|
||||
TransactionRequestAssemblerExtSign prepareTransfer(Transfer transfer, BinanceData binanceData, byte[] pubKeyFroSign, TransactionOption options, boolean sync)
|
||||
throws IOException, NoSuchAlgorithmException;
|
||||
|
||||
List<TransactionMetadata> freeze(TokenFreeze freeze, Wallet wallet, TransactionOption options, boolean sync)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import java.util.List;
|
|||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Assemble a transaction message body.
|
||||
* Assemble a transaction message body with external signature
|
||||
* https://testnet-dex.binance.org/doc/encoding.html
|
||||
*/
|
||||
public class TransactionRequestAssemblerExtSign {
|
||||
|
|
@ -29,12 +29,12 @@ public class TransactionRequestAssemblerExtSign {
|
|||
|
||||
//private Wallet wallet;
|
||||
private BinanceData binanceData;
|
||||
private byte[] pubKey;
|
||||
private byte[] pubKeyForSign;
|
||||
private TransactionOption options;
|
||||
|
||||
public TransactionRequestAssemblerExtSign(BinanceData binanceData, byte[] pubKey, TransactionOption options) {
|
||||
public TransactionRequestAssemblerExtSign(BinanceData binanceData, byte[] pubKeyForSign, TransactionOption options) {
|
||||
this.binanceData = binanceData;
|
||||
this.pubKey = pubKey;
|
||||
this.pubKeyForSign = pubKeyForSign;
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
|
|
@ -62,7 +62,7 @@ public class TransactionRequestAssemblerExtSign {
|
|||
}
|
||||
|
||||
public byte[] encodeSignature(byte[] signatureBytes) throws IOException {
|
||||
StdSignature stdSignature = StdSignature.newBuilder().setPubKey(ByteString.copyFrom(pubKey))
|
||||
StdSignature stdSignature = StdSignature.newBuilder().setPubKey(ByteString.copyFrom(pubKeyForSign))
|
||||
.setSignature(ByteString.copyFrom(signatureBytes))
|
||||
.setAccountNumber(binanceData.getAccountNumber())
|
||||
.setSequence(binanceData.getSequence())
|
||||
|
|
|
|||
|
|
@ -198,9 +198,9 @@ public class BinanceDexApiRestClientImpl implements BinanceDexApiRestClient {
|
|||
return broadcast(requestBody, sync, wallet);
|
||||
}
|
||||
|
||||
public TransactionRequestAssemblerExtSign prepareTransfer(Transfer transfer, BinanceData binanceData, byte[] pubKey, TransactionOption options, boolean sync)
|
||||
public TransactionRequestAssemblerExtSign prepareTransfer(Transfer transfer, BinanceData binanceData, byte[] pubKeyFroSign, TransactionOption options, boolean sync)
|
||||
throws IOException, NoSuchAlgorithmException {
|
||||
TransactionRequestAssemblerExtSign assembler = new TransactionRequestAssemblerExtSign(binanceData, pubKey, options);
|
||||
TransactionRequestAssemblerExtSign assembler = new TransactionRequestAssemblerExtSign(binanceData, pubKeyFroSign, options);
|
||||
return assembler;
|
||||
// RequestBody requestBody = assembler.buildTransfer(transfer);
|
||||
// return broadcast(requestBody, sync, wallet);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue