@@ -16,22 +16,25 @@ use bytes::Bytes;
16
16
use move_binary_format:: file_format:: CompiledModule ;
17
17
use move_core_types:: gas_schedule:: { GasCarrier , InternalGasUnits } ;
18
18
use move_table_extension:: { TableHandle , TableOperation , TableResolver } ;
19
- use sov_modules_api:: { StateMap , StateMapAccessor , WorkingSet } ;
19
+ use sov_modules_api:: { StateMap , StateMapAccessor , StateReaderAndWriter , WorkingSet } ;
20
+ use sov_prover_storage_manager:: new_orphan_storage;
21
+ use sov_state:: DefaultStorageSpec ;
20
22
use std:: cell:: RefCell ;
21
23
use std:: fmt:: Debug ;
24
+ use std:: ops:: DerefMut ;
22
25
23
26
type Result < T , E = StateviewError > = std:: result:: Result < T , E > ;
24
27
/// The Aptos Database structure for storing and working with accounts and their modules.
25
28
pub ( crate ) struct SovAptosDb < ' a , S : sov_modules_api:: Spec > {
26
29
pub ( crate ) state_data : StateMap < StateKeyWrapper , StateValueWrapper > ,
27
30
/// Working set
28
- pub ( crate ) working_set : & ' a mut WorkingSet < S > ,
31
+ pub ( crate ) working_set : RefCell < & ' a mut WorkingSet < S > > ,
29
32
}
30
33
31
34
impl < ' a , S : sov_modules_api:: Spec > SovAptosDb < ' a , S > {
32
35
pub ( crate ) fn new (
33
36
state_data : StateMap < StateKeyWrapper , StateValueWrapper > ,
34
- working_set : & ' a mut WorkingSet < S > ,
37
+ working_set : RefCell < & ' a mut WorkingSet < S > > ,
35
38
) -> Self {
36
39
Self { working_set, state_data }
37
40
}
44
47
{
45
48
type Key = StateKey ;
46
49
47
- fn get_state_value ( & mut self , state_key : & Self :: Key ) -> Result < Option < AptosStateValue > > {
50
+ fn get_state_value ( & self , state_key : & Self :: Key ) -> Result < Option < AptosStateValue > > {
48
51
let state_key_wrapper = StateKeyWrapper :: new ( state_key. clone ( ) ) ;
49
- let state_value_wrapper = self . state_data . get ( & state_key_wrapper, self . working_set ) ;
52
+ let mut working_set = self . working_set . borrow_mut ( ) ;
53
+ let mut working_set = working_set. deref_mut ( ) . deref_mut ( ) ;
54
+ let state_value_wrapper = self . state_data . get ( & state_key_wrapper, working_set. deref_mut ( ) ) ;
50
55
match state_value_wrapper {
51
56
Some ( state_value_wrapper) => {
52
57
let state_value = state_value_wrapper. into ( ) ;
@@ -74,9 +79,11 @@ impl<'a, S: sov_modules_api::Spec> ResourceResolver for SovAptosDb<'a, S> {
74
79
) -> Result < ( Option < Bytes > , usize ) , Error > {
75
80
let ap = AccessPath :: resource_access_path ( * address, struct_tag. clone ( ) )
76
81
. expect ( "Invalid access path." ) ;
82
+ let mut working_set = self . working_set . borrow_mut ( ) ;
83
+ let working_set = working_set. deref_mut ( ) . deref_mut ( ) ;
77
84
match self
78
85
. state_data
79
- . get ( & StateKeyWrapper :: new ( StateKey :: access_path ( ap) ) , self . working_set )
86
+ . get ( & StateKeyWrapper :: new ( StateKey :: access_path ( ap) ) , working_set)
80
87
{
81
88
Some ( val) => Ok ( ( Some ( val. 0 . bytes ( ) . clone ( ) ) , 0 ) ) ,
82
89
None => Ok ( ( None , 0 ) ) ,
@@ -101,9 +108,11 @@ impl<'a, S: sov_modules_api::Spec> ModuleResolver for SovAptosDb<'a, S> {
101
108
102
109
fn get_module ( & self , id : & ModuleId ) -> std:: result:: Result < Option < Bytes > , Self :: Error > {
103
110
let ap = AccessPath :: from ( id) ;
111
+ let mut working_set = self . working_set . borrow_mut ( ) ;
112
+ let working_set = working_set. deref_mut ( ) . deref_mut ( ) ;
104
113
match self
105
114
. state_data
106
- . get ( & StateKeyWrapper :: new ( StateKey :: access_path ( ap) ) , self . working_set )
115
+ . get ( & StateKeyWrapper :: new ( StateKey :: access_path ( ap) ) , working_set)
107
116
{
108
117
Some ( val) => Ok ( Some ( val. 0 . bytes ( ) . clone ( ) ) ) ,
109
118
None => Ok ( None ) ,
@@ -122,7 +131,9 @@ impl<'a, S: sov_modules_api::Spec> TableResolver for SovAptosDb<'a, S> {
122
131
let account_address = AccountAddress :: new ( address) ;
123
132
let ap = AccessPath :: new ( AccountAddress :: from ( account_address) , key. to_vec ( ) ) ;
124
133
let state_key_wrapper = StateKeyWrapper :: new ( StateKey :: access_path ( ap) ) ;
125
- let state_value_wrapper = self . state_data . get ( & state_key_wrapper, self . working_set ) ;
134
+ let mut working_set = self . working_set . borrow_mut ( ) ;
135
+ let working_set = working_set. deref_mut ( ) . deref_mut ( ) ;
136
+ let state_value_wrapper = self . state_data . get ( & state_key_wrapper, working_set) ;
126
137
match state_value_wrapper {
127
138
Some ( state_value_wrapper) => {
128
139
let state_value: StateValue = state_value_wrapper. into ( ) ;
0 commit comments