@@ -106,7 +106,7 @@ pub struct MatchstickInstanceContext<C: Blockchain> {
106
106
pub meta_tests : Vec < ( String , bool , u32 , String ) > ,
107
107
/// Holding the parent entity type, parent virtual field and a tuple of the derived entity type and derived entity field it points to
108
108
/// The example below is taken from a schema.graphql file and will fill the map in the following way:
109
- /// {"GraphAccount": {"nameSignalTransactions", ("NameSignalTransaction", "signer")}}
109
+ /// {"GraphAccount": {"nameSignalTransactions", [ ("NameSignalTransaction", "signer")] }}
110
110
/// ```
111
111
/// type GraphAccount @entity {
112
112
/// id: ID!
@@ -117,11 +117,10 @@ pub struct MatchstickInstanceContext<C: Blockchain> {
117
117
/// signer: GraphAccount!
118
118
/// }
119
119
/// ```
120
- pub ( crate ) derived : HashMap < String , HashMap < String , ( String , String ) > > ,
120
+ pub ( crate ) derived : HashMap < String , HashMap < String , Vec < ( String , String ) > > > ,
121
121
/// Holds the graphql schema for easier access
122
122
schema : HashMap < String , graphql_parser:: schema:: ObjectType < ' static , String > > ,
123
- /// Gives guarantee that all derived relations are in order when true
124
- store_updated : bool ,
123
+ interface_to_entities : HashMap < String , Vec < String > > ,
125
124
/// Holds the mocked return values of `dataSource.address()`, `dataSource.network()` and `dataSource.context()` in that order
126
125
data_source_return_value : (
127
126
Option < String > ,
@@ -146,7 +145,7 @@ impl<C: Blockchain> MatchstickInstanceContext<C> {
146
145
meta_tests : Vec :: new ( ) ,
147
146
derived : HashMap :: new ( ) ,
148
147
schema : HashMap :: new ( ) ,
149
- store_updated : true ,
148
+ interface_to_entities : HashMap :: new ( ) ,
150
149
data_source_return_value : ( None , None , None ) ,
151
150
ipfs : HashMap :: new ( ) ,
152
151
templates : HashMap :: new ( ) ,
@@ -310,7 +309,6 @@ impl<C: Blockchain> MatchstickInstanceContext<C> {
310
309
/// function clearStore(): void
311
310
pub fn clear_store ( & mut self , _gas : & GasCounter ) -> Result < ( ) , HostExportError > {
312
311
self . store . clear ( ) ;
313
- self . store_updated = true ;
314
312
Ok ( ( ) )
315
313
}
316
314
@@ -738,45 +736,47 @@ impl<C: Blockchain> MatchstickInstanceContext<C> {
738
736
) -> Vec < StoreEntity > {
739
737
let mut related_entities: Vec < StoreEntity > = Vec :: new ( ) ;
740
738
741
- // gets the derived entity type and derived entity field associated with the parent entity
742
- let derived_from_entity = self
739
+ // Gets the derived entity type and derived entity field associated with the parent entity
740
+ let derived_from = self
743
741
. derived
744
742
. get ( entity_type)
745
743
. and_then ( |fields| fields. get ( entity_virtual_field) ) ;
746
744
747
- if let Some ( ( derived_from_entity_type, derived_from_entity_field) ) = derived_from_entity {
748
- let derived_entities = self . store . get ( derived_from_entity_type) ;
749
-
750
- if let Some ( derived_entities) = derived_entities {
751
- // loop through all derived entities from the store to find a relation with the parent entity
752
- // if relation is found, it adds the whole entity to the related entities result
753
- for ( derived_entity_id, derived_entity) in derived_entities. iter ( ) {
754
- if !derived_entity. contains_key ( derived_from_entity_field) {
755
- continue ;
756
- }
757
-
758
- // derived field value could be a single ID or list of IDs
759
- let derived_field_value = derived_entity
760
- . get ( derived_from_entity_field)
761
- . unwrap ( )
762
- . clone ( ) ;
763
-
764
- // converts different value types(string, bytes, list) to a single vector
765
- // that way it would be easier to find relation by entity id
766
- let derived_entity_ids: Vec < Value > = match derived_field_value {
767
- Value :: Bytes ( id) => vec ! [ Value :: from( id) ] ,
768
- Value :: String ( id) => vec ! [ Value :: from( id) ] ,
769
- Value :: List ( ids) => ids,
770
- _ => vec ! [ ] ,
771
- } ;
772
-
773
- let relation_found: bool = derived_entity_ids
774
- . iter ( )
775
- . any ( |derived_id| derived_id. to_string ( ) . eq ( entity_id) ) ;
776
-
777
- if relation_found {
778
- related_entities
779
- . push ( derived_entities. get ( derived_entity_id) . unwrap ( ) . clone ( ) ) ;
745
+ if let Some ( entities) = derived_from {
746
+ for ( derived_from_entity_type, derived_from_entity_field) in entities. iter ( ) {
747
+ let derived_entities = self . store . get ( derived_from_entity_type) ;
748
+
749
+ if let Some ( derived_entities) = derived_entities {
750
+ // loop through all derived entities from the store to find a relation with the parent entity
751
+ // if relation is found, it adds the whole entity to the related entities result
752
+ for ( derived_entity_id, derived_entity) in derived_entities. iter ( ) {
753
+ if !derived_entity. contains_key ( derived_from_entity_field) {
754
+ continue ;
755
+ }
756
+
757
+ // derived field value could be a single ID or list of IDs
758
+ let derived_field_value = derived_entity
759
+ . get ( derived_from_entity_field)
760
+ . unwrap ( )
761
+ . clone ( ) ;
762
+
763
+ // converts different value types(string, bytes, list) to a single vector
764
+ // that way it would be easier to find relation by entity id
765
+ let derived_entity_ids: Vec < Value > = match derived_field_value {
766
+ Value :: Bytes ( id) => vec ! [ Value :: from( id) ] ,
767
+ Value :: String ( id) => vec ! [ Value :: from( id) ] ,
768
+ Value :: List ( ids) => ids,
769
+ _ => vec ! [ ] ,
770
+ } ;
771
+
772
+ let relation_found: bool = derived_entity_ids
773
+ . iter ( )
774
+ . any ( |derived_id| derived_id. to_string ( ) . eq ( entity_id) ) ;
775
+
776
+ if relation_found {
777
+ related_entities
778
+ . push ( derived_entities. get ( derived_entity_id) . unwrap ( ) . clone ( ) ) ;
779
+ }
780
780
}
781
781
}
782
782
}
@@ -888,13 +888,7 @@ impl<C: Blockchain> MatchstickInstanceContext<C> {
888
888
id_ptr : AscPtr < AscString > ,
889
889
data_ptr : AscPtr < AscEntity > ,
890
890
) -> Result < ( ) , HostExportError > {
891
- let result = self . update_store ( StoreScope :: Global , entity_type_ptr, id_ptr, data_ptr, _gas) ;
892
-
893
- if result. is_ok ( ) {
894
- self . store_updated = false ;
895
- }
896
-
897
- result
891
+ self . update_store ( StoreScope :: Global , entity_type_ptr, id_ptr, data_ptr, _gas)
898
892
}
899
893
900
894
/// function mockInBlockStore(entityType: string, id: string, data: map): void
@@ -925,7 +919,6 @@ impl<C: Blockchain> MatchstickInstanceContext<C> {
925
919
entity_type_store. remove ( & id) ;
926
920
927
921
self . store . insert ( entity_type, entity_type_store) ;
928
- self . store_updated = false ;
929
922
} else {
930
923
return Err ( anyhow ! (
931
924
"(store.remove) Entity with type '{}' and id '{}' does not exist." ,
0 commit comments