Skip to content

Commit 4a16534

Browse files
committed
rpc-state-reader: add get_struct_layout method for providing a move layout
1 parent 9762e9e commit 4a16534

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

crates/simulacrum/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,14 @@ impl<T: Send + Sync, V: store::SimulatorStore + Send + Sync> RpcStateReader for
602602
fn indexes(&self) -> Option<&dyn sui_types::storage::RpcIndexes> {
603603
None
604604
}
605+
606+
fn get_struct_layout(
607+
&self,
608+
_: &move_core_types::language_storage::StructTag,
609+
) -> sui_types::storage::error::Result<Option<move_core_types::annotated_value::MoveTypeLayout>>
610+
{
611+
Ok(None)
612+
}
605613
}
606614

607615
impl Simulacrum {

crates/sui-core/src/storage.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,21 @@ impl RpcStateReader for RestReadStore {
476476
fn indexes(&self) -> Option<&dyn RpcIndexes> {
477477
self.index().ok().map(|index| index as _)
478478
}
479+
480+
fn get_struct_layout(
481+
&self,
482+
struct_tag: &move_core_types::language_storage::StructTag,
483+
) -> Result<Option<move_core_types::annotated_value::MoveTypeLayout>> {
484+
self.state
485+
.load_epoch_store_one_call_per_task()
486+
.executor()
487+
// TODO(cache) - must read through cache
488+
.type_layout_resolver(Box::new(self.state.get_backing_package_store().as_ref()))
489+
.get_annotated_layout(struct_tag)
490+
.map(|layout| layout.into_layout())
491+
.map(Some)
492+
.map_err(StorageError::custom)
493+
}
479494
}
480495

481496
impl RpcIndexes for RpcIndexStore {

crates/sui-transactional-test-runner/src/simulator_persisted_store.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,14 @@ impl RpcStateReader for PersistedStoreInnerReadOnlyWrapper {
643643
fn indexes(&self) -> Option<&dyn sui_types::storage::RpcIndexes> {
644644
None
645645
}
646+
647+
fn get_struct_layout(
648+
&self,
649+
_: &move_core_types::language_storage::StructTag,
650+
) -> sui_types::storage::error::Result<Option<move_core_types::annotated_value::MoveTypeLayout>>
651+
{
652+
Ok(None)
653+
}
646654
}
647655

648656
impl PersistedStoreInnerReadOnlyWrapper {

crates/sui-types/src/storage/read_store.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::messages_checkpoint::{
1818
use crate::object::Object;
1919
use crate::storage::{get_transaction_input_objects, get_transaction_output_objects};
2020
use crate::transaction::{TransactionData, VerifiedTransaction};
21+
use move_core_types::annotated_value::MoveTypeLayout;
2122
use move_core_types::language_storage::StructTag;
2223
use move_core_types::language_storage::TypeTag;
2324
use serde::Deserialize;
@@ -552,6 +553,25 @@ pub trait RpcStateReader: ObjectStore + ReadStore + Send + Sync {
552553

553554
// Get a handle to an instance of the RpcIndexes
554555
fn indexes(&self) -> Option<&dyn RpcIndexes>;
556+
557+
fn get_type_layout(&self, type_tag: &TypeTag) -> Result<Option<MoveTypeLayout>> {
558+
match type_tag {
559+
TypeTag::Bool => Ok(Some(MoveTypeLayout::Bool)),
560+
TypeTag::U8 => Ok(Some(MoveTypeLayout::U8)),
561+
TypeTag::U64 => Ok(Some(MoveTypeLayout::U64)),
562+
TypeTag::U128 => Ok(Some(MoveTypeLayout::U128)),
563+
TypeTag::Address => Ok(Some(MoveTypeLayout::Address)),
564+
TypeTag::Signer => Ok(Some(MoveTypeLayout::Signer)),
565+
TypeTag::Vector(type_tag) => Ok(self
566+
.get_type_layout(type_tag)?
567+
.map(|layout| MoveTypeLayout::Vector(Box::new(layout)))),
568+
TypeTag::Struct(struct_tag) => self.get_struct_layout(struct_tag),
569+
TypeTag::U16 => Ok(Some(MoveTypeLayout::U16)),
570+
TypeTag::U32 => Ok(Some(MoveTypeLayout::U32)),
571+
TypeTag::U256 => Ok(Some(MoveTypeLayout::U256)),
572+
}
573+
}
574+
fn get_struct_layout(&self, type_tag: &StructTag) -> Result<Option<MoveTypeLayout>>;
555575
}
556576

557577
pub type DynamicFieldIteratorItem =

0 commit comments

Comments
 (0)