3
3
import com .google .inject .AbstractModule ;
4
4
import com .google .inject .Provides ;
5
5
import com .google .inject .Singleton ;
6
+ import com .strategyobject .substrateclient .api .pallet .balances .AccountData ;
7
+ import com .strategyobject .substrateclient .api .pallet .balances .AccountDataReader ;
8
+ import com .strategyobject .substrateclient .api .pallet .system .System ;
9
+ import com .strategyobject .substrateclient .common .types .Lambda ;
6
10
import com .strategyobject .substrateclient .crypto .ss58 .SS58AddressFormat ;
7
11
import com .strategyobject .substrateclient .pallet .GeneratedPalletFactory ;
8
12
import com .strategyobject .substrateclient .pallet .PalletFactory ;
13
+ import com .strategyobject .substrateclient .pallet .events .EventDescriptor ;
14
+ import com .strategyobject .substrateclient .pallet .events .EventDescriptorReader ;
15
+ import com .strategyobject .substrateclient .pallet .events .EventRegistry ;
9
16
import com .strategyobject .substrateclient .rpc .GeneratedRpcSectionFactory ;
10
17
import com .strategyobject .substrateclient .rpc .RpcSectionFactory ;
11
18
import com .strategyobject .substrateclient .rpc .api .section .State ;
@@ -35,12 +42,12 @@ public class DefaultModule extends AbstractModule {
35
42
36
43
private final @ NonNull ProviderInterface providerInterface ;
37
44
38
- private Consumer <ScaleReaderRegistry > configureScaleReaderRegistry = x -> x . registerAnnotatedFrom ( PREFIX ) ;
39
- private Consumer <ScaleWriterRegistry > configureScaleWriterRegistry = x -> x . registerAnnotatedFrom ( PREFIX ) ;
40
- private BiConsumer <RpcDecoderRegistry , RpcDecoderContextFactory > configureRpcDecoderRegistry =
41
- ( registry , contextFactory ) -> registry . registerAnnotatedFrom ( contextFactory , PREFIX ) ;
42
- private BiConsumer < RpcEncoderRegistry , RpcEncoderContextFactory > configureRpcEncoderRegistry =
43
- ( registry , contextFactory ) -> registry . registerAnnotatedFrom ( contextFactory , PREFIX );
45
+ private Consumer <ScaleReaderRegistry > configureScaleReaderRegistry = Lambda :: noop ;
46
+ private Consumer <ScaleWriterRegistry > configureScaleWriterRegistry = Lambda :: noop ;
47
+ private BiConsumer <RpcDecoderRegistry , RpcDecoderContextFactory > configureRpcDecoderRegistry = Lambda :: noop ;
48
+ private BiConsumer < RpcEncoderRegistry , RpcEncoderContextFactory > configureRpcEncoderRegistry = Lambda :: noop ;
49
+ private Consumer < EventRegistry > configureEventRegistry = Lambda :: noop ;
50
+
44
51
45
52
public DefaultModule configureScaleReaderRegistry (Consumer <ScaleReaderRegistry > configure ) {
46
53
configureScaleReaderRegistry = configureScaleReaderRegistry .andThen (configure );
@@ -62,6 +69,11 @@ public DefaultModule configureRpcEncoderRegistry(BiConsumer<RpcEncoderRegistry,
62
69
return this ;
63
70
}
64
71
72
+ public DefaultModule configureEventRegistry (Consumer <EventRegistry > configure ) {
73
+ configureEventRegistry = configureEventRegistry .andThen (configure );
74
+ return this ;
75
+ }
76
+
65
77
@ Override
66
78
protected void configure () {
67
79
try {
@@ -97,8 +109,13 @@ protected void configure() {
97
109
98
110
@ Provides
99
111
@ Singleton
100
- public ScaleReaderRegistry provideScaleReaderRegistry () {
112
+ public ScaleReaderRegistry provideScaleReaderRegistry (MetadataProvider metadataProvider ,
113
+ EventRegistry eventRegistry ) {
101
114
val registry = new ScaleReaderRegistry ();
115
+ registry .registerAnnotatedFrom (PREFIX );
116
+ registry .register (new AccountDataReader (registry ), System .AccountData .class , AccountData .class );
117
+ registry .register (new EventDescriptorReader (registry , metadataProvider , eventRegistry ), EventDescriptor .class );
118
+
102
119
configureScaleReaderRegistry .accept (registry );
103
120
return registry ;
104
121
}
@@ -107,6 +124,8 @@ public ScaleReaderRegistry provideScaleReaderRegistry() {
107
124
@ Singleton
108
125
public ScaleWriterRegistry provideScaleWriterRegistry () {
109
126
val registry = new ScaleWriterRegistry ();
127
+ registry .registerAnnotatedFrom (PREFIX );
128
+
110
129
configureScaleWriterRegistry .accept (registry );
111
130
return registry ;
112
131
}
@@ -120,6 +139,7 @@ public RpcDecoderRegistry provideRpcDecoderRegistry(MetadataProvider metadataPro
120
139
metadataProvider ,
121
140
registry ,
122
141
scaleReaderRegistry );
142
+ registry .registerAnnotatedFrom (() -> context , PREFIX );
123
143
124
144
configureRpcDecoderRegistry .accept (registry , () -> context );
125
145
return registry ;
@@ -134,11 +154,22 @@ public RpcEncoderRegistry provideRpcEncoderRegistry(MetadataProvider metadataPro
134
154
metadataProvider ,
135
155
registry ,
136
156
scaleWriterRegistry );
157
+ registry .registerAnnotatedFrom (() -> context , PREFIX );
137
158
138
159
configureRpcEncoderRegistry .accept (registry , () -> context );
139
160
return registry ;
140
161
}
141
162
163
+ @ Provides
164
+ @ Singleton
165
+ public EventRegistry provideEventRegistry () {
166
+ val registry = new EventRegistry ();
167
+ registry .registerAnnotatedFrom (PREFIX );
168
+
169
+ configureEventRegistry .accept (registry );
170
+ return registry ;
171
+ }
172
+
142
173
@ Provides
143
174
@ Singleton
144
175
public MetadataProvider provideMetadata () {
0 commit comments