Skip to content
Snippets Groups Projects
Commit fa9169b9 authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

add commented transfer

parent 8820e6de
No related branches found
No related tags found
1 merge request!34Draft: tx comments
...@@ -16,3 +16,4 @@ pub mod sudo; ...@@ -16,3 +16,4 @@ pub mod sudo;
pub mod transfer; pub mod transfer;
pub mod ud; pub mod ud;
pub mod vault; pub mod vault;
pub mod commented;
...@@ -12,12 +12,15 @@ pub enum Subcommand { ...@@ -12,12 +12,15 @@ pub enum Subcommand {
amount: u64, amount: u64,
/// Destination address /// Destination address
dest: AccountId, dest: AccountId,
/// Prevent from going below account existential deposit /// Allow going below account existential deposit
#[clap(short = 'k', long = "keep-alive")] #[clap(short = 'k', long = "allow-death")]
keep_alive: bool, allow_death: bool,
/// Use universal dividends instead of units /// Use universal dividends instead of units
#[clap(short = 'u', long = "ud")] #[clap(short = 'u', long = "ud")]
is_ud: bool, is_ud: bool,
/// Add a transaction comment
#[clap(short = 'c', long = "comment")]
comment: Option<String>,
}, },
/// Transfer the same amount for each space-separated address. /// Transfer the same amount for each space-separated address.
/// If an address appears mutiple times, it will get multiple times the same amount /// If an address appears mutiple times, it will get multiple times the same amount
...@@ -39,10 +42,20 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE ...@@ -39,10 +42,20 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
Subcommand::Transfer { Subcommand::Transfer {
amount, amount,
dest, dest,
keep_alive, allow_death,
is_ud, is_ud,
comment,
} => { } => {
commands::transfer::transfer(&data, amount, dest, keep_alive, is_ud).await?; if let Some(comment) = comment {
if is_ud || allow_death {
return Err(GcliError::Input(
"ud or allow death commented transfers are not handled yet".to_string(),
));
}
commands::commented::transfer(&data, amount, dest, comment).await?;
} else {
commands::transfer::transfer(&data, amount, dest, allow_death, is_ud).await?;
}
} }
Subcommand::TransferMultiple { amount, dests } => { Subcommand::TransferMultiple { amount, dests } => {
commands::transfer::transfer_multiple(&data, amount, dests).await?; commands::transfer::transfer_multiple(&data, amount, dests).await?;
......
use crate::*;
#[cfg(any(feature = "dev", feature = "gdev"))] // find how to get runtime calls
type Call = runtime::runtime_types::gdev_runtime::RuntimeCall;
type BalancesCall = runtime::runtime_types::pallet_balances::pallet::Call;
type SystemCall = runtime::runtime_types::frame_system::pallet::Call;
/// commented balance transfer
pub async fn transfer(
data: &Data,
amount: u64,
dest: AccountId,
comment: String,
) -> Result<(), subxt::Error> {
// build transfer call
let transfer_call = Call::Balances(BalancesCall::transfer_keep_alive {
dest: dest.into(),
value: amount,
});
// build comment call
let comment_call = Call::System(SystemCall::remark_with_event {
remark: comment.as_bytes().to_vec(),
});
// wrap these calls in a batch call
submit_call_and_look_event::<
runtime::utility::events::BatchCompleted,
Payload<runtime::utility::calls::types::Batch>,
>(
data,
&runtime::tx()
.utility()
.batch(vec![transfer_call, comment_call]),
)
.await
}
...@@ -9,11 +9,11 @@ pub async fn transfer( ...@@ -9,11 +9,11 @@ pub async fn transfer(
data: &Data, data: &Data,
balance: u64, balance: u64,
dest: AccountId, dest: AccountId,
keep_alive: bool, allow_deat: bool,
is_ud: bool, is_ud: bool,
) -> Result<(), subxt::Error> { ) -> Result<(), subxt::Error> {
match (keep_alive, is_ud) { match (allow_deat, is_ud) {
(true, false) => { (false, false) => {
submit_call_and_look_event::< submit_call_and_look_event::<
runtime::balances::events::Transfer, runtime::balances::events::Transfer,
Payload<runtime::balances::calls::types::TransferKeepAlive>, Payload<runtime::balances::calls::types::TransferKeepAlive>,
...@@ -25,7 +25,7 @@ pub async fn transfer( ...@@ -25,7 +25,7 @@ pub async fn transfer(
) )
.await .await
} }
(false, false) => { (true, false) => {
submit_call_and_look_event::< submit_call_and_look_event::<
runtime::balances::events::Transfer, runtime::balances::events::Transfer,
Payload<runtime::balances::calls::types::TransferAllowDeath>, Payload<runtime::balances::calls::types::TransferAllowDeath>,
...@@ -37,7 +37,7 @@ pub async fn transfer( ...@@ -37,7 +37,7 @@ pub async fn transfer(
) )
.await .await
} }
(true, true) => { (false, true) => {
submit_call_and_look_event::< submit_call_and_look_event::<
runtime::balances::events::Transfer, runtime::balances::events::Transfer,
Payload<runtime::universal_dividend::calls::types::TransferUdKeepAlive>, Payload<runtime::universal_dividend::calls::types::TransferUdKeepAlive>,
...@@ -49,7 +49,7 @@ pub async fn transfer( ...@@ -49,7 +49,7 @@ pub async fn transfer(
) )
.await .await
} }
(false, true) => { (true, true) => {
submit_call_and_look_event::< submit_call_and_look_event::<
runtime::balances::events::Transfer, runtime::balances::events::Transfer,
Payload<runtime::universal_dividend::calls::types::TransferUd>, Payload<runtime::universal_dividend::calls::types::TransferUd>,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment