-
Notifications
You must be signed in to change notification settings - Fork 3
/
account.js
54 lines (45 loc) · 1.17 KB
/
account.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
44
45
46
47
48
49
50
51
52
53
54
class Account {
constructor() {
this.addresses = [
"5aad9b5e21f63955e8840e8b954926c60e0e2d906fdbc0ce1e3afe249a67f614"
];
this.balance = {
"5aad9b5e21f63955e8840e8b954926c60e0e2d906fdbc0ce1e3afe249a67f614": 1000
};
}
initialize(address) {
if (this.balance[address] == undefined) {
this.balance[address] = 0;
this.addresses.push(address);
}
}
transfer(from, to, amount) {
this.initialize(from);
this.initialize(to);
this.increment(to, amount);
this.decrement(from, amount);
}
increment(to, amount) {
this.balance[to] += amount;
}
decrement(from, amount) {
this.balance[from] -= amount;
}
getBalance(address) {
this.initialize(address);
return this.balance[address];
}
update(transaction) {
let amount = transaction.output.amount;
let from = transaction.input.from;
let to = transaction.output.to;
this.transfer(from, to, amount);
}
transferFee(block, transaction) {
let amount = transaction.output.fee;
let from = transaction.input.from;
let to = block.validator;
this.transfer(from, to, amount);
}
}
module.exports = Account;