Skip to content

Commit ac2e641

Browse files
Thoralf-MAlex6323
andauthored
feat(iota-sdk-types)!: add Input consts and methods (#1105)
* feat(iota-sdk-types): add Input consts and methods (#595) * feat(iota-sdk-types): add Input consts and methods * write out im/mutable in consts * add INITIAL_SHARED_VERSION const * address review comments * use const * Input::Shared tuple variant * Input::Pure tuple variant * fix serialization * update schemars * old format * update JsonSchema for Input, order * receiving_objects -> receiving_object * Update crates/iota-sdk-types/src/transaction/mod.rs Co-authored-by: /alex/ <alexander.schmidt@iota.org> * remove receiving_object() * derive Copy for SharedObjectReference * rename, cleanup --------- Co-authored-by: /alex/ <alexander.schmidt@iota.org> * imports --------- Co-authored-by: /alex/ <alexander.schmidt@iota.org>
1 parent b1b0beb commit ac2e641

10 files changed

Lines changed: 208 additions & 86 deletions

File tree

crates/iota-sdk-ffi/src/types/transaction/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ impl Input {
328328
/// not contain structs or objects.
329329
#[uniffi::constructor]
330330
pub fn new_pure(value: Vec<u8>) -> Self {
331-
Self(iota_sdk::types::Input::Pure { value })
331+
Self(iota_sdk::types::Input::Pure(value))
332332
}
333333

334334
/// A move object that is either immutable or address owned
@@ -344,11 +344,13 @@ impl Input {
344344
initial_shared_version: &Version,
345345
mutable: bool,
346346
) -> Self {
347-
Self(iota_sdk::types::Input::Shared {
348-
object_id: object_id.0,
349-
initial_shared_version: **initial_shared_version,
350-
mutable,
351-
})
347+
Self(iota_sdk::types::Input::Shared(
348+
iota_sdk::types::SharedObjectReference {
349+
object_id: object_id.0,
350+
initial_shared_version: **initial_shared_version,
351+
mutable,
352+
},
353+
))
352354
}
353355

354356
#[uniffi::constructor]

crates/iota-sdk-transaction-builder/src/builder/mod.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use std::{
1212
use iota_graphql_client::Client;
1313
use iota_types::{
1414
Address, GasPayment, Identifier, MovePackageData, ObjectId, ObjectReference, Owner,
15-
ProgrammableTransaction, StructTag, Transaction, TransactionEffects, TransactionExpiration,
16-
TransactionV1, TypeTag,
15+
ProgrammableTransaction, SharedObjectReference, StructTag, Transaction, TransactionEffects,
16+
TransactionExpiration, TransactionV1, TypeTag,
1717
};
1818
use reqwest::Url;
1919
use serde::Serialize;
@@ -157,10 +157,7 @@ impl TransactionBuildData {
157157

158158
/// Add a pure input using the BCS serialized bytes
159159
pub fn pure_bytes(&mut self, bytes: Vec<u8>) -> Argument {
160-
self.set_input(
161-
InputKind::Input(iota_types::Input::Pure { value: bytes }),
162-
false,
163-
)
160+
self.set_input(InputKind::Input(iota_types::Input::Pure(bytes)), false)
164161
}
165162

166163
/// Add a pure input
@@ -1038,11 +1035,11 @@ impl<C: ClientMethods, L> TransactionBuilder<C, L> {
10381035
obj.digest(),
10391036
))
10401037
}
1041-
Owner::Shared(v) => iota_types::Input::Shared {
1038+
Owner::Shared(v) => iota_types::Input::Shared(SharedObjectReference {
10421039
object_id,
10431040
initial_shared_version: *v,
10441041
mutable: false,
1045-
},
1042+
}),
10461043
_ => unimplemented!(
10471044
"a new enum variant was added and needs to be handled"
10481045
),
@@ -1061,11 +1058,13 @@ impl<C: ClientMethods, L> TransactionBuilder<C, L> {
10611058
.ok_or_else(|| Error::Input(format!("missing object {object_id}")))?;
10621059

10631060
let input = match obj.owner() {
1064-
Owner::Shared(version) => iota_types::Input::Shared {
1065-
object_id,
1066-
initial_shared_version: *version,
1067-
mutable,
1068-
},
1061+
Owner::Shared(version) => {
1062+
iota_types::Input::Shared(SharedObjectReference {
1063+
object_id,
1064+
initial_shared_version: *version,
1065+
mutable,
1066+
})
1067+
}
10691068
_ => {
10701069
return Err(Error::Input(format!(
10711070
"object {object_id} was passed as shared, but is not"

crates/iota-sdk-transaction-builder/src/builder/move_authenticator.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
//! Account Abstraction.
77
88
use iota_types::{
9-
MoveAuthenticator, MoveAuthenticatorV1, ObjectId, ObjectReference, Owner, TypeTag,
9+
Input, MoveAuthenticator, MoveAuthenticatorV1, ObjectId, ObjectReference, Owner,
10+
SharedObjectReference, TypeTag,
1011
};
1112

1213
use crate::{
@@ -66,9 +67,8 @@ impl MoveAuthenticatorBuilder {
6667
for input in self.call_args {
6768
call_args.push(match input {
6869
InputKind::ImmutableOrOwned(object_id)
69-
| InputKind::Input(iota_types::Input::ImmutableOrOwned(ObjectReference {
70-
object_id,
71-
..
70+
| InputKind::Input(Input::ImmutableOrOwned(ObjectReference {
71+
object_id, ..
7272
})) => {
7373
let obj = client
7474
.object(object_id, None)
@@ -82,12 +82,14 @@ impl MoveAuthenticatorBuilder {
8282
"call arguments must not be owned".to_owned(),
8383
));
8484
}
85-
iota_types::Input::ImmutableOrOwned(obj.object_ref())
85+
Input::ImmutableOrOwned(obj.object_ref())
8686
}
8787
InputKind::Shared { object_id, mutable }
88-
| InputKind::Input(iota_types::Input::Shared {
89-
object_id, mutable, ..
90-
}) => {
88+
| InputKind::Input(Input::Shared(SharedObjectReference {
89+
object_id,
90+
mutable,
91+
..
92+
})) => {
9193
let obj = client
9294
.object(object_id, None)
9395
.await
@@ -102,13 +104,13 @@ impl MoveAuthenticatorBuilder {
102104
)));
103105
};
104106

105-
iota_types::Input::Shared {
107+
Input::Shared(SharedObjectReference {
106108
object_id,
107109
initial_shared_version: *version,
108110
mutable,
109-
}
111+
})
110112
}
111-
InputKind::Receiving(_) | InputKind::Input(iota_types::Input::Receiving(_)) => {
113+
InputKind::Receiving(_) | InputKind::Input(Input::Receiving(_)) => {
112114
return Err(Error::InvalidMoveAuthArg(
113115
"call arguments must not be receiving".to_owned(),
114116
));

crates/iota-sdk-transaction-builder/src/builder/ptb_arguments.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ impl PTBArgument for ObjectReference {
6262

6363
impl<T: MoveArg> PTBArgument for T {
6464
fn input(self) -> InputKind {
65-
InputKind::Input(iota_types::Input::Pure {
66-
value: self.pure_bytes().0,
67-
})
65+
InputKind::Input(iota_types::Input::Pure(self.pure_bytes().0))
6866
}
6967
}
7068

@@ -226,11 +224,13 @@ impl PTBArgument for Shared<ObjectReference> {
226224

227225
impl PTBArgument for &Shared<ObjectReference> {
228226
fn input(self) -> InputKind {
229-
InputKind::Input(iota_types::Input::Shared {
230-
object_id: self.0.object_id,
231-
mutable: false,
232-
initial_shared_version: self.0.version,
233-
})
227+
InputKind::Input(iota_types::Input::Shared(
228+
iota_types::SharedObjectReference {
229+
object_id: self.0.object_id,
230+
mutable: false,
231+
initial_shared_version: self.0.version,
232+
},
233+
))
234234
}
235235
}
236236

@@ -278,11 +278,13 @@ impl PTBArgument for SharedMut<ObjectReference> {
278278

279279
impl PTBArgument for &SharedMut<ObjectReference> {
280280
fn input(self) -> InputKind {
281-
InputKind::Input(iota_types::Input::Shared {
282-
object_id: self.0.object_id,
283-
mutable: true,
284-
initial_shared_version: self.0.version,
285-
})
281+
InputKind::Input(iota_types::Input::Shared(
282+
iota_types::SharedObjectReference {
283+
object_id: self.0.object_id,
284+
mutable: true,
285+
initial_shared_version: self.0.version,
286+
},
287+
))
286288
}
287289
}
288290

crates/iota-sdk-transaction-builder/src/unresolved.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use std::collections::HashMap;
77

8-
use iota_types::{Identifier, ObjectId, ObjectReference, TypeTag};
8+
use iota_types::{Identifier, ObjectId, ObjectReference, SharedObjectReference, TypeTag};
99

1010
/// An identifier indicating the unresolved index of an input.
1111
pub type InputId = usize;
@@ -23,9 +23,9 @@ impl Input {
2323
| InputKind::Shared { object_id, .. }
2424
| InputKind::Receiving(object_id) => Some(object_id),
2525
InputKind::Input(input) => match input {
26-
iota_types::Input::Pure { .. } => None,
26+
iota_types::Input::Pure(..) => None,
2727
iota_types::Input::ImmutableOrOwned(ObjectReference { object_id, .. })
28-
| iota_types::Input::Shared { object_id, .. }
28+
| iota_types::Input::Shared(SharedObjectReference { object_id, .. })
2929
| iota_types::Input::Receiving(ObjectReference { object_id, .. }) => {
3030
Some(object_id)
3131
}
@@ -52,7 +52,7 @@ impl InputKind {
5252
| Self::Input(
5353
iota_types::Input::ImmutableOrOwned(ObjectReference { object_id, .. })
5454
| iota_types::Input::Receiving(ObjectReference { object_id, .. })
55-
| iota_types::Input::Shared { object_id, .. },
55+
| iota_types::Input::Shared(SharedObjectReference { object_id, .. }),
5656
) = self
5757
{
5858
Some(*object_id)

crates/iota-sdk-types/src/crypto/move_authenticator.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Copyright (c) 2025 IOTA Stiftung
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use crate::{Address, Input, ObjectId, ObjectReference, TypeTag, Version};
4+
use crate::{
5+
Address, Input, ObjectId, ObjectReference, TypeTag, Version, transaction::SharedObjectReference,
6+
};
57

68
/// MoveAuthenticator is a signature variant that enables a method of
79
/// authentication through Move code. This type represents the data received
@@ -56,11 +58,11 @@ impl MoveAuthenticatorV1 {
5658
Self {
5759
call_args,
5860
type_args,
59-
object_to_authenticate: Input::Shared {
61+
object_to_authenticate: Input::Shared(SharedObjectReference {
6062
object_id: object_to_authenticate,
6163
initial_shared_version,
6264
mutable: false,
63-
},
65+
}),
6466
}
6567
}
6668

@@ -69,7 +71,7 @@ impl MoveAuthenticatorV1 {
6971
pub fn address(&self) -> Address {
7072
match self.object_to_authenticate {
7173
Input::ImmutableOrOwned(ObjectReference { object_id, .. })
72-
| Input::Shared { object_id, .. } => object_id.into(),
74+
| Input::Shared(SharedObjectReference { object_id, .. }) => object_id.into(),
7375
_ => unreachable!(),
7476
}
7577
}

crates/iota-sdk-types/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,9 @@ pub use transaction::{
170170
Command, ConsensusCommitPrologueV1, ConsensusDeterminedVersionAssignments,
171171
EndOfEpochTransactionKind, GasPayment, GenesisTransaction, Input, MakeMoveVector, MergeCoins,
172172
MoveCall, ProgrammableTransaction, Publish, RandomnessStateUpdate, SenderSignedTransaction,
173-
SignedTransaction, SplitCoins, SystemPackage, Transaction, TransactionExpiration,
174-
TransactionKind, TransactionV1, TransferObjects, Upgrade, VersionAssignment,
173+
SharedObjectReference, SignedTransaction, SplitCoins, SystemPackage, Transaction,
174+
TransactionExpiration, TransactionKind, TransactionV1, TransferObjects, Upgrade,
175+
VersionAssignment,
175176
};
176177
pub use validator::{
177178
ValidatorAggregatedSignature, ValidatorCommittee, ValidatorCommitteeMember, ValidatorSignature,

0 commit comments

Comments
 (0)