Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
polkadot-sdk
Commits
583b0e3c
Commit
583b0e3c
authored
5 years ago
by
thiolliere
Committed by
Gavin Wood
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
impl iter_prefix on doublemap (#4388)
parent
7e3872c0
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
substrate/frame/support/src/storage/generator/double_map.rs
+42
-0
42 additions, 0 deletions
substrate/frame/support/src/storage/generator/double_map.rs
substrate/frame/support/src/storage/mod.rs
+3
-0
3 additions, 0 deletions
substrate/frame/support/src/storage/mod.rs
with
45 additions
and
0 deletions
substrate/frame/support/src/storage/generator/double_map.rs
+
42
−
0
View file @
583b0e3c
...
...
@@ -181,6 +181,17 @@ where
unhashed
::
kill_prefix
(
Self
::
storage_double_map_final_key1
(
k1
)
.as_ref
())
}
fn
iter_prefix
<
KArg1
>
(
k1
:
KArg1
)
->
storage
::
PrefixIterator
<
V
>
where
KArg1
:
?
Sized
+
EncodeLike
<
K1
>
{
let
prefix
=
Self
::
storage_double_map_final_key1
(
k1
);
storage
::
PrefixIterator
::
<
V
>
{
prefix
:
prefix
.clone
(),
previous_key
:
prefix
,
phantom_data
:
Default
::
default
(),
}
}
fn
mutate
<
KArg1
,
KArg2
,
R
,
F
>
(
k1
:
KArg1
,
k2
:
KArg2
,
f
:
F
)
->
R
where
KArg1
:
EncodeLike
<
K1
>
,
...
...
@@ -266,3 +277,34 @@ where
}
}
}
#[cfg(test)]
mod
test
{
use
sp_io
::
TestExternalities
;
use
crate
::
storage
::{
self
,
StorageDoubleMap
};
use
crate
::
hash
::
Twox128
;
#[test]
fn
iter_prefix_works
()
{
TestExternalities
::
default
()
.execute_with
(||
{
struct
MyStorage
;
impl
storage
::
generator
::
StorageDoubleMap
<
u64
,
u64
,
u64
>
for
MyStorage
{
type
Query
=
Option
<
u64
>
;
fn
module_prefix
()
->
&
'static
[
u8
]
{
b"MyModule"
}
fn
storage_prefix
()
->
&
'static
[
u8
]
{
b"MyStorage"
}
type
Hasher1
=
Twox128
;
type
Hasher2
=
Twox128
;
fn
from_optional_value_to_query
(
v
:
Option
<
u64
>
)
->
Self
::
Query
{
v
}
fn
from_query_to_optional_value
(
v
:
Self
::
Query
)
->
Option
<
u64
>
{
v
}
}
MyStorage
::
insert
(
1
,
3
,
7
);
MyStorage
::
insert
(
1
,
4
,
8
);
MyStorage
::
insert
(
2
,
5
,
9
);
MyStorage
::
insert
(
2
,
6
,
10
);
assert_eq!
(
MyStorage
::
iter_prefix
(
1
)
.collect
::
<
Vec
<
_
>>
(),
vec!
[
7
,
8
]);
assert_eq!
(
MyStorage
::
iter_prefix
(
2
)
.collect
::
<
Vec
<
_
>>
(),
vec!
[
10
,
9
]);
});
}
}
This diff is collapsed.
Click to expand it.
substrate/frame/support/src/storage/mod.rs
+
3
−
0
View file @
583b0e3c
...
...
@@ -305,6 +305,9 @@ pub trait StorageDoubleMap<K1: FullEncode, K2: FullEncode, V: FullCodec> {
fn
remove_prefix
<
KArg1
>
(
k1
:
KArg1
)
where
KArg1
:
?
Sized
+
EncodeLike
<
K1
>
;
fn
iter_prefix
<
KArg1
>
(
k1
:
KArg1
)
->
PrefixIterator
<
V
>
where
KArg1
:
?
Sized
+
EncodeLike
<
K1
>
;
fn
mutate
<
KArg1
,
KArg2
,
R
,
F
>
(
k1
:
KArg1
,
k2
:
KArg2
,
f
:
F
)
->
R
where
KArg1
:
EncodeLike
<
K1
>
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment