Adjust rates
This commit is contained in:
@ -36,6 +36,11 @@ public class Config
|
|||||||
public string[] Relays { get; init; } = Array.Empty<string>();
|
public string[] Relays { get; init; } = Array.Empty<string>();
|
||||||
|
|
||||||
public LndConfig Lnd { get; init; } = null!;
|
public LndConfig Lnd { get; init; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cost/min
|
||||||
|
/// </summary>
|
||||||
|
public int Cost { get; init; } = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LndConfig
|
public class LndConfig
|
||||||
|
@ -57,7 +57,7 @@ public class NostrController : Controller
|
|||||||
Quota = new()
|
Quota = new()
|
||||||
{
|
{
|
||||||
Unit = "min",
|
Unit = "min",
|
||||||
Rate = 21,
|
Rate = _config.Cost,
|
||||||
Remaining = user.Balance
|
Remaining = user.Balance
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -62,11 +62,13 @@ public class StreamManager
|
|||||||
if (user == default) throw new Exception("No stream key found");
|
if (user == default) throw new Exception("No stream key found");
|
||||||
|
|
||||||
const long balanceAlertThreshold = 500;
|
const long balanceAlertThreshold = 500;
|
||||||
const double rate = 21.0d; // 21 sats/min
|
var cost = (int)Math.Ceiling(_config.Cost * (duration / 60d));
|
||||||
var cost = Math.Round(rate * (duration / 60d));
|
if (cost > 0)
|
||||||
await _db.Users
|
{
|
||||||
.Where(a => a.PubKey == user.PubKey)
|
await _db.Users
|
||||||
.ExecuteUpdateAsync(o => o.SetProperty(v => v.Balance, v => v.Balance - cost));
|
.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);
|
_logger.LogInformation("Stream consumed {n} seconds for {pubkey} costing {cost} sats", duration, user.PubKey, cost);
|
||||||
if (user.Balance >= balanceAlertThreshold && user.Balance - cost < balanceAlertThreshold)
|
if (user.Balance >= balanceAlertThreshold && user.Balance - cost < balanceAlertThreshold)
|
||||||
|
@ -7,6 +7,7 @@ services:
|
|||||||
- "1935:1935"
|
- "1935:1935"
|
||||||
- "1985:1985"
|
- "1985:1985"
|
||||||
- "8082:8080"
|
- "8082:8080"
|
||||||
|
- "8003:8000"
|
||||||
nostr:
|
nostr:
|
||||||
image: scsibug/nostr-rs-relay
|
image: scsibug/nostr-rs-relay
|
||||||
ports:
|
ports:
|
||||||
|
@ -10,6 +10,11 @@ http_server {
|
|||||||
enabled on;
|
enabled on;
|
||||||
listen 8080;
|
listen 8080;
|
||||||
}
|
}
|
||||||
|
rtc_server {
|
||||||
|
enabled on;
|
||||||
|
listen 8000;
|
||||||
|
candidate *;
|
||||||
|
}
|
||||||
vhost __defaultVhost__ {
|
vhost __defaultVhost__ {
|
||||||
hls {
|
hls {
|
||||||
enabled on;
|
enabled on;
|
||||||
@ -23,4 +28,13 @@ vhost __defaultVhost__ {
|
|||||||
on_unpublish http://10.100.2.226:5295/api/srs;
|
on_unpublish http://10.100.2.226:5295/api/srs;
|
||||||
on_hls 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user