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
Fabrice LEBON
Ğcli-v2s
Commits
ebcae718
Commit
ebcae718
authored
1 year ago
by
Hugo Trentesaux
Committed by
Hugo Trentesaux
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
WIP add smith request
fix no need indexer for account tweak claim ud command name
parent
c7d143f3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/commands/account.rs
+1
-1
1 addition, 1 deletion
src/commands/account.rs
src/commands/smith.rs
+52
-14
52 additions, 14 deletions
src/commands/smith.rs
src/commands/ud.rs
+2
-2
2 additions, 2 deletions
src/commands/ud.rs
with
55 additions
and
17 deletions
src/commands/account.rs
+
1
−
1
View file @
ebcae718
...
@@ -28,7 +28,7 @@ pub enum Subcommand {
...
@@ -28,7 +28,7 @@ pub enum Subcommand {
/// handle account commands
/// handle account commands
pub
async
fn
handle_command
(
data
:
Data
,
command
:
Subcommand
)
->
anyhow
::
Result
<
()
>
{
pub
async
fn
handle_command
(
data
:
Data
,
command
:
Subcommand
)
->
anyhow
::
Result
<
()
>
{
let
mut
data
=
data
.build_client
()
.await
?
.build_indexer
()
.await
?
;
let
mut
data
=
data
.build_client
()
.await
?
;
match
command
{
match
command
{
Subcommand
::
Balance
=>
{
Subcommand
::
Balance
=>
{
data
=
data
data
=
data
...
...
This diff is collapsed.
Click to expand it.
src/commands/smith.rs
+
52
−
14
View file @
ebcae718
...
@@ -3,23 +3,25 @@ use crate::*;
...
@@ -3,23 +3,25 @@ use crate::*;
use
std
::
ops
::
Deref
;
use
std
::
ops
::
Deref
;
type
SessionKeys
=
[
u8
;
128
];
type
SessionKeys
=
[
u8
;
128
];
#[cfg(feature
=
"gdev"
)]
type
SmithMembershipMetaData
=
runtime
::
runtime_types
::
common_runtime
::
entities
::
SmithMembershipMetaData
::
<
SessionKeys
>
;
/// define smith subcommands
/// define smith subcommands
#[derive(Clone,
Default,
Debug,
clap::Parser)]
#[derive(Clone,
Default,
Debug,
clap::Parser)]
pub
enum
Subcommand
{
pub
enum
Subcommand
{
/// Request smith membership
Request
{
endpoint
:
String
},
/// Emit a smith certification
/// Emit a smith certification
Cert
{
to
:
u32
},
Cert
{
to
:
u32
},
/// go online
/// go online
GoOnline
,
GoOnline
,
#[default]
/// go offline
/// go offline
#[default]
GoOffline
,
GoOffline
,
/// Rotate and set session keys
/// Rotate and set session keys
UpdateKeys
,
UpdateKeys
,
/// set sudo keys
/// set sudo keys
SudoSetKey
{
SudoSetKey
{
new_key
:
AccountId
},
new_key
:
AccountId
,
},
/// List upcoming expirations that require an action
/// List upcoming expirations that require an action
ShowExpire
{
ShowExpire
{
/// Show certs that expire within less than this number of blocks
/// Show certs that expire within less than this number of blocks
...
@@ -35,32 +37,36 @@ pub enum Subcommand {
...
@@ -35,32 +37,36 @@ pub enum Subcommand {
/// handle smith commands
/// handle smith commands
pub
async
fn
handle_command
(
data
:
Data
,
command
:
Subcommand
)
->
anyhow
::
Result
<
()
>
{
pub
async
fn
handle_command
(
data
:
Data
,
command
:
Subcommand
)
->
anyhow
::
Result
<
()
>
{
let
mut
data
=
data
.build_client
()
.await
?
.build_indexer
()
.await
?
;
let
mut
data
=
data
.build_client
()
.await
?
;
match
command
{
match
command
{
Subcommand
::
Request
{
endpoint
}
=>
{
data
=
data
.build_keypair
();
dbg!
(
request_smith_membership
(
&
data
,
endpoint
)
.await
)
?
;
}
Subcommand
::
GoOnline
=>
{
Subcommand
::
GoOnline
=>
{
commands
::
smith
::
go_online
(
&
data
)
.await
?
;
go_online
(
&
data
)
.await
?
;
}
}
Subcommand
::
GoOffline
=>
{
Subcommand
::
GoOffline
=>
{
commands
::
smith
::
go_offline
(
&
data
)
.await
?
;
go_offline
(
&
data
)
.await
?
;
}
}
Subcommand
::
Cert
{
to
}
=>
{
Subcommand
::
Cert
{
to
}
=>
{
data
=
data
.build_keypair
()
.fetch_idty_index
()
.await
?
;
data
=
data
.build_keypair
()
.fetch_idty_index
()
.await
?
;
commands
::
smith
::
cert
(
&
data
,
to
)
.await
?
cert
(
&
data
,
to
)
.await
?
}
}
Subcommand
::
UpdateKeys
=>
{
Subcommand
::
UpdateKeys
=>
{
commands
::
smith
::
update_session_keys
(
&
data
)
.await
?
;
update_session_keys
(
&
data
)
.await
?
;
}
}
Subcommand
::
SudoSetKey
{
new_key
}
=>
{
Subcommand
::
SudoSetKey
{
new_key
}
=>
{
data
=
data
.build_keypair
()
.build_client
()
.await
?
;
data
=
data
.build_keypair
()
.build_client
()
.await
?
;
commands
::
sudo
::
set_key
(
data
.keypair
(),
data
.client
(),
new_key
)
.await
?
;
commands
::
sudo
::
set_key
(
data
.keypair
(),
data
.client
(),
new_key
)
.await
?
;
}
}
Subcommand
::
ShowExpire
{
blocks
,
sessions
}
=>
{
Subcommand
::
ShowExpire
{
blocks
,
sessions
}
=>
{
data
=
data
.build_client
()
.await
?
;
data
=
data
.build_client
()
.await
?
.build_indexer
()
.await
?
;
commands
::
expire
::
monitor_expirations
(
&
data
,
blocks
,
sessions
)
.await
?
commands
::
expire
::
monitor_expirations
(
&
data
,
blocks
,
sessions
)
.await
?
}
}
Subcommand
::
ShowOnline
=>
{
Subcommand
::
ShowOnline
=>
{
data
=
data
.build_client
()
.await
?
;
data
=
data
.build_client
()
.await
?
;
commands
::
smith
::
online
(
&
data
)
.await
?
online
(
&
data
)
.await
?
}
}
};
};
...
@@ -68,16 +74,45 @@ pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<(
...
@@ -68,16 +74,45 @@ pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<(
}
}
/// rotate session keys
/// rotate session keys
/// (needs to be connected to unsafe RPC)
pub
async
fn
rotate_keys
(
client
:
&
Client
)
->
Result
<
SessionKeys
,
anyhow
::
Error
>
{
pub
async
fn
rotate_keys
(
client
:
&
Client
)
->
Result
<
SessionKeys
,
anyhow
::
Error
>
{
client
client
.rpc
()
.rpc
()
.rotate_keys
()
.rotate_keys
()
.await
?
.await
.map_err
(|
e
|
anyhow!
(
"Please make sure you are connected to your validator node with the unsafe RPC API enabled {e}"
))
?
.deref
()
.deref
()
.try_into
()
.try_into
()
.map_err
(|
e
|
anyhow!
(
"Session keys have wrong length: {:?}"
,
e
))
.map_err
(|
e
|
anyhow!
(
"Session keys have wrong length: {:?}"
,
e
))
}
}
/// request smith membership
pub
async
fn
request_smith_membership
(
data
:
&
Data
,
endpoint
:
String
)
->
Result
<
(),
anyhow
::
Error
>
{
let
session_keys
=
rotate_keys
(
data
.client
())
.await
?
;
let
metadata
=
SmithMembershipMetaData
{
session_keys
,
owner_key
:
data
.address
(),
p2p_endpoint
:
endpoint
,
};
let
progress
=
data
.client
()
.tx
()
.sign_and_submit_then_watch
(
&
runtime
::
tx
()
.smith_membership
()
.request_membership
(
metadata
),
&
PairSigner
::
new
(
data
.keypair
()),
BaseExtrinsicParamsBuilder
::
new
(),
)
.await
?
;
let
events
=
track_progress
(
progress
)
.await
?
;
let
request
=
events
.find_first
::
<
runtime
::
smith_membership
::
events
::
MembershipRequested
>
()
?
;
if
let
Some
(
event
)
=
request
{
println!
(
"{event:?}"
);
}
Ok
(())
}
/// set session keys
/// set session keys
pub
async
fn
set_session_keys
(
pub
async
fn
set_session_keys
(
data
:
&
Data
,
data
:
&
Data
,
...
@@ -121,7 +156,8 @@ pub async fn go_online(data: &Data) -> Result<(), GcliError> {
...
@@ -121,7 +156,8 @@ pub async fn go_online(data: &Data) -> Result<(), GcliError> {
));
));
}
}
let
progress
=
data
.client
()
let
progress
=
data
.client
()
.tx
()
.tx
()
.sign_and_submit_then_watch
(
.sign_and_submit_then_watch
(
&
runtime
::
tx
()
.authority_members
()
.go_online
(),
&
runtime
::
tx
()
.authority_members
()
.go_online
(),
...
@@ -243,7 +279,9 @@ pub async fn cert(data: &Data, receiver: u32) -> Result<(), anyhow::Error> {
...
@@ -243,7 +279,9 @@ pub async fn cert(data: &Data, receiver: u32) -> Result<(), anyhow::Error> {
.client
()
.client
()
.tx
()
.tx
()
.sign_and_submit_then_watch
(
.sign_and_submit_then_watch
(
&
runtime
::
tx
()
.smith_cert
()
.add_cert
(
data
.idty_index
(),
receiver
),
&
runtime
::
tx
()
.smith_cert
()
.add_cert
(
data
.idty_index
(),
receiver
),
&
PairSigner
::
new
(
data
.keypair
()),
&
PairSigner
::
new
(
data
.keypair
()),
BaseExtrinsicParamsBuilder
::
new
(),
BaseExtrinsicParamsBuilder
::
new
(),
)
)
...
...
This diff is collapsed.
Click to expand it.
src/commands/ud.rs
+
2
−
2
View file @
ebcae718
...
@@ -5,7 +5,7 @@ use crate::*;
...
@@ -5,7 +5,7 @@ use crate::*;
pub
enum
Subcommand
{
pub
enum
Subcommand
{
#[default]
#[default]
/// Claim uds
/// Claim uds
Claim
Uds
,
Claim
,
}
}
/// handle ud commands
/// handle ud commands
...
@@ -14,7 +14,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<(
...
@@ -14,7 +14,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<(
let
mut
data
=
data
.build_client
()
.await
?
;
let
mut
data
=
data
.build_client
()
.await
?
;
// match subcommand
// match subcommand
match
command
{
match
command
{
Subcommand
::
Claim
Uds
=>
{
Subcommand
::
Claim
=>
{
data
=
data
.build_keypair
();
data
=
data
.build_keypair
();
claim_ud
(
data
)
.await
?
;
claim_ud
(
data
)
.await
?
;
}
}
...
...
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