diff --git a/crates/sui-indexer/src/apis/indexer_api.rs b/crates/sui-indexer/src/apis/indexer_api.rs index e01f13decb4c3..f0acc957c144e 100644 --- a/crates/sui-indexer/src/apis/indexer_api.rs +++ b/crates/sui-indexer/src/apis/indexer_api.rs @@ -449,7 +449,7 @@ where Ok(()) } - async fn resolve_name_service_address(&self, _name: String) -> RpcResult { + async fn resolve_name_service_address(&self, _name: String) -> RpcResult> { // TODO(gegaowp): implement name service resolver in indexer todo!() } diff --git a/crates/sui-json-rpc/src/api/indexer.rs b/crates/sui-json-rpc/src/api/indexer.rs index 62ad39e5a8619..ba218173183db 100644 --- a/crates/sui-json-rpc/src/api/indexer.rs +++ b/crates/sui-json-rpc/src/api/indexer.rs @@ -99,7 +99,7 @@ pub trait IndexerApi { &self, /// The name to resolve name: String, - ) -> RpcResult; + ) -> RpcResult>; /// Return the resolved names given address, /// if multiple names are resolved, the first one is the primary name. diff --git a/crates/sui-json-rpc/src/indexer_api.rs b/crates/sui-json-rpc/src/indexer_api.rs index 8cf768d547dfc..4a02691d3986c 100644 --- a/crates/sui-json-rpc/src/indexer_api.rs +++ b/crates/sui-json-rpc/src/indexer_api.rs @@ -275,7 +275,7 @@ impl IndexerApiServer for IndexerApi { .get_object(id, Some(SuiObjectDataOptions::full_content())) } - async fn resolve_name_service_address(&self, name: String) -> RpcResult { + async fn resolve_name_service_address(&self, name: String) -> RpcResult> { let dynmaic_field_table_object_id = self.get_name_service_dynamic_field_table_object_id(/* reverse_lookup */ false)?; // NOTE: 0x1::string::String is the type tag of fields in dynamic_field_table @@ -287,7 +287,7 @@ impl IndexerApiServer for IndexerApi { })); let name_bcs_value = bcs::to_bytes(&name).context("Unable to serialize name")?; // record of the input `name` - let record_object_id = self + let record_object_id_option = self .state .get_dynamic_field_object_id( dynmaic_field_table_object_id, @@ -299,42 +299,46 @@ impl IndexerApiServer for IndexerApi { "Read name service dynamic field table failed with error: {:?}", e ) - })? - .ok_or_else(|| anyhow!("Record not found for name: {:?}", name,))?; - let record_object_read = self.state.get_object_read(&record_object_id).map_err(|e| { - warn!( - "Failed to get object read of name: {:?} with error: {:?}", - record_object_id, e - ); - anyhow!("{e}") - })?; - let record_parsed_move_object = - SuiParsedMoveObject::try_from_object_read(record_object_read)?; - // NOTE: "value" is the field name to get the address info - let address_info_move_value = record_parsed_move_object - .read_dynamic_field_value(NAME_SERVICE_VALUE) - .ok_or_else(|| anyhow!("Cannot find value field in record Move struct"))?; - let address_info_move_struct = match address_info_move_value { - SuiMoveValue::Struct(a) => Ok(a), - _ => Err(anyhow!("value field is not found.")), - }?; - // NOTE: "marker" is the field name to get the address - let address_str_move_value = address_info_move_struct - .read_dynamic_field_value(NAME_SERVICE_MARKER) - .ok_or_else(|| { - anyhow!( - "Cannot find marker field in address info Move struct: {:?}", - address_info_move_struct - ) })?; - let addr = match address_str_move_value { - SuiMoveValue::Address(addr) => Ok(addr), - _ => Err(anyhow!( - "No SuiAddress found in: {:?}", - address_str_move_value - )), - }?; - Ok(addr) + if let Some(record_object_id) = record_object_id_option { + let record_object_read = + self.state.get_object_read(&record_object_id).map_err(|e| { + warn!( + "Failed to get object read of name: {:?} with error: {:?}", + record_object_id, e + ); + anyhow!("{e}") + })?; + let record_parsed_move_object = + SuiParsedMoveObject::try_from_object_read(record_object_read)?; + // NOTE: "value" is the field name to get the address info + let address_info_move_value = record_parsed_move_object + .read_dynamic_field_value(NAME_SERVICE_VALUE) + .ok_or_else(|| anyhow!("Cannot find value field in record Move struct"))?; + let address_info_move_struct = match address_info_move_value { + SuiMoveValue::Struct(a) => Ok(a), + _ => Err(anyhow!("value field is not found.")), + }?; + // NOTE: "marker" is the field name to get the address + let address_str_move_value = address_info_move_struct + .read_dynamic_field_value(NAME_SERVICE_MARKER) + .ok_or_else(|| { + anyhow!( + "Cannot find marker field in address info Move struct: {:?}", + address_info_move_struct + ) + })?; + let addr = match address_str_move_value { + SuiMoveValue::Address(addr) => Ok(addr), + _ => Err(anyhow!( + "No SuiAddress found in: {:?}", + address_str_move_value + )), + }?; + return Ok(Some(addr)); + } else { + return Ok(None); + } } async fn resolve_name_service_names( diff --git a/crates/sui-open-rpc/spec/openrpc.json b/crates/sui-open-rpc/spec/openrpc.json index 5f9e22ff321a2..d9e8cda85b671 100644 --- a/crates/sui-open-rpc/spec/openrpc.json +++ b/crates/sui-open-rpc/spec/openrpc.json @@ -1789,7 +1789,6 @@ ], "result": { "name": "SuiAddress", - "required": true, "schema": { "$ref": "#/components/schemas/SuiAddress" }