@@ -72,7 +72,7 @@ impl Goal {
72
72
}
73
73
74
74
#[ derive( Debug , Serialize , Deserialize , SerializedBytes , Clone , PartialEq ) ]
75
- pub struct UIEnum ( String ) ;
75
+ pub struct UIEnum ( pub String ) ;
76
76
77
77
#[ derive( Serialize , Deserialize , Debug , SerializedBytes , Clone , PartialEq ) ]
78
78
#[ serde( from = "UIEnum" ) ]
@@ -163,10 +163,45 @@ crud!(
163
163
convert_to_receiver_signal
164
164
) ;
165
165
166
+
167
+
168
+ #[ derive( Serialize , Deserialize , Debug , SerializedBytes , Clone , PartialEq ) ]
169
+ #[ serde( from = "UIEnum" ) ]
170
+ #[ serde( into = "UIEnum" ) ]
171
+ pub enum RelationInput {
172
+ ExistingGoalAsChild ,
173
+ ExistingGoalAsParent
174
+ }
175
+ impl From < UIEnum > for RelationInput {
176
+ fn from ( ui_enum : UIEnum ) -> Self {
177
+ match ui_enum. 0 . as_str ( ) {
178
+ "ExistingGoalAsChild" => Self :: ExistingGoalAsChild ,
179
+ "ExistingGoalAsParent" => Self :: ExistingGoalAsParent ,
180
+ _ => Self :: ExistingGoalAsChild ,
181
+ }
182
+ }
183
+ }
184
+ impl From < RelationInput > for UIEnum {
185
+ fn from ( relation_input : RelationInput ) -> Self {
186
+ Self ( relation_input. to_string ( ) )
187
+ }
188
+ }
189
+ impl fmt:: Display for RelationInput {
190
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
191
+ write ! ( f, "{:?}" , self )
192
+ }
193
+ }
194
+
195
+ #[ derive( Serialize , Deserialize , Debug , SerializedBytes , Clone , PartialEq ) ]
196
+ pub struct LinkedGoalDetails {
197
+ goal_address : WrappedHeaderHash ,
198
+ relation : RelationInput
199
+ }
200
+
166
201
#[ derive( Serialize , Deserialize , Debug , SerializedBytes , Clone , PartialEq ) ]
167
202
pub struct CreateGoalWithEdgeInput {
168
203
entry : Goal ,
169
- maybe_parent_address : Option < WrappedHeaderHash > ,
204
+ maybe_linked_goal : Option < LinkedGoalDetails > ,
170
205
}
171
206
172
207
#[ derive( Serialize , Deserialize , Debug , SerializedBytes , Clone , PartialEq ) ]
@@ -189,11 +224,18 @@ pub fn create_goal_with_edge(
189
224
) -> ExternResult < CreateGoalWithEdgeOutput > {
190
225
// false to say don't send a signal
191
226
let wire_entry: GoalWireEntry = inner_create_goal ( input. entry . clone ( ) , false ) ?;
192
- let maybe_edge: Option < EdgeWireEntry > = match input. maybe_parent_address {
193
- Some ( header_hash) => {
227
+ let new_goal_address = wire_entry. address . clone ( ) ;
228
+ let maybe_edge: Option < EdgeWireEntry > = match input. maybe_linked_goal {
229
+ Some ( linked_goal_details) => {
230
+ let ( parent_address, child_address) = match linked_goal_details. relation {
231
+ // new goal becomes parent
232
+ RelationInput :: ExistingGoalAsChild => ( new_goal_address, linked_goal_details. goal_address ) ,
233
+ // new goal becomes child
234
+ RelationInput :: ExistingGoalAsParent => ( linked_goal_details. goal_address , new_goal_address)
235
+ } ;
194
236
let edge = Edge {
195
- parent_address : header_hash ,
196
- child_address : wire_entry . address . clone ( ) ,
237
+ parent_address,
238
+ child_address,
197
239
randomizer : sys_time ( ) ?. as_secs_f64 ( ) ,
198
240
is_imported : false
199
241
} ;
0 commit comments