Skip to content

Commit

Permalink
Fix possible error 500 if no more address in the change address pool (F…
Browse files Browse the repository at this point in the history
…ix #403)
  • Loading branch information
NicolasDorier committed Feb 11, 2023
1 parent b5592e0 commit 7045800
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions NBXplorer/Controllers/MainController.PSBT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public async Task<IActionResult> CreatePSBT(
bool hasChange = false;
if (request.ExplicitChangeAddress == null)
{
var keyInfo = await repo.GetUnused(strategy, DerivationFeature.Change, 0, false);
var keyInfo = (await GetUnusedAddress(network.CryptoCode, strategy, DerivationFeature.Change)).As<KeyPathInformation>();
change = (keyInfo.ScriptPubKey, keyInfo.KeyPath);
}
else
Expand Down Expand Up @@ -323,7 +323,7 @@ public async Task<IActionResult> CreatePSBT(
// We made sure we can build the PSBT, so now we can reserve the change address if we need to
if (hasChange && request.ExplicitChangeAddress == null && request.ReserveChangeAddress)
{
var derivation = await repo.GetUnused(strategy, DerivationFeature.Change, 0, true);
var derivation = (await GetUnusedAddress(network.CryptoCode, strategy, DerivationFeature.Change, reserve: true)).As<KeyPathInformation>();
// In most of the time, this is the same as previously, so no need to rebuild PSBT
if (derivation.ScriptPubKey != change.ScriptPubKey)
{
Expand Down

0 comments on commit 7045800

Please sign in to comment.