Repository navigation
Expand file tree
/
Copy pathManager.java
More file actions
153 lines (118 loc) · 3.46 KB
/
Copy pathManager.java
File metadata and controls
153 lines (118 loc) · 3.46 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package org.tron.core.db;
import com.google.protobuf.ByteString;
import java.util.ArrayList;
import java.util.List;
import org.tron.core.capsule.TransactionCapsule;
import org.tron.core.capsule.WitnessCapsule;
import org.tron.protos.Protocal;
import org.tron.protos.Protocal.Transaction;
public class Manager {
private AccountStore accountStore;
private TransactionStore transactionStore;
private BlockStore blockStore;
private UtxoStore utxoStore;
private WitnessStore witnessStore;
public WitnessStore getWitnessStore() {
return witnessStore;
}
private void setWitnessStore(WitnessStore witnessStore) {
this.witnessStore = witnessStore;
}
public List<Transaction> getPendingTrxs() {
return pendingTrxs;
}
// transaction cache
private List<Transaction> pendingTrxs;
// witness
public List<WitnessCapsule> getWitnesses() {
List<WitnessCapsule> wits = new ArrayList<WitnessCapsule>();
wits.add(new WitnessCapsule(ByteString.copyFromUtf8("0x12")));
wits.add(new WitnessCapsule(ByteString.copyFromUtf8("0x11")));
return wits;
}
public List<WitnessCapsule> getCurrentShuffledWitnesses() {
return getWitnesses();
}
public ByteString getScheduledWitness(long slot) {
if (slot < 0) {
throw new RuntimeException("currentSlot should be positive.");
}
List<WitnessCapsule> currentShuffledWitnesses = getShuffledWitnesses();
if (currentShuffledWitnesses == null || currentShuffledWitnesses.size() == 0) {
throw new RuntimeException("ShuffledWitnesses is null.");
}
int witnessIndex = (int) slot % currentShuffledWitnesses.size();
return currentShuffledWitnesses.get(witnessIndex).getAddress();
}
public List<WitnessCapsule> getShuffledWitnesses() {
return getWitnesses();
}
/**
* all db should be init here.
*/
public void init() {
setAccountStore(AccountStore.create("account"));
setTransactionStore(TransactionStore.create("trans"));
setBlockStore(BlockStore.create("block"));
setUtxoStore(UtxoStore.create("utxo"));
setWitnessStore(WitnessStore.create("witness"));
pendingTrxs = new ArrayList<>();
}
public AccountStore getAccountStore() {
return accountStore;
}
public void pushTrx(Transaction trx) {
this.pendingTrxs.add(trx);
}
/**
* Process transaction.
*/
public void processTrx(TransactionCapsule trxCap) {
if (!trxCap.validate()) {
return;
}
Transaction trx = trxCap.getTransaction();
switch (trx.getType()) {
case Transfer:
break;
case VoteWitess:
break;
case CreateAccount:
break;
case DeployContract:
break;
default:
break;
}
}
/**
* Generate a block.
*/
public Protocal.Block generateBlock() {
for (Transaction trx : pendingTrxs) {
}
//todo
return Protocal.Block.getDefaultInstance();
}
private void setAccountStore(AccountStore accountStore) {
this.accountStore = accountStore;
}
public TransactionStore getTransactionStore() {
return transactionStore;
}
private void setTransactionStore(TransactionStore transactionStore) {
this.transactionStore = transactionStore;
}
public BlockStore getBlockStore() {
return blockStore;
}
private void setBlockStore(BlockStore blockStore) {
this.blockStore = blockStore;
}
public UtxoStore getUtxoStore() {
return utxoStore;
}
private void setUtxoStore(UtxoStore utxoStore) {
this.utxoStore = utxoStore;
}
}