Fix: Adding comment on wallet transactions causes 500 error (Close #1280)

This commit is contained in:
nicolas.dorier 2020-01-16 15:19:28 +09:00
parent c269dee980
commit 9410933e1c
No known key found for this signature in database
GPG Key ID: 6618763EF09186FE
2 changed files with 10 additions and 1 deletions

View File

@ -862,6 +862,7 @@ namespace BTCPayServer.Tests
Assert.Equal(tx.Id, txId.ToString()); Assert.Equal(tx.Id, txId.ToString());
// Hijack the test to see if we can add label and comments // Hijack the test to see if we can add label and comments
Assert.IsType<RedirectToActionResult>(await walletController.ModifyTransaction(walletId, tx.Id, addcomment: "hello-pouet"));
Assert.IsType<RedirectToActionResult>(await walletController.ModifyTransaction(walletId, tx.Id, addlabel: "test")); Assert.IsType<RedirectToActionResult>(await walletController.ModifyTransaction(walletId, tx.Id, addlabel: "test"));
Assert.IsType<RedirectToActionResult>(await walletController.ModifyTransaction(walletId, tx.Id, addlabelclick: "test2")); Assert.IsType<RedirectToActionResult>(await walletController.ModifyTransaction(walletId, tx.Id, addlabelclick: "test2"));
Assert.IsType<RedirectToActionResult>(await walletController.ModifyTransaction(walletId, tx.Id, addcomment: "hello")); Assert.IsType<RedirectToActionResult>(await walletController.ModifyTransaction(walletId, tx.Id, addcomment: "hello"));

View File

@ -85,9 +85,17 @@ namespace BTCPayServer.Services
catch (DbUpdateException) // Does not exists catch (DbUpdateException) // Does not exists
{ {
entity.State = EntityState.Added; entity.State = EntityState.Added;
try
{
await ctx.SaveChangesAsync();
}
catch(DbUpdateException) // the Wallet does not exists in the DB
{
await SetWalletInfo(walletId, new WalletBlobInfo());
await ctx.SaveChangesAsync(); await ctx.SaveChangesAsync();
} }
} }
} }
} }
} }
}