Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Ğ
Ğcli-v2s
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
clients
Rust
Ğcli-v2s
Commits
43af6d37
Commit
43af6d37
authored
1 year ago
by
Hugo Trentesaux
Browse files
Options
Downloads
Patches
Plain Diff
refac identity to display status
parent
04869cd2
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!15
update to runtime 800
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/commands/identity.rs
+27
-42
27 additions, 42 deletions
src/commands/identity.rs
src/commands/runtime.rs
+6
-2
6 additions, 2 deletions
src/commands/runtime.rs
with
33 additions
and
44 deletions
src/commands/identity.rs
+
27
−
42
View file @
43af6d37
...
...
@@ -71,7 +71,6 @@ pub enum Subcommand {
pub
async
fn
handle_command
(
data
:
Data
,
command
:
Subcommand
)
->
Result
<
(),
GcliError
>
{
let
mut
data
=
data
.build_client
()
.await
?
;
match
command
{
// TODO remove indexer where not necessary when BlakeConcat will be there
Subcommand
::
Show
=>
{
data
=
data
.build_indexer
()
.await
?
;
get_identity
(
&
data
,
Some
(
data
.address
()),
None
,
None
)
.await
?
...
...
@@ -150,41 +149,30 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
/// get identity
pub
async
fn
get_identity
(
data
:
&
Data
,
mut
account_id
:
Option
<
AccountId
>
,
mut
identity_id
:
Option
<
IdtyId
>
,
mut
username
:
Option
<
String
>
,
account_id
:
Option
<
AccountId
>
,
identity_id
:
Option
<
IdtyId
>
,
username
:
Option
<
String
>
,
)
->
Result
<
(),
anyhow
::
Error
>
{
let
client
=
data
.client
();
let
indexer
=
data
.indexer
.clone
();
// fetch reachable information using Duniter only (no indexer)
match
(
&
account_id
,
identity_id
,
&
username
)
{
let
(
idty
,
value
)
=
match
(
&
account_id
,
identity_id
,
&
username
)
{
// idty_id → account_id
(
None
,
Some
(
identity_id
),
None
)
=>
{
account_id
=
get_identity_by_index
(
client
,
identity_id
)
.await
?
.map
(|
idty
|
idty
.owner_key
);
if
account_id
.is_none
()
{
return
Err
(
anyhow!
(
"no identity for this account id"
));
}
}
(
None
,
Some
(
idty
),
None
)
=>
(
idty
,
get_identity_by_index
(
client
,
idty
)
.await
?
),
// account_id → idty_id
(
Some
(
account_id
),
None
,
None
)
=>
{
identity_id
=
get_idty_index_by_account_id
(
client
,
account_id
)
.await
?
;
if
identity_id
.is_none
()
{
return
Err
(
anyhow!
(
"no identity for this
identity index
"
));
}
let
idty
=
get_idty_index_by_account_id
(
client
,
account_id
)
.await
?
.ok_or_else
(||
anyhow!
(
"no identity for this
account id
"
))
?
;
(
idty
,
get_identity_by_index
(
client
,
idty
)
.await
?
)
}
// username → idty_id and account_id
(
None
,
None
,
Some
(
username
))
=>
{
identity_id
=
get_idty_index_by_name
(
client
,
username
)
.await
?
;
if
let
Some
(
identity_id
)
=
identity_id
{
account_id
=
get_identity_by_index
(
client
,
identity_id
)
let
idty
=
get_idty_index_by_name
(
client
,
username
)
.await
?
.map
(|
idty
|
idty
.owner_key
);
}
else
{
return
Err
(
anyhow!
(
"no identity found for this username"
));
}
.ok_or_else
(||
anyhow!
(
"no identity found for this username"
))
?
;
(
idty
,
get_identity_by_index
(
client
,
idty
)
.await
?
)
}
_
=>
{
return
Err
(
anyhow!
(
...
...
@@ -192,28 +180,25 @@ pub async fn get_identity(
));
}
};
let
value
=
value
.ok_or_else
(||
anyhow!
(
"no identity value"
))
?
;
// print result
// 1. identity index
println!
(
"Identity index: {}"
,
identity_id
.map_or
(
String
::
new
(),
|
identity_id
|
format!
(
"{identity_id}"
))
);
println!
(
"Identity index: {idty}"
,);
// 2. username (indexer needed if not provided)
if
let
(
Some
(
indexer
),
Some
(
identity_id
),
None
)
=
(
&
indexer
,
identity_id
,
&
username
)
{
username
=
indexer
.username_by_index
(
identity_id
)
.await
?
;
}
println!
(
"Username: {}"
,
username
.unwrap_or
(
"<no indexer>"
.to_string
())
);
let
username
=
username
.unwrap_or
(
if
let
Some
(
indexer
)
=
&
indexer
{
indexer
.username_by_index
(
idty
)
.await
?
.ok_or_else
(||
anyhow!
(
"indexer does not have username for this index"
))
?
}
else
{
"<no indexer>"
.to_string
()
});
println!
(
"Username: {username}"
,);
// 3. address
println!
(
"Address: {}"
,
account_id
.as_ref
()
.map_or
(
String
::
new
(),
AccountId
::
to_string
)
);
println!
(
"Address: {}"
,
AccountId
::
to_string
(
&
value
.owner_key
));
// 4. status
println!
(
"Status: {:?}"
,
value
.status
);
Ok
(())
}
...
...
This diff is collapsed.
Click to expand it.
src/commands/runtime.rs
+
6
−
2
View file @
43af6d37
...
...
@@ -50,7 +50,11 @@ pub async fn runtime_info(data: Data) {
);
println!
(
"min received cert to issue cert: {}"
,
getu32
(
consts
.certification
()
.min_received_cert_to_be_able_to_issue_cert
())
getu32
(
consts
.certification
()
.min_received_cert_to_be_able_to_issue_cert
()
)
);
println!
(
"certification validity: {} blocks"
,
...
...
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