Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOS-8253 Send, Express: (Kaspa) no warning about 84 UTXO #4071

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 3 additions & 18 deletions BlockchainSdk/Blockchains/Kaspa/KaspaTransactionBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,16 @@ class KaspaTransactionBuilder {
}

func availableAmount() -> Amount {
let inputs = unspentOutputs
let inputs = Array(unspentOutputs.prefix(maxInputCount))
let availableAmountInSatoshi = inputs.reduce(0) { $0 + $1.amount }
return Amount(with: blockchain, value: Decimal(availableAmountInSatoshi) / blockchain.decimalValue)
}

func unspentOutputsCount(for amount: Amount) -> Int {
return unspentOutputs.count
}

func setUnspentOutputs(_ unspentOutputs: [BitcoinUnspentOutput]) {
let sortedOutputs = unspentOutputs.sorted {
$0.amount > $1.amount
}

self.unspentOutputs = Array(sortedOutputs.prefix(maxInputCount))
func setUnspentOutputs(_ unspentOutputs: [BitcoinUnspentOutput]) {
self.unspentOutputs = unspentOutputs.sorted { $0.amount > $1.amount }
}

func buildForSign(_ transaction: Transaction) throws -> (KaspaTransaction, [Data]) {
let availableInputValue = self.availableAmount()

guard transaction.amount.type == availableInputValue.type,
transaction.amount <= availableInputValue else {
throw WalletError.failedToBuildTx
}

let destinationAddressScript = try scriptPublicKey(address: transaction.destinationAddress).hexString.lowercased()

var outputs: [KaspaOutput] = [
Expand Down
8 changes: 7 additions & 1 deletion BlockchainSdk/Blockchains/Kaspa/KaspaWalletManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,13 @@ extension KaspaWalletManager: WithdrawalNotificationProvider {

extension KaspaWalletManager: MaximumAmountRestrictable {
func validateMaximumAmount(amount: Amount, fee: Amount) throws {
let amountAvailableToSend = txBuilder.availableAmount() - fee
var amountAvailableToSend = txBuilder.availableAmount() - fee

let change = amount - amountAvailableToSend
if change > .zeroCoin(for: wallet.blockchain), change < dustValue {
amountAvailableToSend = amountAvailableToSend - (dustValue - change)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вычитаем остаток из доступной суммы для отправки, если после отправки 84 UTXO остается пыль

}

if amount <= amountAvailableToSend {
return
}
Expand Down
Loading