Adjust rates

This commit is contained in:
2023-07-10 16:06:37 +01:00
parent 13980b454f
commit 60130329f0
5 changed files with 28 additions and 6 deletions

View File

@ -36,6 +36,11 @@ public class Config
public string[] Relays { get; init; } = Array.Empty<string>();
public LndConfig Lnd { get; init; } = null!;
/// <summary>
/// Cost/min
/// </summary>
public int Cost { get; init; } = 10;
}
public class LndConfig

View File

@ -57,7 +57,7 @@ public class NostrController : Controller
Quota = new()
{
Unit = "min",
Rate = 21,
Rate = _config.Cost,
Remaining = user.Balance
}
};

View File

@ -62,11 +62,13 @@ public class StreamManager
if (user == default) throw new Exception("No stream key found");
const long balanceAlertThreshold = 500;
const double rate = 21.0d; // 21 sats/min
var cost = Math.Round(rate * (duration / 60d));
var cost = (int)Math.Ceiling(_config.Cost * (duration / 60d));
if (cost > 0)
{
await _db.Users
.Where(a => a.PubKey == user.PubKey)
.ExecuteUpdateAsync(o => o.SetProperty(v => v.Balance, v => v.Balance - cost));
}
_logger.LogInformation("Stream consumed {n} seconds for {pubkey} costing {cost} sats", duration, user.PubKey, cost);
if (user.Balance >= balanceAlertThreshold && user.Balance - cost < balanceAlertThreshold)

View File

@ -7,6 +7,7 @@ services:
- "1935:1935"
- "1985:1985"
- "8082:8080"
- "8003:8000"
nostr:
image: scsibug/nostr-rs-relay
ports:

View File

@ -10,6 +10,11 @@ http_server {
enabled on;
listen 8080;
}
rtc_server {
enabled on;
listen 8000;
candidate *;
}
vhost __defaultVhost__ {
hls {
enabled on;
@ -23,4 +28,13 @@ vhost __defaultVhost__ {
on_unpublish http://10.100.2.226:5295/api/srs;
on_hls http://10.100.2.226:5295/api/srs;
}
rtc {
enabled on;
rtmp_to_rtc on;
rtc_to_rtmp on;
}
http_remux {
enabled on;
mount [vhost]/[app]/[stream].ts;
}
}