Skip to content

Commit 358569a

Browse files
committed
sui-sdk-types: remove ObjectId type in favor of Address
Remove the Objectid type and instead directly use the Address type everywhere. These two types were essentially identical to one another already and this will make a number of apis easier to use now that you don't need to worry about converting between the two.
1 parent e6d79e1 commit 358569a

File tree

18 files changed

+117
-246
lines changed

18 files changed

+117
-246
lines changed

crates/sui-graphql-client/src/faucet.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use reqwest::Url;
1010
use serde::Deserialize;
1111
use serde::Serialize;
1212
use serde_json::json;
13-
use sui_types::ObjectId;
1413
use thiserror::Error;
1514
use tracing::error as tracing_error;
1615
use tracing::info;
@@ -42,7 +41,7 @@ pub struct FaucetResponse {
4241
#[serde(rename_all = "camelCase")]
4342
pub struct CoinInfo {
4443
pub amount: u64,
45-
pub id: ObjectId,
44+
pub id: Address,
4645
pub transfer_tx_digest: TransactionDigest,
4746
}
4847

crates/sui-graphql-client/src/query_types/dry_run.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ pub struct ObjectRef {
4949

5050
impl From<ObjectReference> for ObjectRef {
5151
fn from(value: ObjectReference) -> Self {
52-
let address: Address = (*value.object_id()).into();
5352
ObjectRef {
54-
address,
53+
address: *value.object_id(),
5554
version: value.version(),
5655
digest: value.digest().to_string(),
5756
}

crates/sui-sdk-types/src/address.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
/// assert_eq!(hex, address.to_string());
1515
/// ```
1616
///
17-
/// # Deriving an Address
17+
/// # Deriving an account Address
1818
///
19-
/// Addresses are cryptographically derived from a number of user account authenticators, the simplest
20-
/// of which is an [`Ed25519PublicKey`](crate::Ed25519PublicKey).
19+
/// Account addresses are cryptographically derived from a number of user account authenticators,
20+
/// the simplest of which is an [`Ed25519PublicKey`](crate::Ed25519PublicKey).
2121
///
2222
/// Deriving an address consists of the Blake2b256 hash of the sequence of bytes of its
2323
/// corresponding authenticator, prefixed with a domain-separator. For each authenticator, this
@@ -30,14 +30,16 @@
3030
///
3131
/// [`Ed25519PublicKey::derive_address`]: crate::Ed25519PublicKey::derive_address
3232
///
33-
/// ## Relationship to ObjectIds
33+
/// # Usage as ObjectIds
3434
///
35-
/// [`ObjectId`]s and `Address`es share the same 32-byte addressable space but are derived
36-
/// leveraging different domain-separator values to ensure, cryptographically, that there won't be
37-
/// any overlap, e.g. there can't be a valid `Object` whose `ObjectId` is equal to that of the
35+
/// `Address`es are also used as a way to uniquely identify an [`Object`]. When an `Address` is
36+
/// used as an object identifierit can also be referred to as an `ObjectId`. `ObjectId`s and
37+
/// account `Address`es share the same 32-byte addressable space but are derived leveraging
38+
/// different domain-separator values to ensure, cryptographically, that there won't be any
39+
/// overlap, e.g. there can't be a valid `Object` whose `ObjectId` is equal to that of the
3840
/// `Address` of a user account.
3941
///
40-
/// [`ObjectId`]: crate::ObjectId
42+
/// [`Object`]: crate::Object
4143
///
4244
/// # BCS
4345
///
@@ -52,6 +54,7 @@
5254
derive(serde_derive::Serialize, serde_derive::Deserialize)
5355
)]
5456
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
57+
#[doc(alias = "ObjectId")]
5558
pub struct Address(
5659
#[cfg_attr(
5760
feature = "serde",
@@ -174,12 +177,6 @@ impl From<Address> for Vec<u8> {
174177
}
175178
}
176179

177-
impl From<super::ObjectId> for Address {
178-
fn from(value: super::ObjectId) -> Self {
179-
Self::new(value.into_inner())
180-
}
181-
}
182-
183180
impl std::fmt::Display for Address {
184181
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
185182
write!(f, "0x")?;

crates/sui-sdk-types/src/effects/v1.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::execution_status::ExecutionStatus;
22
use crate::object::Owner;
33
use crate::object::Version;
4+
use crate::Address;
45
use crate::EpochId;
56
use crate::GasCostSummary;
6-
use crate::ObjectId;
77
use crate::ObjectReference;
88
use crate::TransactionDigest;
99
use crate::TransactionEventsDigest;
@@ -105,7 +105,7 @@ pub struct TransactionEffectsV1 {
105105
/// The BCS serialized form for this type is defined by the following ABNF:
106106
///
107107
/// ```text
108-
/// modified-at-version = object-id u64
108+
/// modified-at-version = address u64
109109
/// ```
110110
#[derive(Eq, PartialEq, Clone, Debug)]
111111
#[cfg_attr(
@@ -114,7 +114,7 @@ pub struct TransactionEffectsV1 {
114114
)]
115115
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
116116
pub struct ModifiedAtVersion {
117-
pub object_id: ObjectId,
117+
pub object_id: Address,
118118
pub version: Version,
119119
}
120120

crates/sui-sdk-types/src/effects/v2.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ use crate::digest::EffectsAuxiliaryDataDigest;
22
use crate::execution_status::ExecutionStatus;
33
use crate::object::Owner;
44
use crate::object::Version;
5+
use crate::Address;
56
use crate::EpochId;
67
use crate::GasCostSummary;
78
use crate::ObjectDigest;
8-
use crate::ObjectId;
99
use crate::TransactionDigest;
1010
use crate::TransactionEventsDigest;
1111

@@ -87,7 +87,7 @@ pub struct TransactionEffectsV2 {
8787
/// The BCS serialized form for this type is defined by the following ABNF:
8888
///
8989
/// ```text
90-
/// changed-object = object-id object-in object-out id-operation
90+
/// changed-object = address object-in object-out id-operation
9191
/// ```
9292
#[derive(Eq, PartialEq, Clone, Debug)]
9393
#[cfg_attr(
@@ -97,7 +97,7 @@ pub struct TransactionEffectsV2 {
9797
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
9898
pub struct ChangedObject {
9999
/// Id of the object
100-
pub object_id: ObjectId,
100+
pub object_id: Address,
101101

102102
/// State of the object in the store prior to this transaction.
103103
pub input_state: ObjectIn,
@@ -118,7 +118,7 @@ pub struct ChangedObject {
118118
/// The BCS serialized form for this type is defined by the following ABNF:
119119
///
120120
/// ```text
121-
/// unchanged-shared-object = object-id unchanged-shared-object-kind
121+
/// unchanged-shared-object = address unchanged-shared-object-kind
122122
/// ```
123123
#[derive(Eq, PartialEq, Clone, Debug)]
124124
#[cfg_attr(
@@ -127,7 +127,7 @@ pub struct ChangedObject {
127127
)]
128128
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
129129
pub struct UnchangedSharedObject {
130-
pub object_id: ObjectId,
130+
pub object_id: Address,
131131
pub kind: UnchangedSharedKind,
132132
}
133133

crates/sui-sdk-types/src/events.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use super::Address;
22
use super::Identifier;
3-
use super::ObjectId;
43
use super::StructTag;
54
use super::TypeTag;
65

@@ -31,7 +30,7 @@ pub struct TransactionEvents(
3130
/// The BCS serialized form for this type is defined by the following ABNF:
3231
///
3332
/// ```text
34-
/// event = object-id identifier address struct-tag bytes
33+
/// event = address identifier address struct-tag bytes
3534
/// ```
3635
#[derive(PartialEq, Eq, Debug, Clone)]
3736
#[cfg_attr(
@@ -42,7 +41,7 @@ pub struct TransactionEvents(
4241
pub struct Event {
4342
/// Package id of the top-level function invoked by a MoveCall command which triggered this
4443
/// event to be emitted.
45-
pub package_id: ObjectId,
44+
pub package_id: Address,
4645

4746
/// Module name of the top-level function invoked by a MoveCall command which triggered this
4847
/// event to be emitted.

crates/sui-sdk-types/src/execution_status.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use super::Address;
22
use super::Digest;
33
use super::Identifier;
4-
use super::ObjectId;
54

65
/// The status of an executed Transaction
76
///
@@ -89,7 +88,7 @@ pub enum ExecutionStatus {
8988
/// feature-not-yet-supported = %x03
9089
/// object-too-big = %x04 u64 u64
9190
/// package-too-big = %x05 u64 u64
92-
/// circular-object-ownership = %x06 object-id
91+
/// circular-object-ownership = %x06 address
9392
/// insufficient-coin-balance = %x07
9493
/// coin-balance-overflow = %x08
9594
/// publish-error-non-zero-address = %x09
@@ -116,7 +115,7 @@ pub enum ExecutionStatus {
116115
/// sui-move-verification-timedout = %x1e
117116
/// shared-object-operation-not-allowed = %x1f
118117
/// input-object-deleted = %x20
119-
/// execution-canceled-due-to-shared-object-congestion = %x21 (vector object-id)
118+
/// execution-canceled-due-to-shared-object-congestion = %x21 (vector address)
120119
/// address-denied-for-coin = %x22 address string
121120
/// coin-type-global-pause = %x23 string
122121
/// execution-canceled-due-to-randomness-unavailable = %x24
@@ -150,7 +149,7 @@ pub enum ExecutionError {
150149
max_object_size: u64,
151150
},
152151
/// Circular Object Ownership
153-
CircularObjectOwnership { object: ObjectId },
152+
CircularObjectOwnership { object: Address },
154153

155154
//
156155
// Coin errors
@@ -256,7 +255,7 @@ pub enum ExecutionError {
256255
/// Certificate is canceled due to congestion on shared objects
257256
ExecutionCanceledDueToSharedObjectCongestion {
258257
#[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=1).lift()))]
259-
congested_objects: Vec<ObjectId>,
258+
congested_objects: Vec<Address>,
260259
},
261260

262261
/// Address is denied for this coin type
@@ -295,7 +294,7 @@ pub enum ExecutionError {
295294
/// The BCS serialized form for this type is defined by the following ABNF:
296295
///
297296
/// ```text
298-
/// move-location = object-id identifier u16 u16 (option identifier)
297+
/// move-location = address identifier u16 u16 (option identifier)
299298
/// ```
300299
#[derive(Eq, PartialEq, Clone, Debug)]
301300
#[cfg_attr(
@@ -305,7 +304,7 @@ pub enum ExecutionError {
305304
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
306305
pub struct MoveLocation {
307306
/// The package id
308-
pub package: ObjectId,
307+
pub package: Address,
309308

310309
/// The module name
311310
pub module: Identifier,
@@ -423,12 +422,12 @@ pub enum CommandArgumentError {
423422
/// unknown-upgrade-policy /
424423
/// package-id-does-not-match
425424
///
426-
/// unable-to-fetch-package = %x00 object-id
427-
/// not-a-package = %x01 object-id
425+
/// unable-to-fetch-package = %x00 address
426+
/// not-a-package = %x01 address
428427
/// incompatible-upgrade = %x02
429428
/// digest-does-not-match = %x03 digest
430429
/// unknown-upgrade-policy = %x04 u8
431-
/// package-id-does-not-match = %x05 object-id object-id
430+
/// package-id-does-not-match = %x05 address address
432431
/// ```
433432
#[derive(Eq, PartialEq, Clone, Debug)]
434433
#[cfg_attr(
@@ -438,10 +437,10 @@ pub enum CommandArgumentError {
438437
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
439438
pub enum PackageUpgradeError {
440439
/// Unable to fetch package
441-
UnableToFetchPackage { package_id: ObjectId },
440+
UnableToFetchPackage { package_id: Address },
442441

443442
/// Object is not a package
444-
NotAPackage { object_id: ObjectId },
443+
NotAPackage { object_id: Address },
445444

446445
/// Package upgrade is incompatible with previous version
447446
IncompatibleUpgrade,
@@ -454,8 +453,8 @@ pub enum PackageUpgradeError {
454453

455454
/// PackageId does not matach PackageId in upgrade ticket
456455
PackageIdDoesNotMatch {
457-
package_id: ObjectId,
458-
ticket_id: ObjectId,
456+
package_id: Address,
457+
ticket_id: Address,
459458
},
460459
}
461460

crates/sui-sdk-types/src/framework.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//! Rust definitions of move/sui framework types.
22
3+
use super::Address;
34
use super::Object;
4-
use super::ObjectId;
55
use super::TypeTag;
66
use std::borrow::Cow;
77

88
#[derive(Debug, Clone)]
99
pub struct Coin<'a> {
1010
coin_type: Cow<'a, TypeTag>,
11-
id: ObjectId,
11+
id: Address,
1212
balance: u64,
1313
}
1414

@@ -17,7 +17,7 @@ impl<'a> Coin<'a> {
1717
&self.coin_type
1818
}
1919

20-
pub fn id(&self) -> &ObjectId {
20+
pub fn id(&self) -> &Address {
2121
&self.id
2222
}
2323

@@ -31,13 +31,13 @@ impl<'a> Coin<'a> {
3131
let coin_type = move_struct.type_.is_coin()?;
3232

3333
let contents = &move_struct.contents;
34-
if contents.len() != ObjectId::LENGTH + std::mem::size_of::<u64>() {
34+
if contents.len() != Address::LENGTH + std::mem::size_of::<u64>() {
3535
return None;
3636
}
3737

38-
let id = ObjectId::new((&contents[..ObjectId::LENGTH]).try_into().unwrap());
38+
let id = Address::new((&contents[..Address::LENGTH]).try_into().unwrap());
3939
let balance =
40-
u64::from_le_bytes((&contents[ObjectId::LENGTH..]).try_into().unwrap());
40+
u64::from_le_bytes((&contents[Address::LENGTH..]).try_into().unwrap());
4141

4242
Some(Self {
4343
coin_type: Cow::Borrowed(coin_type),

crates/sui-sdk-types/src/hash.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ enum HashingIntent {
425425
RegularObjectId = 0xf1,
426426
}
427427

428-
impl crate::ObjectId {
428+
impl crate::Address {
429429
/// Create an ObjectId from `TransactionDigest` and `count`.
430430
///
431431
/// `count` is the number of objects that have been created during a transactions.

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ mod execution_status;
105105
pub mod framework;
106106
mod gas;
107107
mod object;
108-
mod object_id;
109108
mod transaction;
110109
mod type_tag;
111110
mod u256;
@@ -208,7 +207,6 @@ pub use object::Owner;
208207
pub use object::TypeOrigin;
209208
pub use object::UpgradeInfo;
210209
pub use object::Version;
211-
pub use object_id::ObjectId;
212210
pub use transaction::ActiveJwk;
213211
pub use transaction::Argument;
214212
pub use transaction::AuthenticatorStateExpire;

0 commit comments

Comments
 (0)