Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
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
nodes
typescript
duniter
Merge requests
!1372
[ref] dbs: DunpNodeIdV1Db must be indexed by pubkey
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
[ref] dbs: DunpNodeIdV1Db must be indexed by pubkey
dunp-v1-node-id
into
dev
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
Éloïs
requested to merge
dunp-v1-node-id
into
dev
4 years ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Compare
dev
dev (base)
and
latest version
latest version
dfc43543
1 commit,
4 years ago
1 file
+
20
−
4
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
rust-libs/duniter-dbs/src/keys/dunp_node_id.rs
+
20
−
4
Options
@@ -26,24 +26,24 @@ pub struct DunpNodeIdV1Db([u8; 37]); // uuid ++ pubkey
impl
DunpNodeIdV1Db
{
pub
fn
new
(
uuid
:
u32
,
pubkey
:
PublicKey
)
->
Self
{
let
mut
buffer
=
uninit_array!
[
u8
;
37
];
let
(
uuid
_buffer
,
pubkey
_buffer
)
=
buffer
.as_out
()
.split_at_out
(
4
);
let
(
pubkey
_buffer
,
uuid
_buffer
)
=
buffer
.as_out
()
.split_at_out
(
33
);
uuid_buffer
.copy_from_slice
(
&
uuid
.to_be_bytes
()[
..
]);
pubkey_buffer
.copy_from_slice
(
pubkey
.as_ref
());
uuid_buffer
.copy_from_slice
(
&
uuid
.to_be_bytes
()[
..
]);
Self
(
unsafe
{
std
::
mem
::
transmute
(
buffer
)
})
}
pub
fn
get_uuid
(
&
self
)
->
u32
{
let
mut
buffer
=
uninit_array!
[
u8
;
4
];
buffer
.as_out
()
.copy_from_slice
(
&
self
.0
[
..
4
]);
buffer
.as_out
()
.copy_from_slice
(
&
self
.0
[
33
..
]);
u32
::
from_be_bytes
(
unsafe
{
std
::
mem
::
transmute
(
buffer
)
})
}
pub
fn
get_pubkey
(
&
self
)
->
PublicKey
{
let
mut
buffer
=
uninit_array!
[
u8
;
33
];
buffer
.as_out
()
.copy_from_slice
(
&
self
.0
[
4
..
]);
buffer
.as_out
()
.copy_from_slice
(
&
self
.0
[
..
33
]);
let
bytes
:
[
u8
;
33
]
=
unsafe
{
std
::
mem
::
transmute
(
buffer
)
};
PublicKey
::
try_from
(
&
bytes
[
..
])
.unwrap_or_else
(|
_
|
unreachable!
())
@@ -93,3 +93,19 @@ impl ExplorableKey for DunpNodeIdV1Db {
Ok
(
self
.to_string
())
}
}
#[cfg(test)]
mod
tests
{
use
super
::
*
;
#[test]
fn
test_serde
()
{
let
node_id
=
DunpNodeIdV1Db
::
new
(
42
,
PublicKey
::
default
());
assert_eq!
(
node_id
.get_uuid
(),
42
);
assert_eq!
(
node_id
.get_pubkey
(),
PublicKey
::
default
());
let
mut
node_id_
=
DunpNodeIdV1Db
([
0u8
;
37
]);
node_id_
.0
[
32
]
=
32
;
node_id_
.0
[
36
]
=
42
;
assert_eq!
(
node_id_
,
node_id
)
}
}
Loading