mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 06:24:24 +01:00
Use callback to update invoice state instead of long polling
This commit is contained in:
@@ -26,6 +26,7 @@ namespace BTCPayServer.Controllers
|
||||
public StoresController(
|
||||
StoreRepository repo,
|
||||
TokenRepository tokenRepo,
|
||||
CallbackController callbackController,
|
||||
UserManager<ApplicationUser> userManager,
|
||||
AccessTokenController tokenController,
|
||||
BTCPayWallet wallet,
|
||||
@@ -39,8 +40,10 @@ namespace BTCPayServer.Controllers
|
||||
_Wallet = wallet;
|
||||
_Env = env;
|
||||
_Network = network;
|
||||
_CallbackController = callbackController;
|
||||
}
|
||||
Network _Network;
|
||||
CallbackController _CallbackController;
|
||||
BTCPayWallet _Wallet;
|
||||
AccessTokenController _TokenController;
|
||||
StoreRepository _Repo;
|
||||
@@ -86,7 +89,7 @@ namespace BTCPayServer.Controllers
|
||||
StoresViewModel result = new StoresViewModel();
|
||||
result.StatusMessage = StatusMessage;
|
||||
var stores = await _Repo.GetStoresByUserId(GetUserId());
|
||||
var balances = stores.Select(async s => string.IsNullOrEmpty(s.DerivationStrategy) ? Money.Zero : await _Wallet.GetBalance(s.DerivationStrategy)).ToArray();
|
||||
var balances = stores.Select(async s => string.IsNullOrEmpty(s.DerivationStrategy) ? Money.Zero : await _Wallet.GetBalance(ParseDerivationStrategy(s.DerivationStrategy))).ToArray();
|
||||
|
||||
for(int i = 0; i < stores.Length; i++)
|
||||
{
|
||||
@@ -156,7 +159,9 @@ namespace BTCPayServer.Controllers
|
||||
needUpdate = true;
|
||||
try
|
||||
{
|
||||
await _Wallet.TrackAsync(model.DerivationScheme);
|
||||
var strategy = ParseDerivationStrategy(model.DerivationScheme);
|
||||
await _Wallet.TrackAsync(strategy);
|
||||
await _CallbackController.RegisterCallbackUriAsync(strategy, Request);
|
||||
store.DerivationStrategy = model.DerivationScheme;
|
||||
}
|
||||
catch
|
||||
@@ -192,6 +197,11 @@ namespace BTCPayServer.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
private DerivationStrategyBase ParseDerivationStrategy(string derivationScheme)
|
||||
{
|
||||
return new DerivationStrategyFactory(_Network).Parse(derivationScheme);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("{storeId}/Tokens")]
|
||||
public async Task<IActionResult> ListTokens(string storeId)
|
||||
|
||||
Reference in New Issue
Block a user