Skip to content

Commit 7045800

Browse files
committed
Fix possible error 500 if no more address in the change address pool (Fix #403)
1 parent b5592e0 commit 7045800

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

NBXplorer/Controllers/MainController.PSBT.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public async Task<IActionResult> CreatePSBT(
259259
bool hasChange = false;
260260
if (request.ExplicitChangeAddress == null)
261261
{
262-
var keyInfo = await repo.GetUnused(strategy, DerivationFeature.Change, 0, false);
262+
var keyInfo = (await GetUnusedAddress(network.CryptoCode, strategy, DerivationFeature.Change)).As<KeyPathInformation>();
263263
change = (keyInfo.ScriptPubKey, keyInfo.KeyPath);
264264
}
265265
else
@@ -323,7 +323,7 @@ public async Task<IActionResult> CreatePSBT(
323323
// We made sure we can build the PSBT, so now we can reserve the change address if we need to
324324
if (hasChange && request.ExplicitChangeAddress == null && request.ReserveChangeAddress)
325325
{
326-
var derivation = await repo.GetUnused(strategy, DerivationFeature.Change, 0, true);
326+
var derivation = (await GetUnusedAddress(network.CryptoCode, strategy, DerivationFeature.Change, reserve: true)).As<KeyPathInformation>();
327327
// In most of the time, this is the same as previously, so no need to rebuild PSBT
328328
if (derivation.ScriptPubKey != change.ScriptPubKey)
329329
{

0 commit comments

Comments
 (0)