forked from amir-ashy/Blockchain
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransactionPool.cs
More file actions
45 lines (40 loc) · 1.04 KB
/
TransactionPool.cs
File metadata and controls
45 lines (40 loc) · 1.04 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
using Blockchain.Model;
using System.Collections.Generic;
using System.Linq;
namespace Blockchain
{
public class TransactionPool
{
private List<Transaction> rawTransactionList;
private object lockObj;
public TransactionPool()
{
lockObj = new object();
rawTransactionList = new List<Transaction>();
}
public void AddRaw(Transaction transaction)
{
lock (lockObj)
{
rawTransactionList.Add(transaction);
}
}
public void AddRaw(string from, string to, int amount)
{
var transaction = new Transaction(from, to, amount);
lock (lockObj)
{
rawTransactionList.Add(transaction);
}
}
public List<Transaction> TakeAll()
{
lock (lockObj)
{
var all = rawTransactionList.ToList();
rawTransactionList.Clear();
return all;
}
}
}
}