Skip to content
Open
572 changes: 274 additions & 298 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ iota-rest-kv = { path = "crates/iota-rest-kv" }
iota-rosetta = { path = "crates/iota-rosetta" }
iota-rpc-loadgen = { path = "crates/iota-rpc-loadgen" }
iota-sdk = { path = "crates/iota-sdk" }
iota-sdk-types = { git = "https://github.com/iotaledger/iota-rust-sdk.git", rev = "e7dde3b255e30354b895d15a010bf26bdfd10c90", default-features = false }
iota-sdk-types = { git = "https://github.com/iotaledger/iota-rust-sdk.git", rev = "fa43f106d7866b2f0fd5603ceab17a3b6f641776", default-features = false }
iota-simulator = { path = "crates/iota-simulator" }
iota-snapshot = { path = "crates/iota-snapshot" }
iota-source-validation = { path = "crates/iota-source-validation" }
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-e2e-tests/tests/dynamic_committee_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl StressTestRunner {

fn split_off(builder: &mut ProgrammableTransactionBuilder, amount: u64) -> Argument {
let amt_arg = builder.pure(amount).unwrap();
builder.command(Command::SplitCoins(Argument::GasCoin, vec![amt_arg]))
builder.command(Command::SplitCoins(Argument::Gas, vec![amt_arg]))
}

async fn get_from_effects(&self, effects: &[(ObjectRef, Owner)], name: &str) -> Option<Object> {
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-genesis-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ test-outputs = ["dep:iota-sdk-crypto"]

[target.'cfg(not(msim))'.dependencies]
# iota-sdk-crypto is only used when compiling test-outputs feature
iota-sdk-crypto = { git = "https://github.com/iotaledger/iota-rust-sdk.git", rev = "d8cdab6ab3f2fd9ba8059ba56e80ba950badc88d", optional = true, features = ["ed25519", "mnemonic"] }
iota-sdk-crypto = { git = "https://github.com/iotaledger/iota-rust-sdk.git", rev = "fa43f106d7866b2f0fd5603ceab17a3b6f641776", optional = true, features = ["ed25519", "mnemonic"] }

[[example]]
name = "snapshot_add_test_outputs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,11 @@ impl From<NativeArgument> for TransactionArgument {
use NativeArgument as N;
use TransactionArgument as A;
match argument {
N::GasCoin => A::GasCoin(GasCoin { dummy: None }),
N::Gas => A::GasCoin(GasCoin { dummy: None }),
Copy link
Member Author

Choose a reason for hiding this comment

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

I think I would actually keep it GasCoin in the SDK, opinions?

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer Gas

Copy link
Member Author

Choose a reason for hiding this comment

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

It would be inconsistent with its counterpart in the monorepo still called GasCoin

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, but so are many things we are doing in the SDK

N::Input(ix) => A::Input(Input { ix }),
N::Result(cmd) => A::Result(TxResult { cmd, ix: None }),
N::NestedResult(cmd, ix) => A::Result(TxResult { cmd, ix: Some(ix) }),
_ => unimplemented!("a new enum variant was added and needs to be handled"),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@ impl Merge<&CommandOutputReadSource<'_>> for CommandOutput {
self.argument = source
.arg
.map(|arg| -> Result<_, Box<dyn std::error::Error>> {
let sdk_arg: iota_sdk_types::Argument = arg.into();
sdk_arg.try_into().map_err(Into::into)
arg.try_into().map_err(Into::into)
})
.transpose()?;
}
Expand Down
3 changes: 2 additions & 1 deletion crates/iota-json-rpc-types/src/iota_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2264,10 +2264,11 @@ impl Display for IotaArgument {
impl From<Argument> for IotaArgument {
fn from(value: Argument) -> Self {
match value {
Argument::GasCoin => Self::GasCoin,
Argument::Gas => Self::GasCoin,
Argument::Input(i) => Self::Input(i),
Argument::Result(i) => Self::Result(i),
Argument::NestedResult(i, j) => Self::NestedResult(i, j),
_ => unimplemented!("a new enum variant was added and needs to be handled"),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/iota-replay/src/displays/transaction_displays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,11 @@ impl Display for Pretty<'_, Argument> {
let Pretty(argument) = self;

let output = match argument {
Argument::GasCoin => "GasCoin".to_string(),
Argument::Gas => "Gas".to_string(),
Argument::Input(i) => format!("Input {i}"),
Argument::Result(i) => format!("Result {i}"),
Argument::NestedResult(j, k) => format!("Result {j}: {k}"),
_ => unimplemented!("a new enum variant was added and needs to be handled"),
};
write!(f, "{output}")
}
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-rosetta/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ impl InternalOperation {
let validator = builder.input(CallArg::Pure(bcs::to_bytes(&validator)?))?;
(validator, state, amount)
};
let coin = builder.command(Command::SplitCoins(Argument::GasCoin, vec![amount]));
let coin = builder.command(Command::SplitCoins(Argument::Gas, vec![amount]));

let arguments = vec![system_state, coin, validator];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async fn main() -> Result<(), anyhow::Error> {
.unwrap()
})
.collect::<Vec<_>>();
builder.command(Command::MergeCoins(Argument::GasCoin, coin_args));
builder.command(Command::MergeCoins(Argument::Gas, coin_args));
}
builder.finish()
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ async fn main() -> Result<(), anyhow::Error> {
// 2) Split coin
// The amount we want in the new coin, 1000 NANOS
let split_coin_amount = ptb.pure(1000u64)?; // note that we need to specify the u64 type
ptb.command(Command::SplitCoins(
Argument::GasCoin,
vec![split_coin_amount],
));
ptb.command(Command::SplitCoins(Argument::Gas, vec![split_coin_amount]));

// 3) Transfer the new coin to a different address
let argument_address = ptb.pure(recipient)?;
Expand Down
7 changes: 2 additions & 5 deletions crates/iota-sdk/examples/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,12 @@ pub async fn split_coin_digest(
// first, we want to split the coin, and we specify how much IOTA (in NANOS) we
// want for the new coin
let split_coin_amount = ptb.pure(1000u64)?; // note that we need to specify the u64 type here
ptb.command(Command::SplitCoins(
Argument::GasCoin,
vec![split_coin_amount],
));
ptb.command(Command::SplitCoins(Argument::Gas, vec![split_coin_amount]));
// now we want to merge the coins (so that we don't have many coins with very
// small values) observe here that we pass Argument::Result(0), which
// instructs the PTB to get the result from the previous command
ptb.command(Command::MergeCoins(
Argument::GasCoin,
Argument::Gas,
vec![Argument::Result(0)],
));

Expand Down
2 changes: 1 addition & 1 deletion crates/iota-transaction-builder/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl TransactionBuilder {
}
}
PtbInput::PtbRef(iota_arg) => match iota_arg {
IotaArgument::GasCoin => Argument::GasCoin,
IotaArgument::GasCoin => Argument::Gas,
IotaArgument::Input(idx) => Argument::Input(idx),
IotaArgument::Result(idx) => Argument::Result(idx),
IotaArgument::NestedResult(idx, nested_idx) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ where
pub fn parse_command_arg(&mut self) -> Result<Argument> {
use super::token::CommandToken as Tok;
Ok(match self.inner().advance_any()? {
(Tok::Ident, GAS_COIN) => Argument::GasCoin,
(Tok::Ident, GAS_COIN) => Argument::Gas,
(Tok::Ident, INPUT) => {
self.inner().advance(Tok::LParen)?;
let num = self.parse_u16()?;
Expand Down
3 changes: 1 addition & 2 deletions crates/iota-transactional-test-runner/src/test_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2391,8 +2391,7 @@ impl IotaTestAdapter {

// Fund the abstract account with gas
let gas_amount = builder.pure(GAS_FOR_ABSTRACT_ACCOUNT)?;
let new_coin_arg =
builder.command(Command::SplitCoins(Argument::GasCoin, vec![gas_amount]));
let new_coin_arg = builder.command(Command::SplitCoins(Argument::Gas, vec![gas_amount]));
builder.command(Command::TransferObjects(vec![new_coin_arg], aa_addr));

Ok(builder.finish())
Expand Down
99 changes: 25 additions & 74 deletions crates/iota-types/src/iota_sdk_types_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ use iota_sdk_types::{
},
object_id::ObjectId,
transaction::{
ActiveJwk, Argument, AuthenticatorStateExpire, AuthenticatorStateUpdateV1,
CancelledTransaction, ChangeEpoch, ChangeEpochV2, ChangeEpochV3, ChangeEpochV4, Command,
ActiveJwk, AuthenticatorStateExpire, AuthenticatorStateUpdateV1, CancelledTransaction,
ChangeEpoch, ChangeEpochV2, ChangeEpochV3, ChangeEpochV4, Command,
ConsensusCommitPrologueV1, ConsensusDeterminedVersionAssignments,
EndOfEpochTransactionKind, GasPayment, GenesisTransaction, Input, MakeMoveVector,
MergeCoins, MoveCall, ProgrammableTransaction, Publish, RandomnessStateUpdate,
Expand Down Expand Up @@ -1684,25 +1684,17 @@ impl TryFrom<crate::transaction::Command> for Command {
.into_iter()
.map(|type_input| type_input.into_type_tag())
.collect::<Result<_, _>>()?,
arguments: programmable_move_call
.arguments
.into_iter()
.map(Into::into)
.collect(),
arguments: programmable_move_call.arguments,
}),
InternalCmd::TransferObjects(objects, address) => {
Self::TransferObjects(TransferObjects {
objects: objects.into_iter().map(Into::into).collect(),
address: address.into(),
})
Self::TransferObjects(TransferObjects { objects, address })
}
InternalCmd::SplitCoins(coin, amounts) => {
Self::SplitCoins(SplitCoins { coin, amounts })
}
InternalCmd::SplitCoins(coin, amounts) => Self::SplitCoins(SplitCoins {
coin: coin.into(),
amounts: amounts.into_iter().map(Into::into).collect(),
}),
InternalCmd::MergeCoins(argument, coins_to_merge) => Self::MergeCoins(MergeCoins {
coin: argument.into(),
coins_to_merge: coins_to_merge.into_iter().map(Into::into).collect(),
coin: argument,
coins_to_merge,
}),
InternalCmd::Publish(modules, dependencies) => Self::Publish(Publish {
modules,
Expand All @@ -1712,14 +1704,14 @@ impl TryFrom<crate::transaction::Command> for Command {
type_: type_tag
.map(|type_input| type_input.into_type_tag())
.transpose()?,
elements: elements.into_iter().map(Into::into).collect(),
elements,
}),
InternalCmd::Upgrade(modules, dependencies, package, ticket) => {
Self::Upgrade(Upgrade {
modules,
dependencies,
package,
ticket: ticket.into(),
ticket,
})
}
}
Expand All @@ -1737,74 +1729,33 @@ impl TryFrom<Command> for crate::transaction::Command {
move_call.module,
move_call.function,
move_call.type_arguments,
move_call.arguments.into_iter().map(Into::into).collect(),
),
Command::TransferObjects(transfer_objects) => Self::TransferObjects(
transfer_objects
.objects
.into_iter()
.map(Into::into)
.collect(),
transfer_objects.address.into(),
),
Command::SplitCoins(split_coins) => Self::SplitCoins(
split_coins.coin.into(),
split_coins.amounts.into_iter().map(Into::into).collect(),
),
Command::MergeCoins(merge_coins) => Self::MergeCoins(
merge_coins.coin.into(),
merge_coins
.coins_to_merge
.into_iter()
.map(Into::into)
.collect(),
move_call.arguments,
),
Command::TransferObjects(transfer_objects) => {
Self::TransferObjects(transfer_objects.objects, transfer_objects.address)
}
Command::SplitCoins(split_coins) => {
Self::SplitCoins(split_coins.coin, split_coins.amounts)
}
Command::MergeCoins(merge_coins) => {
Self::MergeCoins(merge_coins.coin, merge_coins.coins_to_merge)
}
Command::Publish(publish) => Self::Publish(publish.modules, publish.dependencies),
Command::MakeMoveVector(make_move_vector) => Self::make_move_vec(
make_move_vector.type_,
make_move_vector
.elements
.into_iter()
.map(Into::into)
.collect(),
),
Command::MakeMoveVector(make_move_vector) => {
Self::make_move_vec(make_move_vector.type_, make_move_vector.elements)
}
Command::Upgrade(upgrade) => Self::Upgrade(
upgrade.modules,
upgrade.dependencies,
upgrade.package,
upgrade.ticket.into(),
upgrade.ticket,
),
_ => unimplemented!("a new enum variant was added and needs to be handled"),
}
.pipe(Ok)
}
}

impl From<crate::transaction::Argument> for Argument {
fn from(value: crate::transaction::Argument) -> Self {
match value {
crate::transaction::Argument::GasCoin => Self::Gas,
crate::transaction::Argument::Input(idx) => Self::Input(idx),
crate::transaction::Argument::Result(idx) => Self::Result(idx),
crate::transaction::Argument::NestedResult(idx1, idx2) => {
Self::NestedResult(idx1, idx2)
}
}
}
}

impl From<Argument> for crate::transaction::Argument {
fn from(value: Argument) -> Self {
match value {
Argument::Gas => Self::GasCoin,
Argument::Input(idx) => Self::Input(idx),
Argument::Result(idx) => Self::Result(idx),
Argument::NestedResult(idx1, idx2) => Self::NestedResult(idx1, idx2),
_ => unimplemented!("a new enum variant was added and needs to be handled"),
}
}
}

impl From<crate::messages_checkpoint::EndOfEpochData> for EndOfEpochData {
fn from(value: crate::messages_checkpoint::EndOfEpochData) -> Self {
Self {
Expand Down
8 changes: 4 additions & 4 deletions crates/iota-types/src/programmable_transaction_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,16 @@ impl ProgrammableTransactionBuilder {
let rec_arg = self.pure(recipient).unwrap();
let coin_arg = if let Some(amount) = amount {
let amt_arg = self.pure(amount).unwrap();
self.command(Command::SplitCoins(Argument::GasCoin, vec![amt_arg]))
self.command(Command::SplitCoins(Argument::Gas, vec![amt_arg]))
} else {
Argument::GasCoin
Argument::Gas
};
self.command(Command::TransferObjects(vec![coin_arg], rec_arg));
}

pub fn pay_all_iota(&mut self, recipient: IotaAddress) {
let rec_arg = self.pure(recipient).unwrap();
self.command(Command::TransferObjects(vec![Argument::GasCoin], rec_arg));
self.command(Command::TransferObjects(vec![Argument::Gas], rec_arg));
}

/// Will fail to generate if recipients and amounts do not have the same
Expand All @@ -256,7 +256,7 @@ impl ProgrammableTransactionBuilder {
recipients: Vec<IotaAddress>,
amounts: Vec<u64>,
) -> anyhow::Result<()> {
self.pay_impl(recipients, amounts, Argument::GasCoin)
self.pay_impl(recipients, amounts, Argument::Gas)
}

pub fn split_coin(&mut self, recipient: IotaAddress, coin: ObjectRef, amounts: Vec<u64>) {
Expand Down
29 changes: 1 addition & 28 deletions crates/iota-types/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use anyhow::bail;
use enum_dispatch::enum_dispatch;
use fastcrypto::{encoding::Base64, hash::HashFunction};
use iota_protocol_config::ProtocolConfig;
pub use iota_sdk_types::Argument;
use iota_sdk_types::{
Identifier, ObjectId, TypeTag,
crypto::{Intent, IntentMessage, IntentScope},
Expand Down Expand Up @@ -912,23 +913,6 @@ pub enum Command {
Upgrade(Vec<Vec<u8>>, Vec<ObjectID>, ObjectID, Argument),
}

/// An argument to a programmable transaction command
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Serialize, Deserialize)]
pub enum Argument {
/// The gas coin. The gas coin can only be used by-ref, except for with
/// `TransferObjects`, which can use it by-value.
GasCoin,
/// One of the input objects or primitive values (from
/// `ProgrammableTransaction` inputs)
Input(u16),
/// The result of another command (from `ProgrammableTransaction` commands)
Result(u16),
/// Like a `Result` but it accesses a nested result. Currently, the only
/// usage of this is to access a value from a Move call with multiple
/// return values.
NestedResult(u16, u16),
}

/// The command for calling a Move function, either an entry function or a
/// public function (which cannot return references).
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -1294,17 +1278,6 @@ impl ProgrammableTransaction {
}
}

impl Display for Argument {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Argument::GasCoin => write!(f, "GasCoin"),
Argument::Input(i) => write!(f, "Input({i})"),
Argument::Result(i) => write!(f, "Result({i})"),
Argument::NestedResult(i, j) => write!(f, "NestedResult({i},{j})"),
}
}
}

impl Display for ProgrammableMoveCall {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let ProgrammableMoveCall {
Expand Down
Loading
Loading