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
30bafa01
Commit
30bafa01
authored
2 years ago
by
Hugo Trentesaux
Browse files
Options
Downloads
Patches
Plain Diff
feat: batch transfer
parent
44cefc17
No related branches found
No related tags found
1 merge request
!2
feat: batch transfer
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+4
-0
4 additions, 0 deletions
README.md
res/metadata.scale
+0
-0
0 additions, 0 deletions
res/metadata.scale
src/commands/transfer.rs
+33
-0
33 additions, 0 deletions
src/commands/transfer.rs
src/main.rs
+25
-5
25 additions, 5 deletions
src/main.rs
with
62 additions
and
5 deletions
README.md
+
4
−
0
View file @
30bafa01
...
@@ -2,6 +2,10 @@
...
@@ -2,6 +2,10 @@
CLI client for
[
Duniter-V2S
](
https://git.duniter.org/nodes/rust/duniter-v2s/
)
.
CLI client for
[
Duniter-V2S
](
https://git.duniter.org/nodes/rust/duniter-v2s/
)
.
Using
-
https://github.com/duniter/substrate
-
https://github.com/duniter/subxt
## Usage
## Usage
If using a different runtime, update the metadata for the client to compile:
If using a different runtime, update the metadata for the client to compile:
...
...
This diff is collapsed.
Click to expand it.
res/metadata.scale
+
0
−
0
View file @
30bafa01
No preview for this file type
This diff is collapsed.
Click to expand it.
src/commands/transfer.rs
+
33
−
0
View file @
30bafa01
...
@@ -4,6 +4,9 @@ use anyhow::Result;
...
@@ -4,6 +4,9 @@ use anyhow::Result;
use
sp_core
::{
crypto
::
AccountId32
,
sr25519
::
Pair
};
use
sp_core
::{
crypto
::
AccountId32
,
sr25519
::
Pair
};
use
subxt
::
tx
::{
BaseExtrinsicParamsBuilder
,
PairSigner
};
use
subxt
::
tx
::{
BaseExtrinsicParamsBuilder
,
PairSigner
};
type
Call
=
gdev
::
runtime_types
::
gdev_runtime
::
Call
;
type
BalancesCall
=
gdev
::
runtime_types
::
pallet_balances
::
pallet
::
Call
;
pub
async
fn
transfer
(
pub
async
fn
transfer
(
pair
:
Pair
,
pair
:
Pair
,
client
:
Client
,
client
:
Client
,
...
@@ -35,3 +38,33 @@ pub async fn transfer(
...
@@ -35,3 +38,33 @@ pub async fn transfer(
Ok
(())
Ok
(())
}
}
pub
async
fn
transfer_multiple
(
pair
:
Pair
,
client
:
Client
,
amount
:
u64
,
dests
:
Vec
<
AccountId32
>
,
)
->
Result
<
()
>
{
// build the list of transactions from the destination accounts
let
transactions
:
Vec
<
Call
>
=
dests
.into_iter
()
.map
(|
dest
|
{
Call
::
Balances
(
BalancesCall
::
transfer_keep_alive
{
dest
:
dest
.into
(),
value
:
amount
,
})
})
.collect
();
// wrap these calls in a batch call
client
.tx
()
.sign_and_submit_then_watch
(
&
gdev
::
tx
()
.utility
()
.batch
(
transactions
),
&
PairSigner
::
new
(
pair
.clone
()),
BaseExtrinsicParamsBuilder
::
new
(),
)
.await
?
;
Ok
(())
}
This diff is collapsed.
Click to expand it.
src/main.rs
+
25
−
5
View file @
30bafa01
...
@@ -127,11 +127,22 @@ pub enum Subcommand {
...
@@ -127,11 +127,22 @@ pub enum Subcommand {
new_key
:
sp_core
::
crypto
::
AccountId32
,
new_key
:
sp_core
::
crypto
::
AccountId32
,
},
},
Transfer
{
Transfer
{
balance
:
u64
,
/// Amount to transfer
amount
:
u64
,
/// Destination address
dest
:
sp_core
::
crypto
::
AccountId32
,
dest
:
sp_core
::
crypto
::
AccountId32
,
#[clap(short
=
'k'
)]
/// Prevent from going below account existential deposit
#[clap(short
=
'k'
,
long
=
"keep-alive"
)]
keep_alive
:
bool
,
keep_alive
:
bool
,
},
},
/// Transfer the same amount for each space-separated address.
/// If an address appears mutiple times, it will get multiple times the same amount
TransferMultiple
{
/// Amount given to each destination address
amount
:
u64
,
/// List of target addresses
dests
:
Vec
<
sp_core
::
crypto
::
AccountId32
>
,
},
/// Rotate and set session keys
/// Rotate and set session keys
UpdateKeys
,
UpdateKeys
,
}
}
...
@@ -174,7 +185,7 @@ async fn main() -> Result<()> {
...
@@ -174,7 +185,7 @@ async fn main() -> Result<()> {
println!
(
"Account address: {}"
,
account_id
);
println!
(
"Account address: {}"
,
account_id
);
}
}
let
client
=
Client
::
new
()
.await
.unwrap
()
;
let
client
=
Client
::
new
()
.await
?
;
if
let
Some
(
account_id
)
=
&
account_id
{
if
let
Some
(
account_id
)
=
&
account_id
{
let
account
=
client
let
account
=
client
...
@@ -272,19 +283,28 @@ async fn main() -> Result<()> {
...
@@ -272,19 +283,28 @@ async fn main() -> Result<()> {
.await
?
.await
?
}
}
Subcommand
::
Transfer
{
Subcommand
::
Transfer
{
balance
,
amount
,
dest
,
dest
,
keep_alive
,
keep_alive
,
}
=>
{
}
=>
{
commands
::
transfer
::
transfer
(
commands
::
transfer
::
transfer
(
pair
.expect
(
"This subcommand needs a secret."
),
pair
.expect
(
"This subcommand needs a secret."
),
client
,
client
,
balance
,
amount
,
dest
,
dest
,
keep_alive
,
keep_alive
,
)
)
.await
?
.await
?
}
}
Subcommand
::
TransferMultiple
{
amount
,
dests
}
=>
{
commands
::
transfer
::
transfer_multiple
(
pair
.expect
(
"This subcommand needs a secret."
),
client
,
amount
,
dests
,
)
.await
?
}
Subcommand
::
UpdateKeys
=>
commands
::
smith
::
update_session_keys
(
Subcommand
::
UpdateKeys
=>
commands
::
smith
::
update_session_keys
(
pair
.expect
(
"This subcommand needs a secret."
),
pair
.expect
(
"This subcommand needs a secret."
),
client
,
client
,
...
...
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