Bug fixes
This commit is contained in:
@ -84,23 +84,27 @@ public class StreamManagerFactory
|
||||
|
||||
if (ep == default) throw new Exception("No endpoint found");
|
||||
|
||||
stream = new()
|
||||
// create new stream entry for source only
|
||||
if (info.Variant == "source")
|
||||
{
|
||||
EndpointId = ep.Id,
|
||||
PubKey = user.PubKey,
|
||||
ClientId = info.ClientId,
|
||||
State = UserStreamState.Planned
|
||||
};
|
||||
stream = new()
|
||||
{
|
||||
EndpointId = ep.Id,
|
||||
PubKey = user.PubKey,
|
||||
ClientId = info.ClientId,
|
||||
State = UserStreamState.Planned
|
||||
};
|
||||
|
||||
var ev = _eventBuilder.CreateStreamEvent(user, stream);
|
||||
stream.Event = JsonConvert.SerializeObject(ev, NostrSerializer.Settings);
|
||||
_db.Streams.Add(stream);
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
var ev = _eventBuilder.CreateStreamEvent(user, stream);
|
||||
stream.Event = JsonConvert.SerializeObject(ev, NostrSerializer.Settings);
|
||||
_db.Streams.Add(stream);
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
// replace again with new values
|
||||
stream = new()
|
||||
{
|
||||
Id = stream.Id,
|
||||
Id = stream?.Id ?? Guid.NewGuid(),
|
||||
User = user,
|
||||
Endpoint = ep,
|
||||
ClientId = info.ClientId,
|
||||
|
@ -1,5 +1,3 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Nostr.Client.Utils;
|
||||
using NostrStreamer.Database;
|
||||
@ -17,17 +15,44 @@ public class UserService
|
||||
_lnd = lnd;
|
||||
}
|
||||
|
||||
public async Task<string> CreateTopup(string pubkey, ulong amount, string? nostr)
|
||||
/// <summary>
|
||||
/// Create new user account
|
||||
/// </summary>
|
||||
/// <param name="pubkey"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<User> CreateAccount(string pubkey)
|
||||
{
|
||||
var user = new User()
|
||||
{
|
||||
PubKey = pubkey,
|
||||
Balance = 1000_000,
|
||||
StreamKey = Guid.NewGuid().ToString()
|
||||
};
|
||||
|
||||
_db.Users.Add(user);
|
||||
await _db.SaveChangesAsync();
|
||||
return user;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create topup for a user
|
||||
/// </summary>
|
||||
/// <param name="pubkey"></param>
|
||||
/// <param name="amount">milli-sats amount</param>
|
||||
/// <param name="descHash"></param>
|
||||
/// <param name="nostr"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public async Task<string> CreateTopup(string pubkey, ulong amount, string? descHash, string? nostr)
|
||||
{
|
||||
var user = await GetUser(pubkey);
|
||||
if (user == default) throw new Exception("No user found");
|
||||
|
||||
var descHash = string.IsNullOrEmpty(nostr) ? null : SHA256.HashData(Encoding.UTF8.GetBytes(nostr)).ToHex();
|
||||
var invoice = await _lnd.AddInvoice(amount * 1000, TimeSpan.FromMinutes(10), $"Top up for {pubkey}", descHash);
|
||||
var invoice = await _lnd.AddInvoice(amount, TimeSpan.FromMinutes(10), $"Top up for {pubkey}", descHash);
|
||||
_db.Payments.Add(new()
|
||||
{
|
||||
PubKey = pubkey,
|
||||
Amount = amount,
|
||||
Amount = amount / 1000,
|
||||
Invoice = invoice.PaymentRequest,
|
||||
PaymentHash = invoice.RHash.ToByteArray().ToHex(),
|
||||
Nostr = nostr,
|
Reference in New Issue
Block a user