Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/iota-sdk/examples/generic_move_function.rs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example isn't about make_move_vec and tbh it's a worse way to use the builder so I say revert this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, do you think we should have a separate example about .make_move_vec then?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, maybe

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async fn main() -> Result<()> {
builder
.move_call(Address::FRAMEWORK, "vec_map", "from_keys_values")
.generics::<(Address, u64)>()
.arguments((vec![address1, address2], vec![10000000u64, 20000000u64]));
.arguments(([address1, address2], [10000000u64, 20000000u64]));

let res = builder.dry_run(false).await?;

Expand Down
35 changes: 35 additions & 0 deletions crates/iota-transaction-builder/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,41 @@ impl<C, L> TransactionBuilder<C, L> {
}

/// Make a move vector from a list of elements.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should also mention something like:

/// Often it is possible (and more efficient) to pass a rust slice or `Vec` instead of calling this function, which will serialize the bytes into a move vector pure argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, makes sense to add this comment, Can you come up with a valid use-case? Then I'ld add another example just for that, because currently .make_move_vec is not covered I think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know of a valid use-case other than if there's something we can't do with the normal syntax that I'm not thinking of

///
/// Often it is possible (and more efficient) to pass a rust slice or `Vec`
/// instead of calling this function, which will serialize the bytes into a
/// move vector pure argument.
///
/// # Example
///
/// ```
/// # use std::str::FromStr;
/// # use iota_transaction_builder::{TransactionBuilder, res};
/// # use iota_types::{Address, Transaction};
///
/// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() -> eyre::Result<()> {
/// let client = iota_graphql_client::Client::new_devnet();
/// let sender = "0x71b4b4f171b4355ff691b7c470579cf1a926f96f724e5f9a30efc4b5f75d085e".parse()?;
///
/// let mut builder = TransactionBuilder::new(sender).with_client(client);
///
/// let address1 =
/// Address::from_str("0xde49ea53fbadee67d3e35a097cdbea210b659676fc680a0b0c5f11d0763d375e")?;
/// let address2 =
/// Address::from_str("0xe512234aa4ef6184c52663f09612b68f040dd0c45de037d96190a071ca5525b3")?;
///
/// builder
/// .make_move_vec([address1, address2])
/// .name("addresses")
/// .move_call(Address::FRAMEWORK, "vec_map", "from_keys_values")
/// .generics::<(Address, u64)>()
/// .arguments((res("addresses"), [10000000u64, 20000000u64]));
///
/// let txn: Transaction = builder.finish().await?;
/// # Ok(())
/// # }
/// ```
pub fn make_move_vec<T: PTBArgument + MoveType>(
&mut self,
elements: impl IntoIterator<Item = T>,
Expand Down