-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Abstractions and API for querying to storages #12
Conversation
67065db
to
511a756
Compare
storage/src/main/java/com/strategyobject/substrateclient/storage/KeyHashingAlgorithm.java
Show resolved
Hide resolved
(byte) ((hash >> 32) & 0xff), | ||
(byte) ((hash >> 40) & 0xff), | ||
(byte) ((hash >> 48) & 0xff), | ||
(byte) ((hash >> 56) & 0xff) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return new byte[]{
(byte) hash,
(byte) (hash >> 8),
(byte) (hash >> 16),
(byte) (hash >> 24),
(byte) (hash >> 32),
(byte) (hash >> 40),
(byte) (hash >> 48),
(byte) (hash >> 56)
};
var key = new byte[0]; | ||
var keyLength = 0; | ||
|
||
while (!Arrays.equals(hash, blake2_128(key))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as far as I remember we discussed that here might be a better approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not needed more, I used that for tests and forgot to delete. Will remove.
storage/src/main/java/com/strategyobject/substrateclient/storage/DiverseKeyValueCollection.java
Outdated
Show resolved
Hide resolved
private DiverseKeyValueCollection(List<Pair<StorageKey, StorageData>> pairs, | ||
List<ScaleReader<Object>> valueReaders, | ||
List<Function<StorageKey, List<Object>>> keyExtractors) { | ||
if (pairs.size() != valueReaders.size()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use preconditions for this
Preconditions.checkArgument(pairs.size() == valueReaders.size(), "Number of value readers doesn't match number of pairs.");
val blockHash = new AtomicReference<BlockHash>(); | ||
val value = new AtomicReference<BlockHash>(); | ||
val argument = new AtomicInteger(); | ||
storage.subscribe((exception, block, v, keys) -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't the test unsubscribe in the end?
storage/src/main/java/com/strategyobject/substrateclient/storage/StorageKeyProvider.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
public StorageKeyProvider with(@NonNull KeyHasher<?>... hashers) { | ||
if (keyHashers.size() > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preconditions.checkState(keyHashers.isEmpty(), "Key hashers are already set.");
return task | ||
.thenApplyAsync(storageKeys -> { | ||
if ((size = storageKeys.size()) > 0) { | ||
hasNext = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like it shows if 'current' exists (not 'next')
511a756
to
871ff7b
Compare
|
||
/** | ||
* TwoX 64 Concat hash algorithm. | ||
* That's a non-cryptographic and transparent. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This algorithm is non-cryptographic and transparent.
PagedKeyValueIterator<V> entriesPaged(int pageSize, @NonNull Object... keys); | ||
|
||
/** | ||
* Returns collection of key-values each item of which |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returns a collection of key-values, each item of which
|
||
/** | ||
* Returns collection of key-values each item of which | ||
* contains the all keys of the entry and the value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contains all the keys of the entry and its value.
CompletableFuture<KeyValueCollection<V>> entries(@NonNull Object... keys); | ||
|
||
/** | ||
* Returns iterator of collection of key-values each item of which |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returns an iterator of a key-value collection, each item of which
|
||
/** | ||
* Returns iterator of collection of key-values each item of which | ||
* contains the rest keys of the entry and the value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contains the remaining keys and the value.
/** | ||
* @param keys the keys of the storage's entry. | ||
* @return the queryable key that allows to request value. | ||
* The queryable key can also be joined to other keys for multi query. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The queryable key can also be joined to other keys for forming a multi query.
CompletableFuture<List<Pair<BlockHash, List<V>>>> history(@NonNull Object... keys); | ||
|
||
/** | ||
* Returns collection of key-values each item of which |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returns a key-value collection, each item of which
|
||
/** | ||
* Returns collection of key-values each item of which | ||
* contains the rest keys of the entry and the value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contains the remaining keys of the entry and its value.
* Returns collection of key-values each item of which | ||
* contains the rest keys of the entry and the value. | ||
* @param keys some keys of the storage's entry. | ||
* Note: each key must follow the other in the strict order as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: all the keys must follow the same strict order as
* contains the rest keys of the entry and the value. | ||
* @param keys some keys of the storage's entry. | ||
* Note: each key must follow the other in the strict order as | ||
* they represented in the storage. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they appear in the storage.
OR
their sequence in the storage.
* @param queryKey StorageKey that contains pallet and storage names | ||
* and may contain some keys of the entry. | ||
* Note: each key follows the other in the strict order as | ||
* they set in the storage. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they appear in the storage.
OR
their sequence in the storage.
* Note: each key follows the other in the strict order as | ||
* they set in the storage. | ||
* @param countOfKeysInQuery number of keys that involved in queryKey. | ||
* @return the rest keys of the entry which don't contain in the queryKey. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@return the remaining keys of the entry which are not included in the queryKey.
* and may contain some keys of the entry. | ||
* Note: each key follows the other in the strict order as | ||
* they set in the storage. | ||
* @param countOfKeysInQuery number of keys that involved in queryKey. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@param countOfKeysInQuery number of keys included in the queryKey.
|
||
/** | ||
* @param keys values of the keys for request to the entry | ||
* Note: each key must follow the other in the strict order as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: all the keys must follow the same exact order as
/** | ||
* @param keys values of the keys for request to the entry | ||
* Note: each key must follow the other in the strict order as | ||
* they represented in the storage. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they appear in the storage.
OR
their sequence in the storage.
import java.util.function.Function; | ||
|
||
/** | ||
* Collection that contains entries of different kinds of storage. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Collection that contains entries from various storage types.
|
||
/** | ||
* @return the queryable key that allows to request value. | ||
* The queryable key can also be joined to other keys for multi query. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The queryable key can also be joined to other keys for forming a multi query.
|
||
/** | ||
* An algorithm that's used to generate storage map's key. | ||
* As a general rule it should be a transparent algorithm as so |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a general rule it should be a transparent algorithm since
* @param exception happened on event. | ||
* @param block hash of the block where the change happened. | ||
* @param value new value of the storage's entry. | ||
* @param keys list of the keys of the storage's entry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@param keys list of the storage entry's keys.
* of the entry. | ||
* @param queryKey StorageKey that contains pallet and storage names | ||
* and may contain some keys of the entry. | ||
* Note: each key follows the other in the strict order as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: all the keys must follow the same exact order as
@@ -10,7 +10,10 @@ | |||
import static com.strategyobject.substrateclient.rpc.codegen.sections.Constants.CLASS_NAME_TEMPLATE; | |||
|
|||
public class RpcGeneratedSectionFactory { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this class doesn't seem to be anyhow involved in code generation. What do you think about moving it to rpc-sections
or rpc-core
?
There is added interface `StorageNMap` that represents a storage of data in blockchain. Added corresponding abstractions and entites such `KeyHashingAlgorithm`, `Blake2B128Concat`, `Identity`, `TwoX64Concat` and etc. Added appropriate methods to section `State`.
871ff7b
to
d2811c1
Compare
There is added interface
StorageNMap
that represents a storage of data in blockchain.Added corresponding abstractions and entites such
KeyHashingAlgorithm
,Blake2B128Concat
,Identity
,TwoX64Concat
and etc.Added appropriate methods to section
State
.