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
93590643
Commit
93590643
authored
1 year ago
by
Hugo Trentesaux
Committed by
Hugo Trentesaux
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
split main in runtime and utils
parent
8b2da794
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/main.rs
+18
-116
18 additions, 116 deletions
src/main.rs
src/runtime_config.rs
+53
-0
53 additions, 0 deletions
src/runtime_config.rs
src/utils.rs
+55
-0
55 additions, 0 deletions
src/utils.rs
with
126 additions
and
116 deletions
src/main.rs
+
18
−
116
View file @
93590643
...
...
@@ -4,73 +4,22 @@ mod conf;
mod
data
;
mod
indexer
;
mod
keys
;
mod
runtime_config
;
mod
utils
;
use
anyhow
::
anyhow
;
use
clap
::
Parser
;
use
codec
::
Encode
;
use
data
::
*
;
use
keys
::
*
;
use
runtime_config
::
*
;
use
serde
::
Deserialize
;
use
sp_core
::{
sr25519
::
Pair
,
Pair
as
_
};
use
subxt
::
blocks
::
ExtrinsicEvents
;
use
subxt
::
tx
::{
BaseExtrinsicParamsBuilder
,
PairSigner
,
TxStatus
};
use
utils
::
*
;
#[cfg(feature
=
"gdev"
)]
#[subxt::subxt(
runtime_metadata_path
=
"res/metadata.scale"
,
derive_for_all_types
=
"Debug"
)]
pub
mod
runtime
{
// IF NEEDED
// #[subxt(substitute_type = "spcore::sr25519::Signature")]
// use crate::gdev::runtime_types::sp_core::sr25519::Signature;
}
// declare custom types
pub
type
Client
=
subxt
::
OnlineClient
<
Runtime
>
;
pub
type
AccountId
=
subxt
::
ext
::
sp_runtime
::
AccountId32
;
pub
type
TxInBlock
=
subxt
::
tx
::
TxInBlock
<
Runtime
,
Client
>
;
pub
type
TxProgress
=
subxt
::
tx
::
TxProgress
<
Runtime
,
Client
>
;
pub
type
Balance
=
u64
;
pub
type
AccountData
=
runtime
::
runtime_types
::
pallet_duniter_account
::
types
::
AccountData
<
Balance
>
;
pub
type
AccountInfo
=
runtime
::
runtime_types
::
frame_system
::
AccountInfo
<
u32
,
AccountData
>
;
pub
type
Hash
=
sp_core
::
H256
;
// declare runtime types
pub
enum
Runtime
{}
impl
subxt
::
config
::
Config
for
Runtime
{
type
Index
=
u32
;
type
BlockNumber
=
u32
;
type
Hash
=
Hash
;
type
Hashing
=
subxt
::
ext
::
sp_runtime
::
traits
::
BlakeTwo256
;
type
AccountId
=
AccountId
;
type
Address
=
subxt
::
ext
::
sp_runtime
::
MultiAddress
<
Self
::
AccountId
,
u32
>
;
type
Header
=
subxt
::
ext
::
sp_runtime
::
generic
::
Header
<
Self
::
BlockNumber
,
subxt
::
ext
::
sp_runtime
::
traits
::
BlakeTwo256
,
>
;
type
Signature
=
subxt
::
ext
::
sp_runtime
::
MultiSignature
;
type
ExtrinsicParams
=
subxt
::
tx
::
BaseExtrinsicParams
<
Self
,
Tip
>
;
}
// Tip for transaction fee
#[derive(Copy,
Clone,
Debug,
Default,
codec::Encode)]
pub
struct
Tip
{
#[codec(compact)]
tip
:
u64
,
}
impl
Tip
{
pub
fn
new
(
amount
:
u64
)
->
Self
{
Tip
{
tip
:
amount
}
}
}
impl
From
<
u64
>
for
Tip
{
fn
from
(
n
:
u64
)
->
Self
{
Self
::
new
(
n
)
}
}
// define command line arguments
/// define command line arguments
#[derive(Clone,
clap::Parser,
Debug,
Default)]
#[clap(author,
version,
about,
long_about
=
None)]
pub
struct
Args
{
...
...
@@ -101,60 +50,7 @@ pub struct Args {
network
:
Option
<
String
>
,
}
/// track progress of transaction on the network
/// until it is in block with success or failure
pub
async
fn
track_progress
(
mut
progress
:
TxProgress
,
)
->
Result
<
ExtrinsicEvents
<
Runtime
>
,
subxt
::
Error
>
{
loop
{
if
let
Some
(
status
)
=
progress
.next_item
()
.await
{
match
status
?
{
TxStatus
::
Ready
=>
{
println!
(
"transaction submitted to the network, waiting 6 seconds..."
);
}
TxStatus
::
InBlock
(
in_block
)
=>
break
in_block
,
TxStatus
::
Invalid
=>
{
println!
(
"Invalid"
);
}
_
=>
continue
,
}
}
}
.wait_for_success
()
.await
}
/// custom error type intended to provide more convenient error message to user
#[derive(Debug)]
pub
enum
GcliError
{
/// error coming from subxt
Subxt
(
subxt
::
Error
),
/// error coming from duniter
Duniter
(
String
),
/// error coming from indexer
Indexer
(
String
),
/// logic error (illegal operation or security)
Logic
(
String
),
/// error coming from anyhow
Anyhow
(
anyhow
::
Error
),
}
impl
std
::
fmt
::
Display
for
GcliError
{
fn
fmt
(
&
self
,
f
:
&
mut
std
::
fmt
::
Formatter
)
->
std
::
fmt
::
Result
{
write!
(
f
,
"{:?}"
,
self
)
}
}
impl
std
::
error
::
Error
for
GcliError
{}
impl
From
<
subxt
::
Error
>
for
GcliError
{
fn
from
(
e
:
subxt
::
Error
)
->
GcliError
{
GcliError
::
Subxt
(
e
)
}
}
impl
From
<
anyhow
::
Error
>
for
GcliError
{
fn
from
(
e
:
anyhow
::
Error
)
->
GcliError
{
GcliError
::
Anyhow
(
e
)
}
}
/// define subcommands
#[derive(Clone,
Debug,
clap::Subcommand,
Default)]
pub
enum
Subcommand
{
#[clap(hide
=
true
)]
...
...
@@ -166,9 +62,7 @@ pub enum Subcommand {
actual_repart
:
Option
<
u32
>
,
},
#[clap(hide
=
true
)]
SpamRoll
{
actual_repart
:
usize
,
},
SpamRoll
{
actual_repart
:
usize
},
/// Get information about runtime
RuntimeInfo
,
#[default]
...
...
@@ -200,6 +94,7 @@ pub enum Subcommand {
Config
(
conf
::
Subcommand
),
}
/// maint function
#[tokio::main(flavor
=
"current_thread"
)]
async
fn
main
()
->
Result
<
(),
GcliError
>
{
// init logger
...
...
@@ -209,6 +104,7 @@ async fn main() -> Result<(), GcliError> {
let
args
=
Args
::
parse
();
let
mut
data
=
Data
::
new
(
args
.clone
());
// match subcommands
match
args
.subcommand
{
Subcommand
::
Repart
{
target
,
...
...
@@ -262,10 +158,16 @@ async fn main() -> Result<(), GcliError> {
.unwrap
()
);
}
Subcommand
::
Account
(
subcommand
)
=>
commands
::
account
::
handle_command
(
data
,
subcommand
)
.await
?
,
Subcommand
::
Identity
(
subcommand
)
=>
commands
::
identity
::
handle_command
(
data
,
subcommand
)
.await
?
,
Subcommand
::
Account
(
subcommand
)
=>
{
commands
::
account
::
handle_command
(
data
,
subcommand
)
.await
?
}
Subcommand
::
Identity
(
subcommand
)
=>
{
commands
::
identity
::
handle_command
(
data
,
subcommand
)
.await
?
}
Subcommand
::
Smith
(
subcommand
)
=>
commands
::
smith
::
handle_command
(
data
,
subcommand
)
.await
?
,
Subcommand
::
Tech
(
subcommand
)
=>
commands
::
collective
::
handle_command
(
data
,
subcommand
)
.await
?
,
Subcommand
::
Tech
(
subcommand
)
=>
{
commands
::
collective
::
handle_command
(
data
,
subcommand
)
.await
?
}
Subcommand
::
Ud
(
subcommand
)
=>
commands
::
ud
::
handle_command
(
data
,
subcommand
)
.await
?
,
Subcommand
::
Oneshot
(
subcommand
)
=>
{
commands
::
oneshot
::
handle_command
(
data
,
subcommand
)
.await
?
...
...
This diff is collapsed.
Click to expand it.
src/runtime_config.rs
0 → 100644
+
53
−
0
View file @
93590643
#[cfg(feature
=
"gdev"
)]
#[subxt::subxt(
runtime_metadata_path
=
"res/metadata.scale"
,
derive_for_all_types
=
"Debug"
)]
pub
mod
runtime
{
// IF NEEDED
// #[subxt(substitute_type = "spcore::sr25519::Signature")]
// use crate::gdev::runtime_types::sp_core::sr25519::Signature;
}
// declare custom types
pub
type
Client
=
subxt
::
OnlineClient
<
Runtime
>
;
pub
type
AccountId
=
subxt
::
ext
::
sp_runtime
::
AccountId32
;
pub
type
TxProgress
=
subxt
::
tx
::
TxProgress
<
Runtime
,
Client
>
;
pub
type
Balance
=
u64
;
pub
type
AccountData
=
runtime
::
runtime_types
::
pallet_duniter_account
::
types
::
AccountData
<
Balance
>
;
pub
type
AccountInfo
=
runtime
::
runtime_types
::
frame_system
::
AccountInfo
<
u32
,
AccountData
>
;
pub
type
Hash
=
sp_core
::
H256
;
// declare runtime types
pub
enum
Runtime
{}
impl
subxt
::
config
::
Config
for
Runtime
{
type
Index
=
u32
;
type
BlockNumber
=
u32
;
type
Hash
=
Hash
;
type
Hashing
=
subxt
::
ext
::
sp_runtime
::
traits
::
BlakeTwo256
;
type
AccountId
=
AccountId
;
type
Address
=
subxt
::
ext
::
sp_runtime
::
MultiAddress
<
Self
::
AccountId
,
u32
>
;
type
Header
=
subxt
::
ext
::
sp_runtime
::
generic
::
Header
<
Self
::
BlockNumber
,
subxt
::
ext
::
sp_runtime
::
traits
::
BlakeTwo256
,
>
;
type
Signature
=
subxt
::
ext
::
sp_runtime
::
MultiSignature
;
type
ExtrinsicParams
=
subxt
::
tx
::
BaseExtrinsicParams
<
Self
,
Tip
>
;
}
// Tip for transaction fee
#[derive(Copy,
Clone,
Debug,
Default,
codec::Encode)]
pub
struct
Tip
{
#[codec(compact)]
tip
:
u64
,
}
impl
Tip
{
pub
fn
new
(
amount
:
u64
)
->
Self
{
Tip
{
tip
:
amount
}
}
}
impl
From
<
u64
>
for
Tip
{
fn
from
(
n
:
u64
)
->
Self
{
Self
::
new
(
n
)
}
}
This diff is collapsed.
Click to expand it.
src/utils.rs
0 → 100644
+
55
−
0
View file @
93590643
use
crate
::
*
;
/// track progress of transaction on the network
/// until it is in block with success or failure
pub
async
fn
track_progress
(
mut
progress
:
TxProgress
,
)
->
Result
<
ExtrinsicEvents
<
Runtime
>
,
subxt
::
Error
>
{
loop
{
if
let
Some
(
status
)
=
progress
.next_item
()
.await
{
match
status
?
{
TxStatus
::
Ready
=>
{
println!
(
"transaction submitted to the network, waiting 6 seconds..."
);
}
TxStatus
::
InBlock
(
in_block
)
=>
break
in_block
,
TxStatus
::
Invalid
=>
{
println!
(
"Invalid"
);
}
_
=>
continue
,
}
}
}
.wait_for_success
()
.await
}
/// custom error type intended to provide more convenient error message to user
#[derive(Debug)]
pub
enum
GcliError
{
/// error coming from subxt
Subxt
(
subxt
::
Error
),
/// error coming from duniter
Duniter
(
String
),
/// error coming from indexer
Indexer
(
String
),
/// logic error (illegal operation or security)
Logic
(
String
),
/// error coming from anyhow
Anyhow
(
anyhow
::
Error
),
}
impl
std
::
fmt
::
Display
for
GcliError
{
fn
fmt
(
&
self
,
f
:
&
mut
std
::
fmt
::
Formatter
)
->
std
::
fmt
::
Result
{
write!
(
f
,
"{:?}"
,
self
)
}
}
impl
std
::
error
::
Error
for
GcliError
{}
impl
From
<
subxt
::
Error
>
for
GcliError
{
fn
from
(
e
:
subxt
::
Error
)
->
GcliError
{
GcliError
::
Subxt
(
e
)
}
}
impl
From
<
anyhow
::
Error
>
for
GcliError
{
fn
from
(
e
:
anyhow
::
Error
)
->
GcliError
{
GcliError
::
Anyhow
(
e
)
}
}
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