27
27
import lombok .AllArgsConstructor ;
28
28
import lombok .Value ;
29
29
import lombok .extern .slf4j .Slf4j ;
30
+ import org .ethereum .config .SystemProperties ;
30
31
import org .ethereum .core .*;
31
32
import org .ethereum .crypto .ECKey ;
32
33
import org .ethereum .db .ByteArrayWrapper ;
@@ -102,6 +103,9 @@ public class WalletService {
102
103
103
104
EmbeddedDatabase wordsDatabase ;
104
105
106
+ @ Autowired
107
+ SystemProperties config ;
108
+
105
109
/**
106
110
* key - hex address in lower case
107
111
* value - address user friendly name
@@ -111,6 +115,8 @@ public class WalletService {
111
115
final Map <String , TransactionInfo > pendingSendTransactions = new ConcurrentHashMap <>();
112
116
final Map <String , TransactionInfo > pendingReceiveTransactions = new ConcurrentHashMap <>();
113
117
118
+ private boolean subscribedForEvents ;
119
+
114
120
@ PostConstruct
115
121
public void init () {
116
122
addresses .clear ();
@@ -122,24 +128,36 @@ public void init() {
122
128
fileSystemWalletStore .fromStore ().stream ()
123
129
.forEach (a -> addresses .put (a .address , a .name ));
124
130
125
- ethereum .addListener (new EthereumListenerAdapter () {
126
- @ Override
127
- public void onSyncDone (SyncState state ) {
128
- if (state == SyncState .UNSECURE ) {
129
- ethereum .addListener (new EthereumListenerAdapter () {
130
- @ Override
131
- public void onPendingTransactionsReceived (List <Transaction > list ) {
132
- handlePendingTransactionsReceived (list );
133
- }
134
-
135
- @ Override
136
- public void onBlock (BlockSummary blockSummary ) {
137
- handleBlock (blockSummary );
138
- }
139
- });
131
+ // workaround issue in ethereumJ-core, where single miner could never got sync done event
132
+ if (config .minerStart ()) {
133
+ subscribeOnce ();
134
+ } else {
135
+ ethereum .addListener (new EthereumListenerAdapter () {
136
+ @ Override
137
+ public void onSyncDone (SyncState state ) {
138
+ if (state == SyncState .UNSECURE || state == SyncState .COMPLETE ) {
139
+ subscribeOnce ();
140
+ }
140
141
}
141
- }
142
- });
142
+ });
143
+ }
144
+ }
145
+
146
+ private void subscribeOnce () {
147
+ if (!subscribedForEvents ) {
148
+ subscribedForEvents = true ;
149
+ ethereum .addListener (new EthereumListenerAdapter () {
150
+ @ Override
151
+ public void onPendingTransactionsReceived (List <Transaction > list ) {
152
+ handlePendingTransactionsReceived (list );
153
+ }
154
+
155
+ @ Override
156
+ public void onBlock (BlockSummary blockSummary ) {
157
+ handleBlock (blockSummary );
158
+ }
159
+ });
160
+ }
143
161
}
144
162
145
163
public void handleBlock (BlockSummary blockSummary ) {
0 commit comments