mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-03-20 22:28:48 +00:00
bad missing funds error fix
This commit is contained in:
parent
7c3703ffd7
commit
d546d5de97
1 changed files with 47 additions and 10 deletions
|
@ -142,13 +142,17 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T>
|
||||||
fractionDigits: cryptoCurrency.fractionDigits,
|
fractionDigits: cryptoCurrency.fractionDigits,
|
||||||
);
|
);
|
||||||
final Set<UTXO> utxosToUse = {};
|
final Set<UTXO> utxosToUse = {};
|
||||||
for (final utxo in utxos) {
|
final Set<UTXO> utxosRemaining = {};
|
||||||
|
for (int i = 0; i < utxos.length; i++) {
|
||||||
|
final utxo = utxos[i];
|
||||||
sum += Amount(
|
sum += Amount(
|
||||||
rawValue: BigInt.from(utxo.value),
|
rawValue: BigInt.from(utxo.value),
|
||||||
fractionDigits: cryptoCurrency.fractionDigits,
|
fractionDigits: cryptoCurrency.fractionDigits,
|
||||||
);
|
);
|
||||||
utxosToUse.add(utxo);
|
if (sum < total) {
|
||||||
if (sum > total) {
|
utxosToUse.add(utxo);
|
||||||
|
} else {
|
||||||
|
utxosRemaining.addAll(utxos.sublist(i));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,13 +187,40 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T>
|
||||||
await checkChangeAddressForTransactions();
|
await checkChangeAddressForTransactions();
|
||||||
final changeAddress = await getCurrentChangeAddress();
|
final changeAddress = await getCurrentChangeAddress();
|
||||||
|
|
||||||
final config = Frost.createSignConfig(
|
String? config;
|
||||||
network: network,
|
|
||||||
inputs: inputs,
|
while (config == null) {
|
||||||
outputs: txData.recipients!,
|
try {
|
||||||
changeAddress: changeAddress!.value,
|
config = Frost.createSignConfig(
|
||||||
feePerWeight: feePerWeight,
|
network: network,
|
||||||
);
|
inputs: inputs,
|
||||||
|
outputs: txData.recipients!,
|
||||||
|
changeAddress: changeAddress!.value,
|
||||||
|
feePerWeight: feePerWeight,
|
||||||
|
);
|
||||||
|
} on FrostdartException catch (e) {
|
||||||
|
if (e.errorCode == NOT_ENOUGH_FUNDS_ERROR &&
|
||||||
|
utxosRemaining.isNotEmpty) {
|
||||||
|
// add extra utxo
|
||||||
|
final utxo = utxosRemaining.take(1).first;
|
||||||
|
final dData = await getDerivationData(
|
||||||
|
utxo.address,
|
||||||
|
);
|
||||||
|
final publicKey = cryptoCurrency.addressToPubkey(
|
||||||
|
address: utxo.address!,
|
||||||
|
);
|
||||||
|
inputs.add(
|
||||||
|
(
|
||||||
|
utxo: utxo,
|
||||||
|
scriptPubKey: publicKey,
|
||||||
|
addressDerivationData: dData,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return txData.copyWith(frostMSConfig: config, utxos: utxosToUse);
|
return txData.copyWith(frostMSConfig: config, utxos: utxosToUse);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
|
@ -1380,6 +1411,8 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T>
|
||||||
// rust doesn't like the addressDerivationData
|
// rust doesn't like the addressDerivationData
|
||||||
index++;
|
index++;
|
||||||
continue;
|
continue;
|
||||||
|
} else {
|
||||||
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1408,6 +1441,8 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T>
|
||||||
// rust doesn't like the addressDerivationData
|
// rust doesn't like the addressDerivationData
|
||||||
index++;
|
index++;
|
||||||
continue;
|
continue;
|
||||||
|
} else {
|
||||||
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1484,6 +1519,8 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T>
|
||||||
// rust doesn't like the addressDerivationData
|
// rust doesn't like the addressDerivationData
|
||||||
index++;
|
index++;
|
||||||
continue;
|
continue;
|
||||||
|
} else {
|
||||||
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue