Repository: MystenLabs/sui
File: crates/sui-bridge/src/sui_client.rs (Rust)

Code before:
                }
            };

        let field_bcs = response.into_inner().object().contents().to_owned();

        let field: sui_types::dynamic_field::Field<
            MoveTypeBridgeMessageKey,
            LinkedTableNode<MoveTypeBridgeMessageKey, MoveTypeBridgeRecord>,
        > = bcs::from_bytes(field_bcs.value())?;

        Ok(Some(field.value.value))
    }

    async fn get_gas_data_panic_if_not_gas(
        &self,
        gas_object_id: ObjectID,
    ) -> (GasCoin, ObjectRef, Owner) {
        loop {
            let result = async {
                let resp = self
                    .clone()
                    .ledger_client()
                    .get_object(
                        GetObjectRequest::new(&(gas_object_id.into())).with_read_mask(
                            FieldMask::from_paths([
                                Object::path_builder().object_id(),
                                Object::path_builder().version(),
                                Object::path_builder().digest(),
                                Object::path_builder().owner().finish(),
                                Object::path_builder().contents().finish(),
                            ]),
                        ),
                    )
                    .await?
                    .into_inner();

                let obj = resp.object();

                let object_id_parsed: ObjectID = obj
                    .object_id()
                    .parse()
                    .map_err(|e| BridgeError::Generic(format!("Failed to parse object_id: {e}")))?;
                let version = SequenceNumber::from_u64(obj.version());
                let digest: sui_types::digests::ObjectDigest = obj
                    .digest()
                    .parse()
                    .map_err(|e| BridgeError::Generic(format!("Failed to parse digest: {e}")))?;
                let object_ref: ObjectRef = (object_id_parsed, version, digest);

                let proto_owner = obj.owner().to_owned();
                let sdk_owner: sui_sdk_types::Owner = (&proto_owner)

Review comment (suggestion):
Lets request the `bcs` field and then we can deser directly into the monorepo Object type.

Code after:
                Ok(data) => return data,
                Err(e) => {
                    warn!("Can't get gas object: {:?}: {:?}", gas_object_id, e);
                    tokio::time::sleep(Duration::from_secs(5)).await;
                }
            }
        }
    }
}

#[async_trait]
impl SuiClientInner for SuiClientInternal {
    async fn query_events(
        &self,
        query: EventFilter,
        cursor: Option<EventID>,
    ) -> Result<EventPage, BridgeError> {
        self.jsonrpc_client.query_events(query, cursor).await
    }

    async fn get_events_by_tx_digest(
        &self,
        tx_digest: TransactionDigest,
    ) -> Result<SuiEvents, BridgeError> {
        self.grpc_client.get_events_by_tx_digest(tx_digest).await
    }

    async fn get_chain_identifier(&self) -> Result<String, BridgeError> {
        self.grpc_client.get_chain_identifier().await
    }

    async fn get_reference_gas_price(&self) -> Result<u64, BridgeError> {
        self.grpc_client.get_reference_gas_price().await
    }

    async fn get_latest_checkpoint_sequence_number(&self) -> Result<u64, BridgeError> {
        self.grpc_client
            .get_latest_checkpoint_sequence_number()
            .await
    }

    async fn get_mutable_bridge_object_arg(&self) -> Result<ObjectArg, BridgeError> {
        self.grpc_client.get_mutable_bridge_object_arg().await
    }

    async fn get_bridge_summary(&self) -> Result<BridgeSummary, BridgeError> {
        self.grpc_client.get_bridge_summary().await
    }

    async fn get_token_transfer_action_onchain_status(
        &self,