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
44cefc17
Verified
Commit
44cefc17
authored
2 years ago
by
Pascal Engélibert
Browse files
Options
Downloads
Patches
Plain Diff
feat: Smith commands
parent
7fb2a001
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.rs
+1
-0
1 addition, 0 deletions
src/commands.rs
src/commands/smith.rs
+78
-0
78 additions, 0 deletions
src/commands/smith.rs
src/main.rs
+25
-1
25 additions, 1 deletion
src/main.rs
with
104 additions
and
1 deletion
src/commands.rs
+
1
−
0
View file @
44cefc17
...
...
@@ -2,5 +2,6 @@ pub mod expire;
pub
mod
net_test
;
pub
mod
oneshot
;
pub
mod
revocation
;
pub
mod
smith
;
pub
mod
sudo
;
pub
mod
transfer
;
This diff is collapsed.
Click to expand it.
src/commands/smith.rs
0 → 100644
+
78
−
0
View file @
44cefc17
use
crate
::{
gdev
,
Client
};
use
anyhow
::{
anyhow
,
Result
};
use
sp_core
::{
crypto
::
AccountId32
,
sr25519
::
Pair
,
Pair
as
_
};
use
std
::
ops
::
Deref
;
use
subxt
::
tx
::{
BaseExtrinsicParamsBuilder
,
PairSigner
};
type
SessionKeys
=
[
u8
;
128
];
pub
async
fn
rotate_keys
(
client
:
&
Client
)
->
Result
<
SessionKeys
>
{
client
.rpc
()
.rotate_keys
()
.await
?
.deref
()
.try_into
()
.map_err
(|
e
|
anyhow!
(
"Session keys have wrong length: {:?}"
,
e
))
}
pub
async
fn
set_session_keys
(
pair
:
Pair
,
client
:
Client
,
session_keys
:
SessionKeys
)
->
Result
<
()
>
{
client
.tx
()
.sign_and_submit_then_watch
(
&
gdev
::
tx
()
.authority_members
()
.set_session_keys
(
session_keys
),
&
PairSigner
::
new
(
pair
),
BaseExtrinsicParamsBuilder
::
new
(),
)
.await
?
;
Ok
(())
}
pub
async
fn
update_session_keys
(
pair
:
Pair
,
client
:
Client
)
->
Result
<
()
>
{
let
session_keys
=
rotate_keys
(
&
client
)
.await
?
;
set_session_keys
(
pair
,
client
,
session_keys
)
.await
}
pub
async
fn
go_online
(
pair
:
Pair
,
client
:
Client
)
->
Result
<
()
>
{
if
client
.storage
()
.fetch
(
&
gdev
::
storage
()
.session
()
.next_keys
(
AccountId32
::
from
(
pair
.public
())),
None
,
)
.await
?
.is_none
()
{
return
Err
(
anyhow!
(
"This account has not set session keys!"
));
}
client
.tx
()
.sign_and_submit_then_watch
(
&
gdev
::
tx
()
.authority_members
()
.go_online
(),
&
PairSigner
::
new
(
pair
),
BaseExtrinsicParamsBuilder
::
new
(),
)
.await
?
;
Ok
(())
}
pub
async
fn
go_offline
(
pair
:
Pair
,
client
:
Client
)
->
Result
<
()
>
{
client
.tx
()
.sign_and_submit_then_watch
(
&
gdev
::
tx
()
.authority_members
()
.go_offline
(),
&
PairSigner
::
new
(
pair
),
BaseExtrinsicParamsBuilder
::
new
(),
)
.await
?
;
Ok
(())
}
This diff is collapsed.
Click to expand it.
src/main.rs
+
25
−
1
View file @
44cefc17
...
...
@@ -106,6 +106,8 @@ pub enum Subcommand {
},
/// Generate a revocation document for the provided account
GenRevocDoc
,
GoOffline
,
GoOnline
,
OneshotBalance
{
account
:
sp_core
::
crypto
::
AccountId32
,
},
...
...
@@ -118,7 +120,9 @@ pub enum Subcommand {
actual_repart
:
Option
<
u32
>
,
},
#[clap(hide
=
true
)]
SpamRoll
{
actual_repart
:
usize
},
SpamRoll
{
actual_repart
:
usize
,
},
SudoSetKey
{
new_key
:
sp_core
::
crypto
::
AccountId32
,
},
...
...
@@ -128,6 +132,8 @@ pub enum Subcommand {
#[clap(short
=
'k'
)]
keep_alive
:
bool
,
},
/// Rotate and set session keys
UpdateKeys
,
}
#[tokio::main(flavor
=
"current_thread"
)]
...
...
@@ -164,6 +170,10 @@ async fn main() -> Result<()> {
(
None
,
None
)
=>
(
None
,
None
),
};
if
let
Some
(
account_id
)
=
&
account_id
{
println!
(
"Account address: {}"
,
account_id
);
}
let
client
=
Client
::
new
()
.await
.unwrap
();
if
let
Some
(
account_id
)
=
&
account_id
{
...
...
@@ -222,6 +232,14 @@ async fn main() -> Result<()> {
)
.await
?
}
Subcommand
::
GoOffline
=>
{
commands
::
smith
::
go_offline
(
pair
.expect
(
"This subcommand needs a secret."
),
client
)
.await
?
}
Subcommand
::
GoOnline
=>
{
commands
::
smith
::
go_online
(
pair
.expect
(
"This subcommand needs a secret."
),
client
)
.await
?
}
Subcommand
::
OneshotBalance
{
account
}
=>
{
commands
::
oneshot
::
oneshot_account_balance
(
client
,
account
)
.await
?
}
...
...
@@ -267,6 +285,12 @@ async fn main() -> Result<()> {
)
.await
?
}
Subcommand
::
UpdateKeys
=>
commands
::
smith
::
update_session_keys
(
pair
.expect
(
"This subcommand needs a secret."
),
client
,
)
.await
.unwrap
(),
}
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