sui_rpc_api/grpc/v2/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

pub mod ledger_service;
mod move_package_service;
mod name_service;
mod signature_verification_service;
mod state_service;
mod subscription_service;
mod transaction_execution_service;
pub use ledger_service::protocol_config_to_proto;

fn render_json(
    service: &crate::RpcService,
    struct_tag: &move_core_types::language_storage::StructTag,
    contents: &[u8],
) -> Option<prost_types::Value> {
    let layout = service
        .reader
        .inner()
        .get_struct_layout(struct_tag)
        .ok()
        .flatten()?;

    sui_types::proto_value::ProtoVisitorBuilder::new(service.config.max_json_move_value_size())
        .deserialize_value(contents, &layout)
        .map_err(|e| tracing::debug!("unable to convert move value to JSON: {e}"))
        .ok()
}

fn render_object_to_json(
    service: &crate::RpcService,
    object: &sui_types::object::Object,
) -> Option<prost_types::Value> {
    object.data.try_as_move().and_then(|move_object| {
        render_json(
            service,
            &move_object.type_().clone().into(),
            move_object.contents(),
        )
    })
}