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 .common . types . AutoRegistry ;
6
+ import com .strategyobject .substrateclient .crypto . ss58 . SS58AddressFormat ;
7
7
import com .strategyobject .substrateclient .pallet .GeneratedPalletFactory ;
8
8
import com .strategyobject .substrateclient .pallet .PalletFactory ;
9
9
import com .strategyobject .substrateclient .rpc .GeneratedRpcSectionFactory ;
10
10
import com .strategyobject .substrateclient .rpc .RpcSectionFactory ;
11
11
import com .strategyobject .substrateclient .rpc .api .section .State ;
12
+ import com .strategyobject .substrateclient .rpc .context .RpcDecoderContext ;
13
+ import com .strategyobject .substrateclient .rpc .context .RpcDecoderContextFactory ;
14
+ import com .strategyobject .substrateclient .rpc .context .RpcEncoderContext ;
15
+ import com .strategyobject .substrateclient .rpc .context .RpcEncoderContextFactory ;
16
+ import com .strategyobject .substrateclient .rpc .metadata .ManualMetadataProvider ;
17
+ import com .strategyobject .substrateclient .rpc .metadata .MetadataProvider ;
18
+ import com .strategyobject .substrateclient .rpc .metadata .Pallet ;
19
+ import com .strategyobject .substrateclient .rpc .metadata .PalletCollection ;
12
20
import com .strategyobject .substrateclient .rpc .registries .RpcDecoderRegistry ;
13
21
import com .strategyobject .substrateclient .rpc .registries .RpcEncoderRegistry ;
14
22
import com .strategyobject .substrateclient .scale .registries .ScaleReaderRegistry ;
18
26
import lombok .RequiredArgsConstructor ;
19
27
import lombok .val ;
20
28
29
+ import java .util .function .BiConsumer ;
21
30
import java .util .function .Consumer ;
22
31
23
32
@ RequiredArgsConstructor
24
33
public class DefaultModule extends AbstractModule {
25
- private final @ NonNull ProviderInterface providerInterface ;
34
+ private static final String PREFIX = "com.strategyobject.substrateclient" ;
26
35
27
- private Consumer <ScaleReaderRegistry > configureScaleReaderRegistry = this ::autoRegister ;
28
- private Consumer <ScaleWriterRegistry > configureScaleWriterRegistry = this ::autoRegister ;
29
- private Consumer <RpcDecoderRegistry > configureRpcDecoderRegistry = this ::autoRegister ;
30
- private Consumer <RpcEncoderRegistry > configureRpcEncoderRegistry = this ::autoRegister ;
36
+ private final @ NonNull ProviderInterface providerInterface ;
31
37
32
- private void autoRegister (AutoRegistry registry ) {
33
- registry .registerAnnotatedFrom ("com.strategyobject.substrateclient" );
34
- }
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 );
35
44
36
45
public DefaultModule configureScaleReaderRegistry (Consumer <ScaleReaderRegistry > configure ) {
37
46
configureScaleReaderRegistry = configureScaleReaderRegistry .andThen (configure );
@@ -43,12 +52,12 @@ public DefaultModule configureScaleWriterRegistry(Consumer<ScaleWriterRegistry>
43
52
return this ;
44
53
}
45
54
46
- public DefaultModule configureRpcDecoderRegistry (Consumer <RpcDecoderRegistry > configure ) {
55
+ public DefaultModule configureRpcDecoderRegistry (BiConsumer <RpcDecoderRegistry , RpcDecoderContextFactory > configure ) {
47
56
configureRpcDecoderRegistry = configureRpcDecoderRegistry .andThen (configure );
48
57
return this ;
49
58
}
50
59
51
- public DefaultModule configureRpcEncoderRegistry (Consumer <RpcEncoderRegistry > configure ) {
60
+ public DefaultModule configureRpcEncoderRegistry (BiConsumer <RpcEncoderRegistry , RpcEncoderContextFactory > configure ) {
52
61
configureRpcEncoderRegistry = configureRpcEncoderRegistry .andThen (configure );
53
62
return this ;
54
63
}
@@ -78,7 +87,8 @@ protected void configure() {
78
87
.toConstructor (
79
88
Api .class .getConstructor (
80
89
RpcSectionFactory .class ,
81
- PalletFactory .class ))
90
+ PalletFactory .class ,
91
+ MetadataProvider .class ))
82
92
.asEagerSingleton ();
83
93
} catch (NoSuchMethodException e ) {
84
94
throw new RuntimeException (e );
@@ -103,20 +113,77 @@ public ScaleWriterRegistry provideScaleWriterRegistry() {
103
113
104
114
@ Provides
105
115
@ Singleton
106
- public RpcDecoderRegistry provideRpcDecoderRegistry (ScaleReaderRegistry scaleReaderRegistry ) {
107
- val registry = new RpcDecoderRegistry (scaleReaderRegistry );
108
- configureRpcDecoderRegistry .accept (registry );
116
+ public RpcDecoderRegistry provideRpcDecoderRegistry (MetadataProvider metadataProvider ,
117
+ ScaleReaderRegistry scaleReaderRegistry ) {
118
+ val registry = new RpcDecoderRegistry ();
119
+ val context = new RpcDecoderContext (
120
+ metadataProvider ,
121
+ registry ,
122
+ scaleReaderRegistry );
123
+
124
+ configureRpcDecoderRegistry .accept (registry , () -> context );
109
125
return registry ;
110
126
}
111
127
112
128
@ Provides
113
129
@ Singleton
114
- public RpcEncoderRegistry provideRpcEncoderRegistry (ScaleWriterRegistry scaleWriterRegistry ) {
115
- val registry = new RpcEncoderRegistry (scaleWriterRegistry );
116
- configureRpcEncoderRegistry .accept (registry );
130
+ public RpcEncoderRegistry provideRpcEncoderRegistry (MetadataProvider metadataProvider ,
131
+ ScaleWriterRegistry scaleWriterRegistry ) {
132
+ val registry = new RpcEncoderRegistry ();
133
+ val context = new RpcEncoderContext (
134
+ metadataProvider ,
135
+ registry ,
136
+ scaleWriterRegistry );
137
+
138
+ configureRpcEncoderRegistry .accept (registry , () -> context );
117
139
return registry ;
118
140
}
119
141
142
+ @ Provides
143
+ @ Singleton
144
+ public MetadataProvider provideMetadata () {
145
+ // TODO. Use provider based on real Metadata
146
+ return new ManualMetadataProvider (
147
+ SS58AddressFormat .SUBSTRATE_ACCOUNT ,
148
+ new PalletCollection (
149
+ new Pallet (0 , "System" ),
150
+ new Pallet (1 , "Utility" ),
151
+ new Pallet (2 , "Babe" ),
152
+ new Pallet (3 , "Timestamp" ),
153
+ new Pallet (4 , "Authorship" ),
154
+ new Pallet (5 , "Indices" ),
155
+ new Pallet (6 , "Balances" ),
156
+ new Pallet (7 , "TransactionPayment" ),
157
+ new Pallet (8 , "Staking" ),
158
+ new Pallet (9 , "Session" ),
159
+ new Pallet (10 , "Democracy" ),
160
+ new Pallet (11 , "Council" ),
161
+ new Pallet (12 , "TechnicalCommittee" ),
162
+ new Pallet (13 , "Elections" ),
163
+ new Pallet (14 , "TechnicalMembership" ),
164
+ new Pallet (15 , "Grandpa" ),
165
+ new Pallet (16 , "Treasury" ),
166
+ new Pallet (17 , "Contracts" ),
167
+ new Pallet (18 , "Sudo" ),
168
+ new Pallet (19 , "ImOnline" ),
169
+ new Pallet (20 , "AuthorityDiscovery" ),
170
+ new Pallet (21 , "Offences" ),
171
+ new Pallet (22 , "Historical" ),
172
+ new Pallet (23 , "RandomnessCollectiveFlip" ),
173
+ new Pallet (24 , "Identity" ),
174
+ new Pallet (25 , "Society" ),
175
+ new Pallet (26 , "Recovery" ),
176
+ new Pallet (27 , "Vesting" ),
177
+ new Pallet (28 , "Scheduler" ),
178
+ new Pallet (29 , "Proxy" ),
179
+ new Pallet (30 , "Multisig" ),
180
+ new Pallet (31 , "Bounties" ),
181
+ new Pallet (32 , "Tips" ),
182
+ new Pallet (33 , "Assets" ),
183
+ new Pallet (34 , "Mmr" ),
184
+ new Pallet (35 , "Lottery" )));
185
+ }
186
+
120
187
@ Provides
121
188
@ Singleton
122
189
public State provideState (RpcSectionFactory rpcSectionFactory ) {
0 commit comments