diff --git a/rpc/api/src/state/mod.rs b/rpc/api/src/state/mod.rs index 2372b645a1..e59f21e9b6 100644 --- a/rpc/api/src/state/mod.rs +++ b/rpc/api/src/state/mod.rs @@ -65,7 +65,7 @@ pub trait StateApi { /// Return the TableInfo according to queried AccountAddress #[rpc(name = "state.get_table_info")] - fn get_table_info(&self, address: AccountAddress) -> FutureResult; + fn get_table_info(&self, address: AccountAddress) -> FutureResult>; /// Return the TableItem value and provide a State Proof at `state_root` #[rpc(name = "state.get_with_table_item_proof")] diff --git a/rpc/api/src/types.rs b/rpc/api/src/types.rs index 0d955a6eab..532a140998 100644 --- a/rpc/api/src/types.rs +++ b/rpc/api/src/types.rs @@ -1903,15 +1903,14 @@ impl From for BlockInfoView { #[serde(rename = "table_item")] pub struct TableItemView { handle: TableHandle, - #[schemars(with = "String")] - key: Vec, + key: StrView>, } impl From for TableItemView { fn from(table_item: TableItem) -> Self { Self { handle: table_item.handle, - key: table_item.key, + key: table_item.key.into(), } } } @@ -1930,35 +1929,34 @@ impl From for StateKeyView { StateKey::AccessPath(access_path) => Self::AccessPath(access_path), StateKey::TableItem(table_item) => Self::TableItem(TableItemView { handle: table_item.handle, - key: table_item.key, + key: table_item.key.into(), }), } } } #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize, JsonSchema)] +#[serde(rename = "table_info")] pub struct TableInfoView { - #[schemars(with = "String")] - #[serde(rename = "table_info")] - inner: Option, + key_type: TypeTagView, + value_type: TypeTagView, } -impl TableInfoView { - pub fn new(inner: Option) -> Self { - Self { inner } +impl From for TableInfoView { + fn from(value: TableInfo) -> Self { + Self { + key_type: value.key_type.into(), + value_type: value.value_type.into(), + } } } -impl From for Option { +impl From for TableInfo { fn from(value: TableInfoView) -> Self { - value.inner - } -} - -impl TryInto for TableInfoView { - type Error = String; - fn try_into(self) -> Result { - self.inner.ok_or_else(|| "Null".to_string()) + Self { + key_type: value.key_type.0, + value_type: value.value_type.0, + } } } diff --git a/rpc/client/src/lib.rs b/rpc/client/src/lib.rs index 7b704bcc64..6f3d748c59 100644 --- a/rpc/client/src/lib.rs +++ b/rpc/client/src/lib.rs @@ -656,7 +656,10 @@ impl RpcClient { .map_err(map_err) } - pub fn state_get_table_info(&self, address: AccountAddress) -> anyhow::Result { + pub fn state_get_table_info( + &self, + address: AccountAddress, + ) -> anyhow::Result> { self.call_rpc_blocking(|inner| inner.state_client.get_table_info(address)) .map_err(map_err) } diff --git a/rpc/client/src/remote_state_reader.rs b/rpc/client/src/remote_state_reader.rs index fb61583e60..796d71cd9e 100644 --- a/rpc/client/src/remote_state_reader.rs +++ b/rpc/client/src/remote_state_reader.rs @@ -110,7 +110,9 @@ impl<'a> ChainStateReader for RemoteStateReader<'a> { .map(Into::into) } fn get_table_info(&self, address: AccountAddress) -> Result> { - self.client.state_get_table_info(address).map(Into::into) + self.client + .state_get_table_info(address) + .map(|v| v.map(Into::into)) } } diff --git a/rpc/server/src/module/state_rpc.rs b/rpc/server/src/module/state_rpc.rs index 782177a54f..2426982c7c 100644 --- a/rpc/server/src/module/state_rpc.rs +++ b/rpc/server/src/module/state_rpc.rs @@ -186,12 +186,12 @@ where Box::pin(fut) } - fn get_table_info(&self, address: AccountAddress) -> FutureResult { + fn get_table_info(&self, address: AccountAddress) -> FutureResult> { let fut = self .service .clone() .get_table_info(address) - .map_ok(TableInfoView::new) + .map_ok(|v| v.map(Into::into)) .map_err(map_err); Box::pin(fut) }