From 4564b06f48fd4c5a0410b2624975a9c08bea9808 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Tue, 20 Feb 2024 17:45:33 +0100 Subject: [PATCH 1/9] Add send_mana and prepare_send_mana --- .../operations/transaction/high_level/mod.rs | 1 + .../transaction/high_level/send_mana.rs | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 sdk/src/wallet/operations/transaction/high_level/send_mana.rs diff --git a/sdk/src/wallet/operations/transaction/high_level/mod.rs b/sdk/src/wallet/operations/transaction/high_level/mod.rs index 4834aa9328..0312a91efe 100644 --- a/sdk/src/wallet/operations/transaction/high_level/mod.rs +++ b/sdk/src/wallet/operations/transaction/high_level/mod.rs @@ -7,6 +7,7 @@ pub(crate) mod create_account; pub(crate) mod delegation; pub(crate) mod minting; pub(crate) mod send; +pub(crate) mod send_mana; pub(crate) mod send_native_tokens; pub(crate) mod send_nft; pub(crate) mod staking; diff --git a/sdk/src/wallet/operations/transaction/high_level/send_mana.rs b/sdk/src/wallet/operations/transaction/high_level/send_mana.rs new file mode 100644 index 0000000000..44437c6013 --- /dev/null +++ b/sdk/src/wallet/operations/transaction/high_level/send_mana.rs @@ -0,0 +1,51 @@ +// Copyright 2024 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +use crate::{ + client::{api::PreparedTransactionData, secret::SecretManage}, + types::block::{ + address::Bech32Address, + output::{unlock_condition::AddressUnlockCondition, BasicOutputBuilder}, + }, + utils::ConvertTo, + wallet::{ + operations::transaction::{TransactionOptions, TransactionWithMetadata}, + Wallet, + }, +}; + +impl Wallet +where + crate::wallet::Error: From, + crate::client::Error: From, +{ + pub async fn send_mana( + &self, + mana: u64, + address: impl ConvertTo, + options: impl Into> + Send, + ) -> crate::wallet::Result { + let options = options.into(); + let prepared_transaction = self.prepare_send_mana(mana, address, options.clone()).await?; + + self.sign_and_submit_transaction(prepared_transaction, options).await + } + + pub async fn prepare_send_mana( + &self, + mana: u64, + address: impl ConvertTo, + options: impl Into> + Send, + ) -> crate::wallet::Result { + log::debug!("[TRANSACTION] prepare_send_mana"); + let options = options.into(); + let storage_score_params = self.client().get_storage_score_parameters().await?; + + let output = BasicOutputBuilder::new_with_minimum_amount(storage_score_params) + .with_mana(mana) + .add_unlock_condition(AddressUnlockCondition::new(address.convert()?)) + .finish_output()?; + + self.prepare_transaction(vec![output], options).await + } +} From 0ea9c425efc90df7c39985ccf940a7c2e155d735 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Tue, 20 Feb 2024 18:02:15 +0100 Subject: [PATCH 2/9] Add send-mana to CLI --- cli/src/wallet_cli/mod.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cli/src/wallet_cli/mod.rs b/cli/src/wallet_cli/mod.rs index 5b7ff66755..a4efd2b1aa 100644 --- a/cli/src/wallet_cli/mod.rs +++ b/cli/src/wallet_cli/mod.rs @@ -272,6 +272,13 @@ pub enum WalletCommand { #[arg(long, default_value_t = false)] allow_micro_amount: bool, }, + /// Send mana. + SendMana { + /// Address to send mana to, e.g. rms1qztwng6cty8cfm42nzvq099ev7udhrnk0rw8jt8vttf9kpqnxhpsx869vr3. + address: Bech32Address, + /// Amount of mana to send, e.g. 1000000. + mana: u64, + }, /// Send a native token. /// This will create an output with an expiration and storage deposit return unlock condition. SendNativeToken { @@ -1033,6 +1040,23 @@ pub async fn send_command( Ok(()) } +// `send-mana` command +pub async fn send_mana_command( + wallet: &Wallet, + address: impl ConvertTo, + mana: u64, +) -> Result<(), Error> { + let transaction = wallet.send_mana(mana, address, None).await?; + + println_log_info!( + "Transaction sent:\n{:?}\n{:?}", + transaction.transaction_id, + transaction.block_id + ); + + Ok(()) +} + // `send-native-token` command pub async fn send_native_token_command( wallet: &Wallet, @@ -1557,6 +1581,10 @@ pub async fn prompt_internal( }; send_command(wallet, address, amount, return_address, expiration, allow_micro_amount).await } + WalletCommand::SendMana { address, mana } => { + ensure_password(wallet).await?; + send_mana_command(wallet, address, mana).await + } WalletCommand::SendNativeToken { address, token_id, From 4bfd88fa0dce734d7bedf0411a57f80793c3b8c1 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 22 Feb 2024 11:01:06 +0100 Subject: [PATCH 3/9] Add return_strategy --- Cargo.lock | 201 +++++++++--------- .../transaction/high_level/send_mana.rs | 33 ++- .../operations/transaction/prepare_output.rs | 2 +- 3 files changed, 124 insertions(+), 112 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 01d2d20049..ce584ab1fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,9 +29,9 @@ dependencies = [ [[package]] name = "aes" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac1f845298e95f983ff1944b728ae08b8cebab80d684f0a832ed0fc74dfa27e2" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" dependencies = [ "cfg-if", "cipher", @@ -54,9 +54,9 @@ dependencies = [ [[package]] name = "ahash" -version = "0.8.7" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" +checksum = "d713b3834d76b85304d4d525563c1276e2e30dc97cc67bfb4585a4a29fc2c89f" dependencies = [ "cfg-if", "once_cell", @@ -81,9 +81,9 @@ checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" [[package]] name = "anstream" -version = "0.6.11" +version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5" +checksum = "96b09b5178381e0874812a9b157f7fe84982617e48f71f4e3235482775e5b540" dependencies = [ "anstyle", "anstyle-parse", @@ -129,9 +129,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.79" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" +checksum = "5ad32ce52e4161730f7098c077cd2ed6229b5804ccf99e5366be1ab72a98b4e1" [[package]] name = "anymap" @@ -159,7 +159,7 @@ checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -268,7 +268,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -341,9 +341,9 @@ checksum = "f5353f36341f7451062466f0b755b96ac3a9547e4d7f6b70d603fc721a7d7896" [[package]] name = "bumpalo" -version = "3.14.0" +version = "3.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" +checksum = "a3b1be7772ee4501dba05acbe66bb1e8760f6a6c474a36035631638e4415f130" [[package]] name = "byte-slice-cast" @@ -376,11 +376,10 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.83" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +checksum = "7f9fa1897e4325be0d68d48df6aa1a71ac2ed4d27723887e7754192705350730" dependencies = [ - "jobserver", "libc", ] @@ -425,9 +424,9 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.33" +version = "0.4.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f13690e35a5e4ace198e7beea2895d29f3a9cc55015fcebe6336bd2010af9eb" +checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" dependencies = [ "num-traits", ] @@ -456,9 +455,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.0" +version = "4.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80c21025abd42669a92efc996ef13cfb2c5c627858421ea58d5c3b331a6c134f" +checksum = "c918d541ef2913577a0f9566e9ce27cb35b6df072075769e0b26cb5a554520da" dependencies = [ "clap_builder", "clap_derive", @@ -466,9 +465,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.0" +version = "4.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "458bf1f341769dfcf849846f65dffdf9146daa56bcd2a47cb4e1de9915567c99" +checksum = "9f3e7391dad68afb0c2ede1bf619f579a3dc9c2ec67f089baa397123a2f3d1eb" dependencies = [ "anstream", "anstyle", @@ -485,7 +484,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -519,9 +518,9 @@ dependencies = [ [[package]] name = "clipboard-win" -version = "5.1.0" +version = "5.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ec832972fefb8cf9313b45a0d1945e29c9c251f1d4c6eafc5fe2124c02d2e81" +checksum = "12f9a0700e0127ba15d1d52dd742097f821cd9c65939303a44d970465040a297" dependencies = [ "error-code", ] @@ -669,7 +668,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "30d2b3721e861707777e3195b0158f950ae6dc4a27e4d02ff9f67e3eb3de199e" dependencies = [ "quote", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -719,14 +718,14 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] name = "darling" -version = "0.20.5" +version = "0.20.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc5d6b04b3fd0ba9926f945895de7d806260a2d7431ba82e7edaecb043c4c6b8" +checksum = "c376d08ea6aa96aafe61237c7200d1241cb177b7d3a542d791f2d118e9cbb955" dependencies = [ "darling_core", "darling_macro", @@ -734,27 +733,27 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.20.5" +version = "0.20.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04e48a959bcd5c761246f5d090ebc2fbf7b9cd527a492b07a67510c108f1e7e3" +checksum = "33043dcd19068b8192064c704b3f83eb464f91f1ff527b44a4e2b08d9cdb8855" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", "strsim 0.10.0", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] name = "darling_macro" -version = "0.20.5" +version = "0.20.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d1545d67a2149e1d93b7e5c7752dce5a7426eb5d1357ddcfd89336b94444f77" +checksum = "c5a91391accf613803c2a9bf9abccdbaa07c54b4244a5b64883f9c3c137c86be" dependencies = [ "darling_core", "quote", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -815,7 +814,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -1170,7 +1169,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -1350,9 +1349,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0c62115964e08cb8039170eb33c1d0e2388a256930279edca206fff675f82c3" +checksum = "bd5256b483761cd23699d0da46cc6fd2ee3be420bbe6d020ae4a091e70b7e9fd" [[package]] name = "hex" @@ -1519,9 +1518,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.2" +version = "2.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "824b2ae422412366ba479e8111fd301f7b5faece8149317bb81925979a53f520" +checksum = "233cf39063f058ea2caae4091bf4a3ef70a653afbc026f5c4a4135d114e3c177" dependencies = [ "equivalent", "hashbrown", @@ -1750,9 +1749,9 @@ checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" [[package]] name = "is-terminal" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe8f25ce1159c7740ff0b9b2f5cdf4a8428742ba7c112b9f20f22cd5219c7dab" +checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" dependencies = [ "hermit-abi", "libc", @@ -1777,15 +1776,6 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" -[[package]] -name = "jobserver" -version = "0.1.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab46a6e9526ddef3ae7f787c06f0f2600639ba80ea3eade3d8e670a2230f51d6" -dependencies = [ - "libc", -] - [[package]] name = "js-sys" version = "0.3.68" @@ -1979,9 +1969,9 @@ dependencies = [ [[package]] name = "napi" -version = "2.15.1" +version = "2.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43792514b0c95c5beec42996da0c1b39265b02b75c97baa82d163d3ef55cbfa7" +checksum = "02bd92040344a83763379b122f4e714932ccaa700439e647f1e90481dd1999cb" dependencies = [ "bitflags 2.4.2", "ctor", @@ -1993,34 +1983,34 @@ dependencies = [ [[package]] name = "napi-build" -version = "2.1.0" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4b4532cf86bfef556348ac65e561e3123879f0e7566cca6d43a6ff5326f13df" +checksum = "2f9130fccc5f763cf2069b34a089a18f0d0883c66aceb81f2fad541a3d823c43" [[package]] name = "napi-derive" -version = "2.15.1" +version = "2.15.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d56bb899c164ab1be5e542ae7db8b26750c864bf2eef07295f17754e6358777" +checksum = "e56bd9f0bd84c1f138c5cb22bbf394f75d796b24dad689599ca94cf94e61cc21" dependencies = [ "cfg-if", "convert_case", "napi-derive-backend", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] name = "napi-derive-backend" -version = "1.0.60" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6cf2d74ac66fd1cccb646be75fdd1c1dce8acfe20a68f61566a31da0d3eb9786" +checksum = "d03b8f403a37007cad225039fc0323b961bb40d697eea744140920ebb689ff1d" dependencies = [ "convert_case", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -2101,9 +2091,9 @@ dependencies = [ [[package]] name = "num_threads" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" dependencies = [ "libc", ] @@ -2281,9 +2271,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] name = "platforms" @@ -2354,7 +2344,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5" dependencies = [ "proc-macro2", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -2468,7 +2458,7 @@ dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -2480,7 +2470,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -2646,16 +2636,17 @@ dependencies = [ [[package]] name = "ring" -version = "0.17.7" +version = "0.17.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "688c63d65483050968b2a8937f7995f443e27041a0f7700aa59b0822aedebb74" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" dependencies = [ "cc", + "cfg-if", "getrandom", "libc", "spin", "untrusted", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -2821,14 +2812,14 @@ checksum = "e5af959c8bf6af1aff6d2b463a57f71aae53d1332da58419e30ad8dc7011d951" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] name = "ryu" -version = "1.0.16" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" [[package]] name = "salsa20" @@ -2924,35 +2915,35 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.21" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" [[package]] name = "serde" -version = "1.0.196" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.196" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] name = "serde_json" -version = "1.0.113" +version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79" +checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" dependencies = [ "itoa", "ryu", @@ -2967,7 +2958,7 @@ checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -3184,7 +3175,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -3197,7 +3188,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -3219,9 +3210,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.48" +version = "2.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "74f1bdc9872430ce9b75da68329d1c1746faf50ffac5f19e02b71e37ff881ffb" dependencies = [ "proc-macro2", "quote", @@ -3263,28 +3254,28 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "target-lexicon" -version = "0.12.13" +version = "0.12.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69758bda2e78f098e4ccb393021a0963bb3442eac05f135c30f61b7370bbafae" +checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f" [[package]] name = "thiserror" -version = "1.0.56" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.56" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -3378,7 +3369,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -3458,7 +3449,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -3528,9 +3519,9 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-normalization" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" dependencies = [ "tinyvec", ] @@ -3653,7 +3644,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.50", "wasm-bindgen-shared", ] @@ -3687,7 +3678,7 @@ checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.50", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3951,9 +3942,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.39" +version = "0.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5389a154b01683d28c77f8f68f49dea75f0a4da32557a58f68ee51ebba472d29" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" dependencies = [ "memchr", ] @@ -4031,7 +4022,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -4052,5 +4043,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.50", ] diff --git a/sdk/src/wallet/operations/transaction/high_level/send_mana.rs b/sdk/src/wallet/operations/transaction/high_level/send_mana.rs index 44437c6013..2ffdb915e1 100644 --- a/sdk/src/wallet/operations/transaction/high_level/send_mana.rs +++ b/sdk/src/wallet/operations/transaction/high_level/send_mana.rs @@ -5,11 +5,14 @@ use crate::{ client::{api::PreparedTransactionData, secret::SecretManage}, types::block::{ address::Bech32Address, - output::{unlock_condition::AddressUnlockCondition, BasicOutputBuilder}, + output::{ + unlock_condition::{AddressUnlockCondition, StorageDepositReturnUnlockCondition}, + BasicOutputBuilder, + }, }, utils::ConvertTo, wallet::{ - operations::transaction::{TransactionOptions, TransactionWithMetadata}, + operations::transaction::{prepare_output::ReturnStrategy, TransactionOptions, TransactionWithMetadata}, Wallet, }, }; @@ -23,10 +26,13 @@ where &self, mana: u64, address: impl ConvertTo, + return_strategy: impl Into> + Send, options: impl Into> + Send, ) -> crate::wallet::Result { let options = options.into(); - let prepared_transaction = self.prepare_send_mana(mana, address, options.clone()).await?; + let prepared_transaction = self + .prepare_send_mana(mana, address, return_strategy, options.clone()) + .await?; self.sign_and_submit_transaction(prepared_transaction, options).await } @@ -35,16 +41,31 @@ where &self, mana: u64, address: impl ConvertTo, + return_strategy: impl Into> + Send, options: impl Into> + Send, ) -> crate::wallet::Result { log::debug!("[TRANSACTION] prepare_send_mana"); + let return_strategy = return_strategy.into().unwrap_or_default(); let options = options.into(); let storage_score_params = self.client().get_storage_score_parameters().await?; - let output = BasicOutputBuilder::new_with_minimum_amount(storage_score_params) + let mut output_builder = BasicOutputBuilder::new_with_minimum_amount(storage_score_params) .with_mana(mana) - .add_unlock_condition(AddressUnlockCondition::new(address.convert()?)) - .finish_output()?; + .add_unlock_condition(AddressUnlockCondition::new(address.convert()?)); + + if let ReturnStrategy::Return = return_strategy { + output_builder = output_builder.add_unlock_condition(StorageDepositReturnUnlockCondition::new( + self.address().await.inner().clone(), + 1, + )?); + let return_amount = output_builder.clone().finish()?.amount(); + output_builder = output_builder.replace_unlock_condition(StorageDepositReturnUnlockCondition::new( + self.address().await.inner().clone(), + return_amount, + )?); + } + + let output = output_builder.finish_output()?; self.prepare_transaction(vec![output], options).await } diff --git a/sdk/src/wallet/operations/transaction/prepare_output.rs b/sdk/src/wallet/operations/transaction/prepare_output.rs index 2d08f60fea..3daf27b867 100644 --- a/sdk/src/wallet/operations/transaction/prepare_output.rs +++ b/sdk/src/wallet/operations/transaction/prepare_output.rs @@ -113,7 +113,7 @@ where let min_amount_basic_output = BasicOutput::minimum_amount(&Address::from(Ed25519Address::null()), storage_score_params); - let min_required_storage_deposit = first_output.minimum_amount(storage_score_params); + let min_required_storage_deposit = first_output.amount(); if params.amount > min_required_storage_deposit { second_output_builder = second_output_builder.with_amount(params.amount); From b5690f7fae670c3aacffefc7733cea67b2b7d3c9 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 22 Feb 2024 11:05:29 +0100 Subject: [PATCH 4/9] Add SendManaParams --- .../transaction/high_level/send_mana.rs | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/sdk/src/wallet/operations/transaction/high_level/send_mana.rs b/sdk/src/wallet/operations/transaction/high_level/send_mana.rs index 2ffdb915e1..3c79b69cbb 100644 --- a/sdk/src/wallet/operations/transaction/high_level/send_mana.rs +++ b/sdk/src/wallet/operations/transaction/high_level/send_mana.rs @@ -1,6 +1,8 @@ // Copyright 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +use serde::{Deserialize, Serialize}; + use crate::{ client::{api::PreparedTransactionData, secret::SecretManage}, types::block::{ @@ -10,13 +12,23 @@ use crate::{ BasicOutputBuilder, }, }, - utils::ConvertTo, + utils::serde::string, wallet::{ operations::transaction::{prepare_output::ReturnStrategy, TransactionOptions, TransactionWithMetadata}, Wallet, }, }; +/// Params for `send_mana()`. +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct SendManaParams { + #[serde(with = "string")] + mana: u64, + address: Bech32Address, + return_strategy: Option, +} + impl Wallet where crate::wallet::Error: From, @@ -24,34 +36,27 @@ where { pub async fn send_mana( &self, - mana: u64, - address: impl ConvertTo, - return_strategy: impl Into> + Send, + params: SendManaParams, options: impl Into> + Send, ) -> crate::wallet::Result { let options = options.into(); - let prepared_transaction = self - .prepare_send_mana(mana, address, return_strategy, options.clone()) - .await?; + let prepared_transaction = self.prepare_send_mana(params, options.clone()).await?; self.sign_and_submit_transaction(prepared_transaction, options).await } pub async fn prepare_send_mana( &self, - mana: u64, - address: impl ConvertTo, - return_strategy: impl Into> + Send, + params: SendManaParams, options: impl Into> + Send, ) -> crate::wallet::Result { log::debug!("[TRANSACTION] prepare_send_mana"); - let return_strategy = return_strategy.into().unwrap_or_default(); - let options = options.into(); + let return_strategy = params.return_strategy.unwrap_or_default(); let storage_score_params = self.client().get_storage_score_parameters().await?; let mut output_builder = BasicOutputBuilder::new_with_minimum_amount(storage_score_params) - .with_mana(mana) - .add_unlock_condition(AddressUnlockCondition::new(address.convert()?)); + .with_mana(params.mana) + .add_unlock_condition(AddressUnlockCondition::new(params.address)); if let ReturnStrategy::Return = return_strategy { output_builder = output_builder.add_unlock_condition(StorageDepositReturnUnlockCondition::new( From 9bdebde7bfcb5373d763ba4ebda4f00df903322a Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 22 Feb 2024 11:06:29 +0100 Subject: [PATCH 5/9] match return_strategy --- .../transaction/high_level/send_mana.rs | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/sdk/src/wallet/operations/transaction/high_level/send_mana.rs b/sdk/src/wallet/operations/transaction/high_level/send_mana.rs index 3c79b69cbb..47153ee075 100644 --- a/sdk/src/wallet/operations/transaction/high_level/send_mana.rs +++ b/sdk/src/wallet/operations/transaction/high_level/send_mana.rs @@ -58,16 +58,19 @@ where .with_mana(params.mana) .add_unlock_condition(AddressUnlockCondition::new(params.address)); - if let ReturnStrategy::Return = return_strategy { - output_builder = output_builder.add_unlock_condition(StorageDepositReturnUnlockCondition::new( - self.address().await.inner().clone(), - 1, - )?); - let return_amount = output_builder.clone().finish()?.amount(); - output_builder = output_builder.replace_unlock_condition(StorageDepositReturnUnlockCondition::new( - self.address().await.inner().clone(), - return_amount, - )?); + match return_strategy { + ReturnStrategy::Return => { + output_builder = output_builder.add_unlock_condition(StorageDepositReturnUnlockCondition::new( + self.address().await.inner().clone(), + 1, + )?); + let return_amount = output_builder.clone().finish()?.amount(); + output_builder = output_builder.replace_unlock_condition(StorageDepositReturnUnlockCondition::new( + self.address().await.inner().clone(), + return_amount, + )?); + } + ReturnStrategy::Gift => {} } let output = output_builder.finish_output()?; From 5f1b79c9a9b4655cda5fcabbd1901d3297b24b30 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 22 Feb 2024 11:12:06 +0100 Subject: [PATCH 6/9] Adapt CLI --- cli/src/wallet_cli/mod.rs | 7 ++++--- sdk/src/wallet/mod.rs | 1 + .../transaction/high_level/send_mana.rs | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/cli/src/wallet_cli/mod.rs b/cli/src/wallet_cli/mod.rs index a4efd2b1aa..87d3530a4f 100644 --- a/cli/src/wallet_cli/mod.rs +++ b/cli/src/wallet_cli/mod.rs @@ -24,8 +24,8 @@ use iota_sdk::{ utils::ConvertTo, wallet::{ types::OutputData, BeginStakingParams, ConsolidationParams, CreateDelegationParams, CreateNativeTokenParams, - Error as WalletError, MintNftParams, OutputsToClaim, SendNativeTokenParams, SendNftParams, SendParams, - SyncOptions, TransactionOptions, Wallet, + Error as WalletError, MintNftParams, OutputsToClaim, SendManaParams, SendNativeTokenParams, SendNftParams, + SendParams, SyncOptions, TransactionOptions, Wallet, }, U256, }; @@ -1046,7 +1046,8 @@ pub async fn send_mana_command( address: impl ConvertTo, mana: u64, ) -> Result<(), Error> { - let transaction = wallet.send_mana(mana, address, None).await?; + let params = SendManaParams::new(mana, address.convert()?); + let transaction = wallet.send_mana(params, None).await?; println_log_info!( "Transaction sent:\n{:?}\n{:?}", diff --git a/sdk/src/wallet/mod.rs b/sdk/src/wallet/mod.rs index 65dc73ccb4..9cc6316633 100644 --- a/sdk/src/wallet/mod.rs +++ b/sdk/src/wallet/mod.rs @@ -62,6 +62,7 @@ pub use self::{ mint_nfts::MintNftParams, }, send::SendParams, + send_mana::SendManaParams, send_native_tokens::SendNativeTokenParams, send_nft::SendNftParams, staking::begin::BeginStakingParams, diff --git a/sdk/src/wallet/operations/transaction/high_level/send_mana.rs b/sdk/src/wallet/operations/transaction/high_level/send_mana.rs index 47153ee075..cad5629277 100644 --- a/sdk/src/wallet/operations/transaction/high_level/send_mana.rs +++ b/sdk/src/wallet/operations/transaction/high_level/send_mana.rs @@ -29,6 +29,21 @@ pub struct SendManaParams { return_strategy: Option, } +impl SendManaParams { + pub fn new(mana: u64, address: Bech32Address) -> Self { + Self { + mana, + address, + return_strategy: None, + } + } + + pub fn with_return_strategy(mut self, return_strategy: ReturnStrategy) -> Self { + self.return_strategy.replace(return_strategy); + self + } +} + impl Wallet where crate::wallet::Error: From, From d2dfe093ea68bbc54ee9b990e9faadd75145cea2 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 22 Feb 2024 12:19:51 +0100 Subject: [PATCH 7/9] gift --- cli/src/wallet_cli/mod.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/cli/src/wallet_cli/mod.rs b/cli/src/wallet_cli/mod.rs index 87d3530a4f..ad9faf623b 100644 --- a/cli/src/wallet_cli/mod.rs +++ b/cli/src/wallet_cli/mod.rs @@ -24,8 +24,8 @@ use iota_sdk::{ utils::ConvertTo, wallet::{ types::OutputData, BeginStakingParams, ConsolidationParams, CreateDelegationParams, CreateNativeTokenParams, - Error as WalletError, MintNftParams, OutputsToClaim, SendManaParams, SendNativeTokenParams, SendNftParams, - SendParams, SyncOptions, TransactionOptions, Wallet, + Error as WalletError, MintNftParams, OutputsToClaim, ReturnStrategy, SendManaParams, SendNativeTokenParams, + SendNftParams, SendParams, SyncOptions, TransactionOptions, Wallet, }, U256, }; @@ -278,6 +278,8 @@ pub enum WalletCommand { address: Bech32Address, /// Amount of mana to send, e.g. 1000000. mana: u64, + #[arg(short, long, default_value_t = false)] + gift: bool, }, /// Send a native token. /// This will create an output with an expiration and storage deposit return unlock condition. @@ -1045,8 +1047,13 @@ pub async fn send_mana_command( wallet: &Wallet, address: impl ConvertTo, mana: u64, + gift: bool, ) -> Result<(), Error> { - let params = SendManaParams::new(mana, address.convert()?); + let params = SendManaParams::new(mana, address.convert()?).with_return_strategy(if gift { + ReturnStrategy::Gift + } else { + ReturnStrategy::Return + }); let transaction = wallet.send_mana(params, None).await?; println_log_info!( @@ -1582,9 +1589,9 @@ pub async fn prompt_internal( }; send_command(wallet, address, amount, return_address, expiration, allow_micro_amount).await } - WalletCommand::SendMana { address, mana } => { + WalletCommand::SendMana { address, mana, gift } => { ensure_password(wallet).await?; - send_mana_command(wallet, address, mana).await + send_mana_command(wallet, address, mana, gift).await } WalletCommand::SendNativeToken { address, From 29dea5d16de4b3c9cfc1e06724301acb58d8e468 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 22 Feb 2024 12:21:18 +0100 Subject: [PATCH 8/9] Comment --- cli/src/wallet_cli/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/src/wallet_cli/mod.rs b/cli/src/wallet_cli/mod.rs index ad9faf623b..dc32b97363 100644 --- a/cli/src/wallet_cli/mod.rs +++ b/cli/src/wallet_cli/mod.rs @@ -278,6 +278,7 @@ pub enum WalletCommand { address: Bech32Address, /// Amount of mana to send, e.g. 1000000. mana: u64, + /// Whether to gift the storage deposit or not. #[arg(short, long, default_value_t = false)] gift: bool, }, From 19100f4191085015385eacfb9bf4fd5eda379726 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 22 Feb 2024 17:19:13 +0100 Subject: [PATCH 9/9] Update cli/src/wallet_cli/mod.rs Co-authored-by: DaughterOfMars --- cli/src/wallet_cli/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/wallet_cli/mod.rs b/cli/src/wallet_cli/mod.rs index dc32b97363..e167e3ea69 100644 --- a/cli/src/wallet_cli/mod.rs +++ b/cli/src/wallet_cli/mod.rs @@ -274,7 +274,7 @@ pub enum WalletCommand { }, /// Send mana. SendMana { - /// Address to send mana to, e.g. rms1qztwng6cty8cfm42nzvq099ev7udhrnk0rw8jt8vttf9kpqnxhpsx869vr3. + /// Recipient address, e.g. rms1qztwng6cty8cfm42nzvq099ev7udhrnk0rw8jt8vttf9kpqnxhpsx869vr3. address: Bech32Address, /// Amount of mana to send, e.g. 1000000. mana: u64,