Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
duniter-core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
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
rust
duniter-core
Commits
2dbd2332
Commit
2dbd2332
authored
4 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
mod(db): PeerCardDbV1: use dubp PeerV10
parent
b0fa1ba7
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
dbs/src/values/peer_card.rs
+2
-61
2 additions, 61 deletions
dbs/src/values/peer_card.rs
with
2 additions
and
61 deletions
dbs/src/values/peer_card.rs
+
2
−
61
View file @
2dbd2332
...
...
@@ -14,43 +14,15 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use
crate
::
*
;
use
dubp
::
peer
::
PeerV10
;
#[derive(Clone,
Debug,
Default,
Deserialize,
PartialEq,
Serialize)]
pub
struct
PeerCardDbV1
{
pub
version
:
u32
,
pub
currency
:
String
,
pub
pubkey
:
PublicKey
,
pub
blockstamp
:
Blockstamp
,
pub
endpoints
:
Vec
<
String
>
,
pub
signature
:
Signature
,
pub
peer
:
PeerV10
,
pub
status
:
bool
,
pub
member
:
bool
,
}
impl
PeerCardDbV1
{
pub
fn
to_raw_string
(
&
self
)
->
String
{
format!
(
"{}{}
\n
"
,
self
.to_raw_unsigned_string
(),
self
.signature
.to_base64
(),
)
}
fn
to_raw_unsigned_string
(
&
self
)
->
String
{
format!
(
"Version: {}
\n
Type: Peer
\n
Currency: {}
\n
PublicKey: {}
\n
Block: {}
\n
Endpoints:
\n
{}
\n
"
,
self
.version
,
self
.currency
,
self
.pubkey
.to_base58
(),
self
.blockstamp
,
self
.endpoints
.join
(
"
\n
"
),
)
}
pub
fn
verify_sig
(
&
self
)
->
Result
<
(),
dubp
::
crypto
::
keys
::
SigError
>
{
self
.pubkey
.verify
(
self
.to_raw_unsigned_string
()
.as_bytes
(),
&
self
.signature
)
}
}
impl
AsBytes
for
PeerCardDbV1
{
fn
as_bytes
<
T
,
F
:
FnMut
(
&
[
u8
])
->
T
>
(
&
self
,
mut
f
:
F
)
->
T
{
let
bytes
=
bincode_db
()
...
...
@@ -85,34 +57,3 @@ impl ExplorableValue for PeerCardDbV1 {
serde_json
::
to_value
(
self
)
.map_err
(|
e
|
KvError
::
DeserError
(
e
.into
()))
}
}
#[cfg(test)]
mod
tests
{
use
super
::
*
;
use
unwrap
::
unwrap
;
#[test]
fn
test_old_peer_sig
()
{
let
peer
=
PeerCardDbV1
{
version
:
10
,
currency
:
"g1"
.to_owned
(),
pubkey
:
unwrap!
(
PublicKey
::
from_base58
(
"8iVdpXqFLCxGyPqgVx5YbFSkmWKkceXveRd2yvBKeARL"
)),
blockstamp
:
unwrap!
(
Blockstamp
::
from_str
(
"423354-00000033A87209DC21BD643088ED8AD52464A80C04BE3F8FBFA4291A9999BE50"
)),
endpoints
:
vec!
[
"BMAS g1.duniter.org 443"
.to_owned
(),
"BASIC_MERKLED_API 91.121.157.13 10901"
.to_owned
(),
"WS2P e66254bf g1.duniter.org 443 ws2p"
.to_owned
()
],
signature
:
unwrap!
(
Signature
::
from_base64
(
"qr6Cnr/Qsgw/clbt0LbdkaFaUwhdgBJw5Fzpn8EhI9zM5/rGbVF6kqiB5pRJxf17XtI45qQ7H7SBbl8X2kAtCA=="
)),
status
:
true
,
member
:
false
,
};
let
peer_raw
=
peer
.to_raw_unsigned_string
();
assert_eq!
(
&
peer_raw
,
"Version: 10
\n
Type: Peer
\n
Currency: g1
\n
PublicKey: 8iVdpXqFLCxGyPqgVx5YbFSkmWKkceXveRd2yvBKeARL
\n
Block: 423354-00000033A87209DC21BD643088ED8AD52464A80C04BE3F8FBFA4291A9999BE50
\n
Endpoints:
\n
BMAS g1.duniter.org 443
\n
BASIC_MERKLED_API 91.121.157.13 10901
\n
WS2P e66254bf g1.duniter.org 443 ws2p
\n
"
,
);
assert!
(
peer
.verify_sig
()
.is_ok
());
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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