5
5
import com .strategyobject .substrateclient .rpc .RpcGeneratedSectionFactory ;
6
6
import com .strategyobject .substrateclient .rpc .api .AccountId ;
7
7
import com .strategyobject .substrateclient .rpc .api .BlockHash ;
8
+ import com .strategyobject .substrateclient .rpc .api .BlockNumber ;
8
9
import com .strategyobject .substrateclient .rpc .api .section .Chain ;
9
10
import com .strategyobject .substrateclient .rpc .api .section .State ;
10
11
import com .strategyobject .substrateclient .scale .ScaleReader ;
@@ -48,8 +49,8 @@ private static StorageNMapImpl<BlockHash> newSystemBlockHashStorage(State state)
48
49
state ,
49
50
(ScaleReader <BlockHash >) ScaleReaderRegistry .getInstance ().resolve (BlockHash .class ),
50
51
StorageKeyProvider .of ("System" , "BlockHash" )
51
- .use (KeyHasher .with ((ScaleWriter <Integer >) ScaleWriterRegistry .getInstance ().resolve (Integer .class ),
52
- (ScaleReader <Integer >) ScaleReaderRegistry .getInstance ().resolve (Integer .class ),
52
+ .use (KeyHasher .with ((ScaleWriter <BlockNumber >) ScaleWriterRegistry .getInstance ().resolve (BlockNumber .class ),
53
+ (ScaleReader <BlockNumber >) ScaleReaderRegistry .getInstance ().resolve (BlockNumber .class ),
53
54
TwoX64Concat .getInstance ())));
54
55
}
55
56
@@ -74,10 +75,10 @@ void keys() throws Exception {
74
75
assertNotNull (collection );
75
76
assertEquals (1 , collection .size ());
76
77
77
- val blockNumber = new AtomicReference <Integer >(null );
78
- collection .iterator ().forEachRemaining (q -> q .consume ((o -> blockNumber .set ((Integer ) o .get (0 )))));
78
+ val blockNumber = new AtomicReference <BlockNumber >(null );
79
+ collection .iterator ().forEachRemaining (q -> q .consume ((o -> blockNumber .set ((BlockNumber ) o .get (0 )))));
79
80
80
- assertEquals (0 , blockNumber .get ());
81
+ assertEquals (BlockNumber . GENESIS , blockNumber .get ());
81
82
82
83
val blocks = collection .multi ().execute ().get ();
83
84
val list = new ArrayList <>();
@@ -101,7 +102,7 @@ void multiToDifferentStorages() throws Exception {
101
102
val storageMap = newSystemBlockHashStorage (state );
102
103
103
104
val getKey = storageValue .query ();
104
- val getHash = storageMap .query (0 );
105
+ val getHash = storageMap .query (BlockNumber . GENESIS );
105
106
106
107
val multi = getKey .join (getHash );
107
108
val collection = multi .execute ().get ();
@@ -110,7 +111,7 @@ void multiToDifferentStorages() throws Exception {
110
111
SS58Codec .decode (
111
112
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" )
112
113
.getAddress ());
113
- val expectedBlock = storageMap .get (0 ).get ();
114
+ val expectedBlock = storageMap .get (BlockNumber . GENESIS ).get ();
114
115
115
116
val list = new ArrayList <>(2 );
116
117
collection .iterator ().forEachRemaining (e -> e .consume ((value , keys ) -> list .add (value )));
@@ -130,14 +131,14 @@ void entries() throws Exception {
130
131
131
132
assertNotNull (collection );
132
133
133
- val blockNumber = new AtomicReference <Integer >(null );
134
+ val blockNumber = new AtomicReference <BlockNumber >(null );
134
135
val blockHash = new AtomicReference <BlockHash >(null );
135
136
collection .iterator ().forEachRemaining (e -> e .consume ((value , keys ) -> {
136
137
blockHash .set (value );
137
- blockNumber .set ((Integer ) keys .get (0 ));
138
+ blockNumber .set ((BlockNumber ) keys .get (0 ));
138
139
}));
139
140
140
- assertEquals (0 , blockNumber .get ());
141
+ assertEquals (BlockNumber . GENESIS , blockNumber .get ());
141
142
assertNotEquals (BigInteger .ZERO , new BigInteger (blockHash .get ().getData ()));
142
143
}
143
144
}
@@ -148,18 +149,24 @@ void multi() throws Exception {
148
149
val state = RpcGeneratedSectionFactory .create (State .class , wsProvider );
149
150
val storage = newSystemBlockHashStorage (state );
150
151
151
- val collection = storage .multi (Arg .of (0 ), Arg .of (1 )).get ();
152
+ val collection = storage .multi (
153
+ Arg .of (BlockNumber .GENESIS ),
154
+ Arg .of (BlockNumber .of (1 )))
155
+ .get ();
152
156
assertNotNull (collection );
153
157
154
- val list = new ArrayList <Pair <Integer , BlockHash >>();
155
- collection .iterator ().forEachRemaining (e -> e .consume ((value , keys ) -> list .add (Pair .of ((Integer ) keys .get (0 ), value ))));
158
+ val list = new ArrayList <Pair <BlockNumber , BlockHash >>();
159
+ collection .iterator ()
160
+ .forEachRemaining (e ->
161
+ e .consume ((value , keys ) ->
162
+ list .add (Pair .of ((BlockNumber ) keys .get (0 ), value ))));
156
163
157
164
assertEquals (2 , list .size ());
158
165
159
- assertEquals (0 , list .get (0 ).getValue0 ());
166
+ assertEquals (BlockNumber . GENESIS , list .get (0 ).getValue0 ());
160
167
assertNotEquals (BigInteger .ZERO , new BigInteger (list .get (0 ).getValue1 ().getData ()));
161
168
162
- assertEquals (1 , list .get (1 ).getValue0 ());
169
+ assertEquals (BlockNumber . of ( 1 ) , list .get (1 ).getValue0 ());
163
170
assertNull (list .get (1 ).getValue1 ());
164
171
}
165
172
}
@@ -204,14 +211,17 @@ void entriesPaged() throws Exception {
204
211
assertNotNull (pages );
205
212
206
213
var pageCount = 0 ;
207
- val pairs = new ArrayList <Pair <Integer , BlockHash >>();
214
+ val pairs = new ArrayList <Pair <BlockNumber , BlockHash >>();
208
215
while (pages .moveNext ().join ()) {
209
- pages .current ().iterator ().forEachRemaining (e -> e .consume ((value , keys ) -> {
210
- val key = (Integer ) keys .get (0 );
211
- assertNotEquals (BigInteger .ZERO , new BigInteger (value .getData ()));
212
-
213
- pairs .add (Pair .of (key , value ));
214
- }));
216
+ pages .current ()
217
+ .iterator ()
218
+ .forEachRemaining (e ->
219
+ e .consume ((value , keys ) -> {
220
+ val key = (BlockNumber ) keys .get (0 );
221
+ assertNotEquals (BigInteger .ZERO , new BigInteger (value .getData ()));
222
+
223
+ pairs .add (Pair .of (key , value ));
224
+ }));
215
225
pageCount ++;
216
226
assertEquals (pageCount , pages .number ());
217
227
}
@@ -227,16 +237,16 @@ void entriesPaged() throws Exception {
227
237
void subscribe () throws Exception {
228
238
try (val wsProvider = getConnectedProvider ()) {
229
239
val state = RpcGeneratedSectionFactory .create (State .class , wsProvider );
230
- val blockNumber = 2 ;
240
+ val blockNumber = BlockNumber . of ( 2 ) ;
231
241
val storage = newSystemBlockHashStorage (state );
232
242
val blockHash = new AtomicReference <BlockHash >();
233
243
val value = new AtomicReference <BlockHash >();
234
- val argument = new AtomicInteger ();
244
+ val argument = new AtomicReference < BlockNumber > ();
235
245
val unsubscribe = storage .subscribe ((exception , block , v , keys ) -> {
236
246
if (exception == null ) {
237
247
blockHash .set (block );
238
248
value .set (v );
239
- argument .set ((Integer ) keys .get (0 ));
249
+ argument .set ((BlockNumber ) keys .get (0 ));
240
250
}
241
251
}, Arg .of (blockNumber ))
242
252
.get (WAIT_TIMEOUT , TimeUnit .SECONDS );
0 commit comments