From 7045800e48ebd23727b7af6cd7c427071b80c3d0 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Sat, 11 Feb 2023 19:35:13 +0900 Subject: [PATCH] Fix possible error 500 if no more address in the change address pool (Fix #403) --- NBXplorer/Controllers/MainController.PSBT.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NBXplorer/Controllers/MainController.PSBT.cs b/NBXplorer/Controllers/MainController.PSBT.cs index 2e7933a5f..779110c99 100644 --- a/NBXplorer/Controllers/MainController.PSBT.cs +++ b/NBXplorer/Controllers/MainController.PSBT.cs @@ -259,7 +259,7 @@ public async Task 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(); change = (keyInfo.ScriptPubKey, keyInfo.KeyPath); } else @@ -323,7 +323,7 @@ public async Task 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(); // In most of the time, this is the same as previously, so no need to rebuild PSBT if (derivation.ScriptPubKey != change.ScriptPubKey) {