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
c7d143f3
Commit
c7d143f3
authored
1 year ago
by
Hugo Trentesaux
Committed by
Hugo Trentesaux
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
move blockchain commands to subcommand
parent
93590643
No related branches found
No related tags found
1 merge request
!7
Big refacto
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/commands/blockchain.rs
+52
-0
52 additions, 0 deletions
src/commands/blockchain.rs
src/commands/net_test.rs
+6
-6
6 additions, 6 deletions
src/commands/net_test.rs
src/main.rs
+19
-78
19 additions, 78 deletions
src/main.rs
with
77 additions
and
84 deletions
src/commands/blockchain.rs
+
52
−
0
View file @
c7d143f3
use
crate
::
*
;
/// define blockchain subcommands
#[derive(Clone,
Default,
Debug,
clap::Parser)]
pub
enum
Subcommand
{
#[clap(hide
=
true
)]
Repart
{
// Number of transactions per block to target
target
:
u32
,
#[clap(short
=
'o'
,
long
=
"old-repart"
)]
// Old/actual repartition
actual_repart
:
Option
<
u32
>
,
},
#[clap(hide
=
true
)]
SpamRoll
{
actual_repart
:
usize
},
/// Get information about runtime
RuntimeInfo
,
/// Check current block
#[default]
CurrentBlock
,
}
/// handle blockchain commands
pub
async
fn
handle_command
(
data
:
Data
,
command
:
Subcommand
)
->
anyhow
::
Result
<
()
>
{
let
mut
data
=
data
.build_client
()
.await
?
.build_indexer
()
.await
?
;
match
command
{
Subcommand
::
Repart
{
target
,
actual_repart
,
}
=>
{
commands
::
net_test
::
repart
(
&
data
,
target
,
actual_repart
)
.await
?
}
Subcommand
::
SpamRoll
{
actual_repart
}
=>
{
commands
::
net_test
::
spam_roll
(
&
data
,
actual_repart
)
.await
?
}
Subcommand
::
RuntimeInfo
=>
{
data
=
data
.fetch_system_properties
()
.await
?
;
commands
::
runtime
::
runtime_info
(
data
)
.await
;
}
Subcommand
::
CurrentBlock
=>
{
println!
(
"current block on {}: {}"
,
data
.cfg.duniter_endpoint
,
data
.client
()
.storage
()
.fetch
(
&
runtime
::
storage
()
.system
()
.number
(),
None
)
.await
?
.unwrap
()
);
}
}
Ok
(())
}
/// get genesis hash
pub
async
fn
fetch_genesis_hash
(
data
:
&
Data
)
->
Result
<
Hash
,
anyhow
::
Error
>
{
Ok
(
data
...
...
This diff is collapsed.
Click to expand it.
src/commands/net_test.rs
+
6
−
6
View file @
c7d143f3
...
...
@@ -4,14 +4,13 @@ use sp_core::DeriveJunction;
use
subxt
::
ext
::
sp_runtime
::
MultiAddress
;
pub
async
fn
repart
(
pair
:
Pair
,
client
:
&
Client
,
data
:
&
Data
,
target
:
u32
,
actual_repart
:
Option
<
u32
>
,
)
->
anyhow
::
Result
<
()
>
{
let
mut
pairs
=
Vec
::
new
();
for
i
in
actual_repart
.unwrap_or_default
()
..
target
{
let
pair_i
=
pair
let
pair_i
=
data
.key
pair
()
.derive
(
std
::
iter
::
once
(
DeriveJunction
::
hard
::
<
u32
>
(
i
)),
None
)
.map_err
(|
_
|
anyhow!
(
"Fail to derive //{}"
,
i
))
?
.0
;
...
...
@@ -29,7 +28,7 @@ pub async fn repart(
.await?;
signer.increment_nonce();*/
if
let
Some
(
pair_i_account
)
=
client
if
let
Some
(
pair_i_account
)
=
data
.
client
()
.storage
()
.fetch
(
&
runtime
::
storage
()
.system
()
.account
(
&
pair_i
.public
()
.into
()),
...
...
@@ -44,11 +43,12 @@ pub async fn repart(
Ok
(())
}
pub
async
fn
spam_roll
(
pair
:
Pair
,
client
:
&
Client
,
actual_repart
:
usize
)
->
anyhow
::
Result
<
()
>
{
pub
async
fn
spam_roll
(
data
:
&
Data
,
actual_repart
:
usize
)
->
anyhow
::
Result
<
()
>
{
let
client
=
data
.client
();
let
mut
nonce
=
0
;
let
mut
pairs
=
Vec
::
<
(
PairSigner
<
Runtime
,
Pair
>
,
AccountId
)
>
::
with_capacity
(
actual_repart
);
for
i
in
0
..
actual_repart
{
let
pair_i
=
pair
let
pair_i
=
data
.key
pair
()
.derive
(
std
::
iter
::
once
(
DeriveJunction
::
hard
::
<
u32
>
(
i
as
u32
)),
None
)
.map_err
(|
_
|
anyhow!
(
"Fail to derive //{}"
,
i
))
?
.0
;
...
...
This diff is collapsed.
Click to expand it.
src/main.rs
+
19
−
78
View file @
c7d143f3
...
...
@@ -45,7 +45,7 @@ pub struct Args {
/// Overwrite duniter websocket RPC endpoint
#[clap(short,
long)]
url
:
Option
<
String
>
,
///
Chose t
arget network
///
T
arget network
(local, gdev, gtest...)
#[clap(short,
long)]
network
:
Option
<
String
>
,
}
...
...
@@ -53,43 +53,35 @@ pub struct Args {
/// define subcommands
#[derive(Clone,
Debug,
clap::Subcommand,
Default)]
pub
enum
Subcommand
{
#[clap(hide
=
true
)]
Repart
{
// Number of transactions per block to target
target
:
u32
,
#[clap(short
=
'o'
,
long
=
"old-repart"
)]
// Old/actual repartition
actual_repart
:
Option
<
u32
>
,
},
#[clap(hide
=
true
)]
SpamRoll
{
actual_repart
:
usize
},
/// Get information about runtime
RuntimeInfo
,
/// Nothing
#[default]
/// Check current block
CurrentBlock
,
/// Account
subcommands
#[clap(hide
=
true
)]
DoNothing
,
/// Account
(balance, transfer...)
#[clap(subcommand)]
Account
(
commands
::
account
::
Subcommand
),
/// Identity
subcommands
/// Identity
(get, create, confirm, revoke...)
#[clap(subcommand)]
Identity
(
commands
::
identity
::
Subcommand
),
/// Smith
subcommands
/// Smith
(certify, go-online, go-offline...)
#[clap(subcommand)]
Smith
(
commands
::
smith
::
Subcommand
),
/// Tech
subcommands
/// Tech
(list members, proposals, vote...)
#[clap(subcommand)]
Tech
(
commands
::
collective
::
Subcommand
),
/// Universal Dividend
subcommands
/// Universal Dividend
(claim...)
#[clap(subcommand)]
Ud
(
commands
::
ud
::
Subcommand
),
/// Oneshot account
subcommands
/// Oneshot account
(balance, create, consume...)
#[clap(subcommand)]
Oneshot
(
commands
::
oneshot
::
Subcommand
),
/// Indexer subcommands
/// Blockchain (current block, runtime info...)
#[clap(subcommand)]
Blockchain
(
commands
::
blockchain
::
Subcommand
),
/// Indexer (check, latest block)
#[clap(subcommand)]
Indexer
(
indexer
::
Subcommand
),
/// Config
subcommands
/// Config
(show, save...)
#[clap(subcommand)]
Config
(
conf
::
Subcommand
),
}
...
...
@@ -101,63 +93,11 @@ async fn main() -> Result<(), GcliError> {
env_logger
::
init
();
// parse argument and initialize data
let
args
=
Args
::
parse
();
let
mut
data
=
Data
::
new
(
args
.clone
());
let
data
=
Data
::
new
(
Args
::
parse
());
// match subcommands
match
args
.subcommand
{
Subcommand
::
Repart
{
target
,
actual_repart
,
}
=>
{
data
=
data
.build_client
()
.await
?
;
commands
::
net_test
::
repart
(
get_keys
(
args
.secret_format
,
&
args
.address
,
&
args
.secret
,
NeededKeys
::
Secret
,
)
?
.1
.unwrap
(),
data
.client
(),
target
,
actual_repart
,
)
.await
?
}
Subcommand
::
SpamRoll
{
actual_repart
}
=>
{
data
=
data
.build_client
()
.await
?
;
commands
::
net_test
::
spam_roll
(
get_keys
(
args
.secret_format
,
&
args
.address
,
&
args
.secret
,
NeededKeys
::
Secret
,
)
?
.1
.unwrap
(),
data
.client
(),
actual_repart
,
)
.await
?
}
Subcommand
::
RuntimeInfo
=>
{
data
=
data
.build_client
()
.await
?
.fetch_system_properties
()
.await
?
;
commands
::
runtime
::
runtime_info
(
data
)
.await
;
}
Subcommand
::
CurrentBlock
=>
{
data
=
data
.build_client
()
.await
?
;
println!
(
"current block on {}: {}"
,
data
.cfg.duniter_endpoint
,
data
.client
()
.storage
()
.fetch
(
&
runtime
::
storage
()
.system
()
.number
(),
None
)
.await
?
.unwrap
()
);
}
match
data
.args.subcommand
.clone
()
{
Subcommand
::
DoNothing
=>
{}
Subcommand
::
Account
(
subcommand
)
=>
{
commands
::
account
::
handle_command
(
data
,
subcommand
)
.await
?
}
...
...
@@ -172,6 +112,7 @@ async fn main() -> Result<(), GcliError> {
Subcommand
::
Oneshot
(
subcommand
)
=>
{
commands
::
oneshot
::
handle_command
(
data
,
subcommand
)
.await
?
}
Subcommand
::
Blockchain
(
subcommand
)
=>
commands
::
blockchain
::
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