forked from tronprotocol/java-tron
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPeerBuilder.java
More file actions
60 lines (50 loc) · 1.34 KB
/
PeerBuilder.java
File metadata and controls
60 lines (50 loc) · 1.34 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
package org.tron.peer;
import javax.inject.Inject;
import org.tron.consensus.client.BlockchainClientListener;
import org.tron.consensus.client.Client;
import org.tron.core.Blockchain;
import org.tron.core.UTXOSet;
import org.tron.crypto.ECKey;
import org.tron.utils.ByteArray;
import org.tron.wallet.Wallet;
/**
* Builds a peer
* <p>
* Set the key and type before calling build
*/
public class PeerBuilder {
private Blockchain blockchain;
private UTXOSet utxoSet;
private Wallet wallet;
private ECKey key;
private String type;
private Client client;
@Inject
public PeerBuilder(Blockchain blockchain, UTXOSet utxoSet, Client client) {
this.blockchain = blockchain;
this.utxoSet = utxoSet;
this.client = client;
}
private void buildWallet() {
if (key == null) {
throw new IllegalStateException("Key must be set before building the wallet");
}
wallet = new Wallet(key);
}
public PeerBuilder setType(String type) {
this.type = type;
return this;
}
public PeerBuilder setKey(ECKey key) {
this.key = key;
return this;
}
public Peer build() {
buildWallet();
utxoSet.reindex();
Peer peer = new Peer(type, blockchain, utxoSet, wallet, client, key);
//peer.setClient(client);
//blockchain.addListener(new BlockchainClientListener(client, peer));
return peer;
}
}