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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
Rust
Ğcli-v2s
Commits
db1ea3d3
Commit
db1ea3d3
authored
1 year ago
by
Hugo Trentesaux
Browse files
Options
Downloads
Patches
Plain Diff
improve online smith command
parent
cbe4cd67
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!25
indexer refac
This commit is part of merge request
!25
. Comments created here will be created in the context of that merge request.
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
res/indexer-queries.graphql
+2
-2
2 additions, 2 deletions
res/indexer-queries.graphql
src/commands/smith.rs
+54
-7
54 additions, 7 deletions
src/commands/smith.rs
src/indexer.rs
+13
-1
13 additions, 1 deletion
src/indexer.rs
src/indexer/queries.rs
+7
-4
7 additions, 4 deletions
src/indexer/queries.rs
with
76 additions
and
14 deletions
res/indexer-queries.graphql
+
2
−
2
Edit
View file @
db1ea3d3
...
@@ -4,8 +4,8 @@ query IdentityNameByIndex($index: Int!) {
...
@@ -4,8 +4,8 @@ query IdentityNameByIndex($index: Int!) {
}
}
}
}
query
NamesByIndexes
(
$i
dtyid
s
:
[
Int
!])
{
query
NamesByIndexes
(
$i
ndexe
s
:
[
Int
!]
!
)
{
identities
(
where
:
{
index_in
:
$i
dtyid
s
})
{
identities
(
where
:
{
index_in
:
$i
ndexe
s
})
{
index
index
name
name
}
}
...
...
This diff is collapsed.
Click to expand it.
src/commands/smith.rs
+
54
−
7
Edit
View file @
db1ea3d3
...
@@ -3,6 +3,7 @@ use crate::*;
...
@@ -3,6 +3,7 @@ use crate::*;
use
commands
::
identity
::
try_get_idty_index_by_name
;
use
commands
::
identity
::
try_get_idty_index_by_name
;
#[cfg(feature
=
"gdev"
)]
#[cfg(feature
=
"gdev"
)]
use
runtime
::
runtime_types
::
gdev_runtime
::
opaque
::
SessionKeys
as
RuntimeSessionKeys
;
use
runtime
::
runtime_types
::
gdev_runtime
::
opaque
::
SessionKeys
as
RuntimeSessionKeys
;
use
std
::
collections
::
HashMap
;
use
std
::
ops
::
Deref
;
use
std
::
ops
::
Deref
;
type
SessionKeys
=
[
u8
;
128
];
type
SessionKeys
=
[
u8
;
128
];
...
@@ -68,7 +69,7 @@ pub enum Subcommand {
...
@@ -68,7 +69,7 @@ pub enum Subcommand {
/// handle smith commands
/// handle smith commands
pub
async
fn
handle_command
(
data
:
Data
,
command
:
Subcommand
)
->
Result
<
(),
GcliError
>
{
pub
async
fn
handle_command
(
data
:
Data
,
command
:
Subcommand
)
->
Result
<
(),
GcliError
>
{
let
mut
data
=
data
.build_client
()
.await
?
;
let
mut
data
=
data
.build_client
()
.await
?
.build_indexer
()
.await
?
;
match
command
{
match
command
{
Subcommand
::
GoOnline
=>
{
Subcommand
::
GoOnline
=>
{
go_online
(
&
data
)
.await
?
;
go_online
(
&
data
)
.await
?
;
...
@@ -222,6 +223,51 @@ pub async fn online(data: &Data) -> Result<(), anyhow::Error> {
...
@@ -222,6 +223,51 @@ pub async fn online(data: &Data) -> Result<(), anyhow::Error> {
.await
?
.await
?
.unwrap_or_default
();
.unwrap_or_default
();
if
let
Some
(
indexer
)
=
&
data
.indexer
{
let
mut
names
=
HashMap
::
<
IdtyId
,
String
>
::
new
();
indexer
.names_by_indexes
(
&
online_authorities
)
.await
.into_iter
()
.for_each
(|
e
|
{
names
.insert
(
e
.0
,
e
.1
);
});
println!
(
"Online:"
);
println!
(
"{}"
,
online_authorities
.iter
()
.map
(|
i
|
&
names
.get
(
i
)
.expect
(
"panic! found authorities whith no name"
)[
..
])
.collect
::
<
Vec
<&
str
>>
()
.join
(
", "
)
);
println!
(
"Incoming:"
);
println!
(
"{}"
,
incoming_authorities
.iter
()
.map
(|
i
|
&
names
.get
(
i
)
.expect
(
"panic! found authorities whith no name"
)[
..
])
.collect
::
<
Vec
<&
str
>>
()
.join
(
", "
)
);
println!
(
"Outgoing:"
);
println!
(
"{}"
,
outgoing_authorities
.iter
()
.map
(|
i
|
&
names
.get
(
i
)
.expect
(
"panic! found authorities whith no name"
)[
..
])
.collect
::
<
Vec
<&
str
>>
()
.join
(
", "
)
);
}
else
{
println!
(
"Online:"
);
println!
(
"Online:"
);
println!
(
"{online_authorities:?}"
);
println!
(
"{online_authorities:?}"
);
...
@@ -230,6 +276,7 @@ pub async fn online(data: &Data) -> Result<(), anyhow::Error> {
...
@@ -230,6 +276,7 @@ pub async fn online(data: &Data) -> Result<(), anyhow::Error> {
println!
(
"Outgoing:"
);
println!
(
"Outgoing:"
);
println!
(
"{outgoing_authorities:?}"
);
println!
(
"{outgoing_authorities:?}"
);
}
Ok
(())
Ok
(())
}
}
...
...
This diff is collapsed.
Click to expand it.
src/indexer.rs
+
13
−
1
Edit
View file @
db1ea3d3
...
@@ -15,7 +15,7 @@ pub struct Indexer {
...
@@ -15,7 +15,7 @@ pub struct Indexer {
}
}
impl
Indexer
{
impl
Indexer
{
//
query
//
/ graphql query without error management
async
fn
query
<
T
:
GraphQLQuery
>
(
async
fn
query
<
T
:
GraphQLQuery
>
(
&
self
,
&
self
,
var
:
<
T
as
GraphQLQuery
>
::
Variables
,
var
:
<
T
as
GraphQLQuery
>
::
Variables
,
...
@@ -38,6 +38,18 @@ impl Indexer {
...
@@ -38,6 +38,18 @@ impl Indexer {
.map
(|
idty
|
idty
.name
)
.map
(|
idty
|
idty
.name
)
}
}
/// index → name (multiple)
pub
async
fn
names_by_indexes
(
&
self
,
indexes
:
&
[
IdtyId
])
->
Vec
<
(
IdtyId
,
String
)
>
{
self
.query
::
<
NamesByIndexes
>
(
names_by_indexes
::
Variables
{
indexes
:
indexes
.iter
()
.map
(|
i
|
*
i
as
i64
)
.collect
(),
})
.await
.identities
.into_iter
()
.map
(|
idty
|
(
idty
.index
as
IdtyId
,
idty
.name
))
.collect
()
}
/// pubkey → name
/// pubkey → name
pub
async
fn
username_by_pubkey
(
&
self
,
pubkey
:
&
str
)
->
Option
<
String
>
{
pub
async
fn
username_by_pubkey
(
&
self
,
pubkey
:
&
str
)
->
Option
<
String
>
{
self
.query
::
<
IdentityNameByPubkey
>
(
identity_name_by_pubkey
::
Variables
{
self
.query
::
<
IdentityNameByPubkey
>
(
identity_name_by_pubkey
::
Variables
{
...
...
This diff is collapsed.
Click to expand it.
src/indexer/queries.rs
+
7
−
4
Edit
View file @
db1ea3d3
use
graphql_client
::
GraphQLQuery
;
use
graphql_client
::
GraphQLQuery
;
use
sp_core
::
Bytes
;
use
sp_core
::
Bytes
;
// index → identity
#[derive(GraphQLQuery)]
#[derive(GraphQLQuery)]
#[graphql(
#[graphql(
schema_path
=
"res/indexer-schema.json"
,
schema_path
=
"res/indexer-schema.json"
,
...
@@ -9,7 +8,6 @@ use sp_core::Bytes;
...
@@ -9,7 +8,6 @@ use sp_core::Bytes;
)]
)]
pub
struct
IdentityNameByIndex
;
pub
struct
IdentityNameByIndex
;
// index → identity info
#[derive(GraphQLQuery)]
#[derive(GraphQLQuery)]
#[graphql(
#[graphql(
schema_path
=
"res/indexer-schema.json"
,
schema_path
=
"res/indexer-schema.json"
,
...
@@ -17,7 +15,6 @@ pub struct IdentityNameByIndex;
...
@@ -17,7 +15,6 @@ pub struct IdentityNameByIndex;
)]
)]
pub
struct
IdentityInfo
;
pub
struct
IdentityInfo
;
// pubkey → identity
#[derive(GraphQLQuery)]
#[derive(GraphQLQuery)]
#[graphql(
#[graphql(
schema_path
=
"res/indexer-schema.json"
,
schema_path
=
"res/indexer-schema.json"
,
...
@@ -25,7 +22,6 @@ pub struct IdentityInfo;
...
@@ -25,7 +22,6 @@ pub struct IdentityInfo;
)]
)]
pub
struct
IdentityNameByPubkey
;
pub
struct
IdentityNameByPubkey
;
// pubkey → wasidentity
#[derive(GraphQLQuery)]
#[derive(GraphQLQuery)]
#[graphql(
#[graphql(
schema_path
=
"res/indexer-schema.json"
,
schema_path
=
"res/indexer-schema.json"
,
...
@@ -53,3 +49,10 @@ pub struct BlockByNumber;
...
@@ -53,3 +49,10 @@ pub struct BlockByNumber;
query_path
=
"res/indexer-queries.graphql"
query_path
=
"res/indexer-queries.graphql"
)]
)]
pub
struct
GenesisHash
;
pub
struct
GenesisHash
;
#[derive(GraphQLQuery,
Debug)]
#[graphql(
schema_path
=
"res/indexer-schema.json"
,
query_path
=
"res/indexer-queries.graphql"
)]
pub
struct
NamesByIndexes
;
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