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
24978eb6
Commit
24978eb6
authored
1 year ago
by
Hugo Trentesaux
Committed by
Hugo Trentesaux
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
refac move onshot commands to subcommand
parent
2b90e624
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!7
Big refacto
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/commands/oneshot.rs
+104
-38
104 additions, 38 deletions
src/commands/oneshot.rs
src/commands/ud.rs
+23
-21
23 additions, 21 deletions
src/commands/ud.rs
src/main.rs
+6
-85
6 additions, 85 deletions
src/main.rs
with
133 additions
and
144 deletions
src/commands/oneshot.rs
+
104
−
38
View file @
24978eb6
use
crate
::
*
;
use
sp_core
::{
crypto
::
AccountId32
,
sr25519
::
Pair
};
use
subxt
::
tx
::{
BaseExtrinsicParamsBuilder
,
PairSigner
};
/// define oneshot account subcommands
#[derive(Clone,
Default,
Debug,
clap::Parser)]
pub
enum
Subcommand
{
/// get balance of oneshot account
#[default]
Balance
,
/// create a oneshot account
Create
{
balance
:
u64
,
dest
:
AccountId
},
/// consume a oneshot account
Consume
{
dest
:
AccountId
,
#[clap(long
=
"oneshot"
)]
dest_oneshot
:
bool
,
},
/// consume a oneshot account whith remaining sent to an other account
ConsumeWithRemaining
{
balance
:
u64
,
dest
:
AccountId
,
#[clap(long
=
"one"
)]
dest_oneshot
:
bool
,
remaining_to
:
AccountId
,
#[clap(long
=
"rem-one"
)]
remaining_to_oneshot
:
bool
,
},
}
/// handle oneshot commands
pub
async
fn
handle_command
(
data
:
Data
,
command
:
Subcommand
)
->
anyhow
::
Result
<
()
>
{
// build indexer because it is needed for all subcommands
let
mut
data
=
data
.build_client
()
.await
?
;
// match subcommand
match
command
{
Subcommand
::
Balance
=>
oneshot_account_balance
(
&
data
)
.await
?
,
Subcommand
::
Create
{
balance
,
dest
}
=>
{
data
=
data
.build_client
()
.await
?
;
create_oneshot_account
(
&
data
,
balance
,
dest
)
.await
?
;
}
Subcommand
::
Consume
{
dest
,
dest_oneshot
}
=>
{
data
=
data
.build_client
()
.await
?
;
consume_oneshot_account
(
&
data
,
dest
,
dest_oneshot
)
.await
?
;
}
Subcommand
::
ConsumeWithRemaining
{
balance
,
dest
,
dest_oneshot
,
remaining_to
,
remaining_to_oneshot
,
}
=>
{
data
=
data
.build_client
()
.await
?
;
consume_oneshot_account_with_remaining
(
&
data
,
balance
,
dest
,
dest_oneshot
,
remaining_to
,
remaining_to_oneshot
,
)
.await
?
;
}
};
Ok
(())
}
/// get balance of oneshot account
pub
async
fn
oneshot_account_balance
(
data
:
&
Data
)
->
Result
<
(),
anyhow
::
Error
>
{
println!
(
"balance of oneshot account {} is: {}"
,
data
.address
(),
data
.client
()
.storage
()
.fetch
(
&
runtime
::
storage
()
.oneshot_account
()
.oneshot_accounts
(
data
.address
()),
None
)
.await
?
.unwrap_or
(
0
)
);
Ok
(())
}
/// create oneshot account
pub
async
fn
create_oneshot_account
(
pair
:
Pair
,
client
:
&
Client
,
data
:
&
Data
,
balance
:
u64
,
dest
:
AccountId
32
,
dest
:
AccountId
,
)
->
Result
<
(),
subxt
::
Error
>
{
let
progress
=
client
let
progress
=
data
.client
()
.tx
()
.sign_and_submit_then_watch
(
&
runtime
::
tx
()
.oneshot_account
()
.create_oneshot_account
(
dest
.into
(),
balance
),
&
PairSigner
::
new
(
pair
),
&
PairSigner
::
new
(
data
.key
pair
()
),
BaseExtrinsicParamsBuilder
::
new
(),
)
.await
?
;
...
...
@@ -29,12 +111,15 @@ pub async fn create_oneshot_account(
Ok
(())
}
/// consume oneshot account
pub
async
fn
consume_oneshot_account
(
pair
:
Pair
,
client
:
&
Client
,
dest
:
AccountId
32
,
data
:
&
Data
,
dest
:
AccountId
,
dest_oneshot
:
bool
,
)
->
Result
<
(),
subxt
::
Error
>
{
let
client
=
data
.client
();
let
number
=
client
.storage
()
.fetch
(
&
runtime
::
storage
()
.system
()
.number
(),
None
)
...
...
@@ -55,7 +140,7 @@ pub async fn consume_oneshot_account(
)
},
),
&
PairSigner
::
new
(
pair
),
&
PairSigner
::
new
(
data
.key
pair
()
),
BaseExtrinsicParamsBuilder
::
new
(),
)
.await
?
;
...
...
@@ -69,15 +154,18 @@ pub async fn consume_oneshot_account(
Ok
(())
}
/// consume oneshot account with remaining
pub
async
fn
consume_oneshot_account_with_remaining
(
pair
:
Pair
,
client
:
&
Client
,
data
:
&
Data
,
balance
:
u64
,
dest
:
AccountId
32
,
dest
:
AccountId
,
dest_oneshot
:
bool
,
remaining_to
:
AccountId
32
,
remaining_to
:
AccountId
,
remaining_to_oneshot
:
bool
,
)
->
Result
<
(),
subxt
::
Error
>
{
let
client
=
data
.client
();
let
number
=
client
.storage
()
.fetch
(
&
runtime
::
storage
()
.system
()
.number
(),
None
)
...
...
@@ -110,7 +198,7 @@ pub async fn consume_oneshot_account_with_remaining(
},
balance
,
),
&
PairSigner
::
new
(
pair
),
&
PairSigner
::
new
(
data
.key
pair
()
),
BaseExtrinsicParamsBuilder
::
new
(),
)
.await
?
;
...
...
@@ -123,25 +211,3 @@ pub async fn consume_oneshot_account_with_remaining(
}
Ok
(())
}
pub
async
fn
oneshot_account_balance
(
client
:
&
Client
,
account
:
AccountId32
,
)
->
Result
<
(),
anyhow
::
Error
>
{
println!
(
"balance of oneshot account {} is: {}"
,
&
account
,
client
.storage
()
.fetch
(
&
runtime
::
storage
()
.oneshot_account
()
.oneshot_accounts
(
&
account
),
None
)
.await
?
.unwrap_or
(
0
)
);
Ok
(())
}
This diff is collapsed.
Click to expand it.
src/commands/ud.rs
+
23
−
21
View file @
24978eb6
use
crate
::
*
;
pub
async
fn
claim_ud
(
data
:
Data
)
->
Result
<
(),
anyhow
::
Error
>
{
let
progress
=
data
.client
()
.tx
()
.sign_and_submit_then_watch
(
&
runtime
::
tx
()
.universal_dividend
()
.claim_uds
(),
&
PairSigner
::
new
(
data
.keypair
()),
BaseExtrinsicParamsBuilder
::
new
(),
)
.await
?
;
let
events
=
track_progress
(
progress
)
.await
?
;
if
let
Some
(
e
)
=
events
.find_first
::
<
runtime
::
universal_dividend
::
events
::
UdsClaimed
>
()
?
{
println!
(
"{e:?}"
);
}
Ok
(())
}
/// define universal dividends subcommands
#[derive(Clone,
Default,
Debug,
clap::Parser)]
pub
enum
Subcommand
{
#[default]
...
...
@@ -33,10 +15,30 @@ pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<(
// match subcommand
match
command
{
Subcommand
::
ClaimUds
=>
{
data
=
data
.build_keypair
();
data
=
data
.build_keypair
();
claim_ud
(
data
)
.await
?
;
}
};
Ok
(())
Ok
(())
}
/// claim universal dividend
pub
async
fn
claim_ud
(
data
:
Data
)
->
Result
<
(),
anyhow
::
Error
>
{
let
progress
=
data
.client
()
.tx
()
.sign_and_submit_then_watch
(
&
runtime
::
tx
()
.universal_dividend
()
.claim_uds
(),
&
PairSigner
::
new
(
data
.keypair
()),
BaseExtrinsicParamsBuilder
::
new
(),
)
.await
?
;
let
events
=
track_progress
(
progress
)
.await
?
;
if
let
Some
(
e
)
=
events
.find_first
::
<
runtime
::
universal_dividend
::
events
::
UdsClaimed
>
()
?
{
println!
(
"{e:?}"
);
}
Ok
(())
}
This diff is collapsed.
Click to expand it.
src/main.rs
+
6
−
85
View file @
24978eb6
...
...
@@ -187,27 +187,6 @@ pub enum Subcommand {
GenRevocDoc
,
/// Revoke an identity immediately
RevokeIdentity
,
CreateOneshot
{
balance
:
u64
,
dest
:
AccountId
,
},
ConsumeOneshot
{
dest
:
AccountId
,
#[clap(long
=
"oneshot"
)]
dest_oneshot
:
bool
,
},
ConsumeOneshotWithRemaining
{
balance
:
u64
,
dest
:
AccountId
,
#[clap(long
=
"one"
)]
dest_oneshot
:
bool
,
remaining_to
:
AccountId
,
#[clap(long
=
"rem-one"
)]
remaining_to_oneshot
:
bool
,
},
OneshotBalance
{
account
:
AccountId
,
},
/// List upcoming expirations that require an action
Expire
{
/// Show certs that expire within less than this number of blocks
...
...
@@ -276,6 +255,9 @@ pub enum Subcommand {
RuntimeInfo
,
/// Check current block
CurrentBlock
,
/// Oneshot account subcommands
#[clap(subcommand)]
Oneshot
(
commands
::
oneshot
::
Subcommand
),
/// Universal Dividend subcommands
#[clap(subcommand)]
Ud
(
commands
::
ud
::
Subcommand
),
...
...
@@ -327,66 +309,6 @@ async fn main() -> Result<(), GcliError> {
.await
?
;
commands
::
identity
::
revoke_identity
(
data
)
.await
?
;
}
Subcommand
::
CreateOneshot
{
balance
,
dest
}
=>
{
data
=
data
.build_client
()
.await
?
;
commands
::
oneshot
::
create_oneshot_account
(
get_keys
(
args
.secret_format
,
&
args
.address
,
&
args
.secret
,
NeededKeys
::
Secret
,
)
?
.1
.unwrap
(),
data
.client
(),
balance
,
dest
,
)
.await
?
;
}
Subcommand
::
ConsumeOneshot
{
dest
,
dest_oneshot
}
=>
{
data
=
data
.build_client
()
.await
?
;
commands
::
oneshot
::
consume_oneshot_account
(
get_keys
(
args
.secret_format
,
&
args
.address
,
&
args
.secret
,
NeededKeys
::
Secret
,
)
?
.1
.unwrap
(),
data
.client
(),
dest
,
dest_oneshot
,
)
.await
?
;
}
Subcommand
::
ConsumeOneshotWithRemaining
{
balance
,
dest
,
dest_oneshot
,
remaining_to
,
remaining_to_oneshot
,
}
=>
{
data
=
data
.build_client
()
.await
?
;
commands
::
oneshot
::
consume_oneshot_account_with_remaining
(
get_keys
(
args
.secret_format
,
&
args
.address
,
&
args
.secret
,
NeededKeys
::
Secret
,
)
?
.1
.unwrap
(),
data
.client
(),
balance
,
dest
,
dest_oneshot
,
remaining_to
,
remaining_to_oneshot
,
)
.await
?
;
}
Subcommand
::
Expire
{
blocks
,
sessions
}
=>
{
data
=
data
.build_client
()
.await
?
;
commands
::
expire
::
monitor_expirations
(
&
data
,
blocks
,
sessions
)
.await
?
...
...
@@ -444,10 +366,6 @@ async fn main() -> Result<(), GcliError> {
)
.await
?
;
}
Subcommand
::
OneshotBalance
{
account
}
=>
{
data
=
data
.build_client
()
.await
?
;
commands
::
oneshot
::
oneshot_account_balance
(
data
.client
(),
account
)
.await
?
}
Subcommand
::
Online
=>
{
data
=
data
.build_client
()
.await
?
;
commands
::
smith
::
online
(
&
data
)
.await
?
...
...
@@ -602,6 +520,9 @@ async fn main() -> Result<(), GcliError> {
.unwrap
()
);
}
Subcommand
::
Oneshot
(
subcommand
)
=>
{
commands
::
oneshot
::
handle_command
(
data
,
subcommand
)
.await
?
}
Subcommand
::
Ud
(
subcommand
)
=>
commands
::
ud
::
handle_command
(
data
,
subcommand
)
.await
?
,
Subcommand
::
Indexer
(
subcommand
)
=>
indexer
::
handle_command
(
data
,
subcommand
)
.await
?
,
Subcommand
::
Config
(
subcommand
)
=>
conf
::
handle_command
(
data
,
subcommand
)
?
,
...
...
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