Persistent Local Storage for offchain workers. (#2894)

* WiP.

* Implement offchain storage APIs.

* Change compare_and_set to return bool.

* Add offchain http test.

* Fix tests.

* Bump spec version.

* Fix warnings and test.

* Fix compilation.

* Remove unused code.

* Introduce Local (fork-aware) and Persistent storage.

* Fix borked merge.

* Prevent warning on depreacated client.backend

* Fix long lines.

* Clean up dependencies.

* Update core/primitives/src/offchain.rs

Co-Authored-By: André Silva <andre.beat@gmail.com>

* Update core/primitives/src/offchain.rs

Co-Authored-By: André Silva <andre.beat@gmail.com>
This commit is contained in:
Tomasz Drwięga
2019-07-02 20:11:06 +02:00
committed by Gavin Wood
parent 24aa882ebc
commit 2217c1e9a1
26 changed files with 726 additions and 118 deletions
+12 -7
View File
@@ -305,7 +305,7 @@ impl OffchainApi for () {
}, "timestamp can be called only in the offchain worker context")
}
fn sleep_until(deadline: Timestamp) {
fn sleep_until(deadline: offchain::Timestamp) {
with_offchain(|ext| {
ext.sleep_until(deadline)
}, "sleep_until can be called only in the offchain worker context")
@@ -317,21 +317,26 @@ impl OffchainApi for () {
}, "random_seed can be called only in the offchain worker context")
}
fn local_storage_set(key: &[u8], value: &[u8]) {
fn local_storage_set(kind: offchain::StorageKind, key: &[u8], value: &[u8]) {
with_offchain(|ext| {
ext.local_storage_set(key, value)
ext.local_storage_set(kind, key, value)
}, "local_storage_set can be called only in the offchain worker context")
}
fn local_storage_compare_and_set(key: &[u8], old_value: &[u8], new_value: &[u8]) {
fn local_storage_compare_and_set(
kind: offchain::StorageKind,
key: &[u8],
old_value: &[u8],
new_value: &[u8],
) -> bool {
with_offchain(|ext| {
ext.local_storage_compare_and_set(key, old_value, new_value)
ext.local_storage_compare_and_set(kind, key, old_value, new_value)
}, "local_storage_compare_and_set can be called only in the offchain worker context")
}
fn local_storage_get(key: &[u8]) -> Option<Vec<u8>> {
fn local_storage_get(kind: offchain::StorageKind, key: &[u8]) -> Option<Vec<u8>> {
with_offchain(|ext| {
ext.local_storage_get(key)
ext.local_storage_get(kind, key)
}, "local_storage_get can be called only in the offchain worker context")
}