-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGroupManager.cs
More file actions
89 lines (71 loc) · 2.16 KB
/
GroupManager.cs
File metadata and controls
89 lines (71 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//using BitcoinLib.Responses;
//using FluidMixer.AddressUtil;
using NBitcoin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace MixerFront
{
public class GroupManager
{
private object _lock = new object();
private Dictionary<string, Group> Groups = new Dictionary<string, Group>();
public static NBitcoin.Network SelectedNetwork = NBitcoin.Network.Main;
public GroupManager()
{
}
public Group CreateNewGroup(string gid, decimal amount, NBitcoin.Network n = null)
{
// TODO: group manager to decide if 'amount' is OK
// based on active usage and how much is in the vault
//
if (n == null)
n = Bitcoin.Instance.Mainnet;
Group g = new Group(gid, amount, n);
if (!AddGroup(g))
return null;
return g;
}
public Group CreateNewGroup(decimal amount, NBitcoin.Network n = null)
{
Random rnd = new Random();
string gid = $"grp_{(rnd.Next(0, int.MaxValue)).ToString("X8")}";
return CreateNewGroup(gid, amount, n);
}
public Group GetGroupBySessionId(string sessionId)
{
lock (_lock)
{
//foreach(var g in )
if (!Groups.ContainsKey(sessionId))
return null;
return Groups[sessionId];
}
//return null;
}
// NOTE: only do on empty group?
public bool AddGroup(Group g)
{
lock (_lock)
{
if (Groups.ContainsKey(g.SessionId))
return false;
Groups.Add(g.SessionId, g);
}
return true;
}
public bool RemoveGroups(Group g)
{
lock (_lock)
{
if (!Groups.ContainsKey(g.SessionId))
return false;
Groups.Remove(g.SessionId);
}
return true;
}
}
}