-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtransaction-pool.js
43 lines (36 loc) · 1.07 KB
/
transaction-pool.js
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
// Import transaction class used for verification
const Transaction = require("./transaction");
// Transaction threshold is the limit or the holding capacity of the nodes
// Once this exceeds a new block is generated
const { TRANSACTION_THRESHOLD } = require("./config");
class TransactionPool {
constructor() {
this.transactions = [];
}
// pushes transactions in the list
// returns true if it is full
// else returns false
addTransaction(transaction) {
this.transactions.push(transaction);
if (this.transactions.length >= TRANSACTION_THRESHOLD) {
return true;
} else {
return false;
}
}
// wrapper function to verify transactions
verifyTransaction(transaction) {
return Transaction.verifyTransaction(transaction);
}
// checks if transactions exists or not
transactionExists(transaction) {
let exists = this.transactions.find(t => t.id === transaction.id);
return exists;
}
// empties the pool
clear() {
console.log("TRANSACTION POOL CLEARED");
this.transactions = [];
}
}
module.exports = TransactionPool;