feat: more info on privkey error (#1612)
Some checks are pending
Cache Dependencies / test (push) Waiting to run

This commit is contained in:
Rafael 2024-08-15 22:34:41 -03:00 committed by GitHub
parent 40496fbfe7
commit 102139b061
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -993,11 +993,29 @@ abstract class ElectrumWalletBase
bool hasTaprootInputs = false;
final transaction = txb.buildTransaction((txDigest, utxo, publicKey, sighash) {
final key = estimatedTx.inputPrivKeyInfos
.firstWhereOrNull((element) => element.privkey.getPublic().toHex() == publicKey);
String error = "Cannot find private key.";
ECPrivateInfo? key;
if (estimatedTx.inputPrivKeyInfos.isEmpty) {
error += "\nNo private keys generated.";
} else {
error += "\nAddress: ${utxo.ownerDetails.address.toAddress()}";
key = estimatedTx.inputPrivKeyInfos.firstWhereOrNull((element) {
final elemPubkey = element.privkey.getPublic().toHex();
if (elemPubkey == publicKey) {
return true;
} else {
error += "\nExpected: $publicKey";
error += "\nPubkey: $elemPubkey";
return false;
}
});
}
if (key == null) {
throw Exception("Cannot find private key");
throw Exception(error);
}
if (utxo.utxo.isP2tr()) {