From 1f46cc0d358b6ee944bd49e13f6658d0d914555c Mon Sep 17 00:00:00 2001 From: Ge Gao <106119108+gegaowp@users.noreply.github.com> Date: Thu, 11 May 2023 18:08:44 -0400 Subject: [PATCH] [cherry-pick] fn: remove object IDs from transactions_to_addr index (#11314) (#11927) --- crates/sui-storage/src/indexes.rs | 2 +- crates/sui-types/src/object.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/sui-storage/src/indexes.rs b/crates/sui-storage/src/indexes.rs index e4ce9ccec89f2..aafe5f8b8c9fb 100644 --- a/crates/sui-storage/src/indexes.rs +++ b/crates/sui-storage/src/indexes.rs @@ -482,7 +482,7 @@ impl IndexStore { &self.tables.transactions_to_addr, mutated_objects.filter_map(|(_, owner)| { owner - .get_owner_address() + .get_address_owner_address() .ok() .map(|addr| ((addr, sequence), digest)) }), diff --git a/crates/sui-types/src/object.rs b/crates/sui-types/src/object.rs index c9a67b46288ba..22f007b9c1cca 100644 --- a/crates/sui-types/src/object.rs +++ b/crates/sui-types/src/object.rs @@ -488,6 +488,19 @@ pub enum Owner { } impl Owner { + // NOTE: only return address of AddressOwner, otherwise return error, + // ObjectOwner's address is converted from object id, thus we will skip it. + pub fn get_address_owner_address(&self) -> SuiResult { + match self { + Self::AddressOwner(address) => Ok(*address), + Self::Shared { .. } | Self::Immutable | Self::ObjectOwner(_) => { + Err(SuiError::UnexpectedOwnerType) + } + } + } + + // NOTE: this function will return address of both AddressOwner and ObjectOwner, + // address of ObjectOwner is converted from object id, even though the type is SuiAddress. pub fn get_owner_address(&self) -> SuiResult { match self { Self::AddressOwner(address) | Self::ObjectOwner(address) => Ok(*address),