Updated on 2026-08-14
This commit is contained in:
parent
c736d34557
commit
256a7f50f0
3 changed files with 17 additions and 10 deletions
|
|
@ -5,6 +5,7 @@ import com.tangem.blockchain.blockchains.binance.client.domain.broadcast.Transfe
|
|||
import com.tangem.blockchain.blockchains.binance.client.encoding.message.MessageType
|
||||
import com.tangem.blockchain.blockchains.binance.client.encoding.message.TransactionRequestAssemblerExtSign
|
||||
import com.tangem.blockchain.blockchains.binance.client.encoding.message.TransferMessage
|
||||
import com.tangem.blockchain.common.AmountType
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.blockchain.common.TransactionData
|
||||
import com.tangem.blockchain.extensions.Result
|
||||
|
|
@ -28,13 +29,14 @@ class BinanceTransactionBuilder(
|
|||
private var transferMessage: TransferMessage? = null
|
||||
|
||||
fun buildToSign(transactionData: TransactionData): Result<ByteArray> {
|
||||
val amount = transactionData.amount
|
||||
|
||||
if (!transactionData.amount.isAboveZero()) return Result.Failure(Exception("Transaction amount is not defined"))
|
||||
if (!amount.isAboveZero()) return Result.Failure(Exception("Transaction amount is not defined"))
|
||||
val accountNumber = accountNumber ?: return Result.Failure(Exception("No account number"))
|
||||
val sequence = sequence ?: return Result.Failure(Exception("No sequence"))
|
||||
|
||||
val transfer = Transfer()
|
||||
transfer.coin = transactionData.amount.currencySymbol
|
||||
transfer.coin = if (amount.type == AmountType.Coin) amount.currencySymbol else amount.address
|
||||
transfer.fromAddress = transactionData.sourceAddress
|
||||
transfer.toAddress = transactionData.destinationAddress
|
||||
transfer.amount = transactionData.amount.value!!
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
package com.tangem.blockchain.blockchains.binance
|
||||
|
||||
import android.util.Log
|
||||
import com.tangem.blockchain.blockchains.binance.network.BinanceInfoResponse
|
||||
import com.tangem.blockchain.blockchains.binance.network.BinanceNetworkManager
|
||||
import com.tangem.blockchain.common.*
|
||||
import com.tangem.blockchain.extensions.Result
|
||||
import com.tangem.blockchain.extensions.SimpleResult
|
||||
import com.tangem.common.CompletionResult
|
||||
import com.tangem.blockchain.blockchains.binance.network.BinanceInfoResponse as BinanceInfoResponse1
|
||||
|
||||
class BinanceWalletManager(
|
||||
cardId: String,
|
||||
|
|
@ -18,16 +18,17 @@ class BinanceWalletManager(
|
|||
private val blockchain = wallet.blockchain
|
||||
|
||||
override suspend fun update() {
|
||||
val result = networkManager.getInfo(wallet.address)
|
||||
val result = networkManager.getInfo(wallet.address, wallet.amounts[AmountType.Token]?.address)
|
||||
when (result) {
|
||||
is Result.Success -> updateWallet(result.data)
|
||||
is Result.Failure -> updateError(result.error)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateWallet(response: BinanceInfoResponse) {
|
||||
private fun updateWallet(response: BinanceInfoResponse1) {
|
||||
Log.d(this::class.java.simpleName, "Balance is ${response.balance}")
|
||||
wallet.amounts[AmountType.Coin]?.value = response.balance
|
||||
wallet.amounts[AmountType.Token]?.value = response.assetBalance
|
||||
|
||||
transactionBuilder.accountNumber = response.accountNumber
|
||||
transactionBuilder.sequence = response.sequence
|
||||
|
|
|
|||
|
|
@ -25,20 +25,22 @@ class BinanceNetworkManager(isTestNet: Boolean = false) {
|
|||
)
|
||||
}
|
||||
|
||||
suspend fun getInfo(address: String): Result<BinanceInfoResponse> {
|
||||
suspend fun getInfo(address: String, assetCode: String? = null): Result<BinanceInfoResponse> {
|
||||
return try {
|
||||
val accountData = retryIO { client.getAccount(address) }
|
||||
|
||||
var coinBalance = BigDecimal.ZERO
|
||||
var assetBalance = BigDecimal.ZERO
|
||||
for (balance in accountData.balances) {
|
||||
if (balance.symbol == "BNB") {
|
||||
coinBalance = balance.free.toBigDecimal()
|
||||
break
|
||||
when (balance.symbol) {
|
||||
"BNB" -> coinBalance = balance.free.toBigDecimal()
|
||||
assetCode -> assetBalance = balance.free.toBigDecimal()
|
||||
}
|
||||
}
|
||||
|
||||
Result.Success(BinanceInfoResponse(
|
||||
balance = coinBalance,
|
||||
assetBalance = assetBalance,
|
||||
accountNumber = accountData.accountNumber.toLong(),
|
||||
sequence = accountData.sequence
|
||||
))
|
||||
|
|
@ -46,6 +48,7 @@ class BinanceNetworkManager(isTestNet: Boolean = false) {
|
|||
if (exception.message == "account not found") {
|
||||
Result.Success(BinanceInfoResponse(
|
||||
balance = BigDecimal.ZERO, //TODO check account not found logic
|
||||
assetBalance = null,
|
||||
accountNumber = null,
|
||||
sequence = null
|
||||
))
|
||||
|
|
@ -88,7 +91,8 @@ class BinanceNetworkManager(isTestNet: Boolean = false) {
|
|||
}
|
||||
|
||||
data class BinanceInfoResponse(
|
||||
val balance: BigDecimal?,
|
||||
val balance: BigDecimal,
|
||||
val assetBalance: BigDecimal?,
|
||||
val accountNumber: Long?,
|
||||
val sequence: Long?
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue