@@ -4044,85 +4044,71 @@ _The initial issue can be edited in order to solve the request of the verifier.
4044
4044
let app_model =
4045
4045
Self :: get_application_model ( client_id. into ( ) , owner. into ( ) , repo. into ( ) ) . await ?;
4046
4046
4047
- if app_model. pr_number == 0 {
4048
- return Err ( LDNError :: Load ( "Active pull request not found" . to_string ( ) ) ) ;
4049
- }
4050
-
4051
- let app_str = & app_model. application . ok_or_else ( || {
4052
- LDNError :: Load ( format ! (
4053
- "Application {} does not have an application field" ,
4054
- client_id
4055
- ) )
4056
- } ) ?;
4057
- let application_file = serde_json:: from_str :: < ApplicationFile > ( app_str) . unwrap ( ) ;
4047
+ let application_file =
4048
+ Self :: get_application_file_with_active_allocation ( & app_model) . await ?;
4058
4049
4059
4050
if application_file. lifecycle . state != AppState :: ReadyToSign {
4060
4051
return Err ( LDNError :: Load ( format ! (
4061
4052
"Application state is {:?}. Expected ReadyToSign" ,
4062
4053
application_file. lifecycle. state
4063
4054
) ) ) ;
4064
4055
}
4065
- let last_allocation = application_file. get_active_allocation ( ) . ok_or_else ( || {
4066
- LDNError :: Load ( format ! (
4067
- "Application {} does not have an active allocation" ,
4068
- client_id
4069
- ) )
4070
- } ) ?;
4071
-
4072
- let is_first = last_allocation. request_type == "First" ;
4056
+ let is_first = application_file. get_active_allocation_request_type ( ) ? == "First" ;
4073
4057
if is_first {
4074
4058
self . remove_first_pending_allocation ( & application_file)
4075
4059
. await ?;
4076
4060
} else {
4077
4061
self . remove_pending_refill ( & app_model. pr_number ) . await ?;
4078
4062
}
4079
- self . issue_updates_after_removing_pending_allocation (
4080
- & application_file. issue_number ,
4081
- is_first,
4082
- )
4083
- . await ?;
4084
- Ok ( ( ) )
4085
- }
4086
4063
4087
- async fn issue_updates_after_removing_pending_allocation (
4088
- & self ,
4089
- issue_number : & str ,
4090
- is_first : bool ,
4091
- ) -> Result < ( ) , LDNError > {
4092
4064
let comment = format ! (
4093
4065
"Last pending allocation reverted for an application `{}`." ,
4094
4066
& self . application_id
4095
4067
) ;
4096
- let issue_number = issue_number. parse :: < u64 > ( ) . map_err ( |e| {
4097
- LDNError :: New ( format ! (
4098
- "Parse issue number: {} to u64 failed. {}" ,
4099
- issue_number, e
4100
- ) )
4101
- } ) ?;
4102
- self . github
4103
- . add_comment_to_issue ( issue_number, & comment)
4104
- . await
4105
- . map_err ( |e| {
4106
- LDNError :: New ( format ! (
4107
- "Error adding comment to issue {} /// {}" ,
4108
- issue_number, e
4109
- ) )
4110
- } ) ?;
4111
4068
4112
4069
let app_state = if is_first {
4113
4070
AppState :: Submitted . as_str ( )
4114
4071
} else {
4115
4072
AppState :: Granted . as_str ( )
4116
4073
} ;
4117
- self . github
4118
- . replace_issue_labels ( issue_number, & [ app_state. into ( ) ] )
4119
- . await
4120
- . map_err ( |e| {
4121
- LDNError :: New ( format ! (
4122
- "Error adding labels to issue {} /// {}" ,
4123
- issue_number, e
4124
- ) )
4125
- } ) ?;
4074
+
4075
+ self . issue_updates ( & application_file. issue_number , & comment, app_state)
4076
+ . await ?;
4077
+ Ok ( ( ) )
4078
+ }
4079
+
4080
+ pub async fn revert_to_ready_to_sign (
4081
+ & self ,
4082
+ client_id : & str ,
4083
+ owner : & str ,
4084
+ repo : & str ,
4085
+ ) -> Result < ( ) , LDNError > {
4086
+ let app_model =
4087
+ Self :: get_application_model ( client_id. into ( ) , owner. into ( ) , repo. into ( ) ) . await ?;
4088
+
4089
+ let application_file =
4090
+ Self :: get_application_file_with_active_allocation ( & app_model) . await ?;
4091
+
4092
+ if application_file. lifecycle . state != AppState :: StartSignDatacap {
4093
+ return Err ( LDNError :: Load ( format ! (
4094
+ "Application state is {:?}. Expected StartSignDatacap" ,
4095
+ application_file. lifecycle. state
4096
+ ) ) ) ;
4097
+ }
4098
+
4099
+ self . remove_signers_from_active_request ( & application_file)
4100
+ . await ?;
4101
+
4102
+ let comment = format ! (
4103
+ "Allocation transaction failed on chain, application {:?} reverted to ReadyToSign state. Please try again." ,
4104
+ & self . application_id
4105
+ ) ;
4106
+ self . issue_updates (
4107
+ & application_file. issue_number ,
4108
+ & comment,
4109
+ AppState :: ReadyToSign . as_str ( ) ,
4110
+ )
4111
+ . await ?;
4126
4112
Ok ( ( ) )
4127
4113
}
4128
4114
@@ -4166,6 +4152,85 @@ _The initial issue can be edited in order to solve the request of the verifier.
4166
4152
} ) ?;
4167
4153
Ok ( ( ) )
4168
4154
}
4155
+
4156
+ async fn remove_signers_from_active_request (
4157
+ & self ,
4158
+ application_file : & ApplicationFile ,
4159
+ ) -> Result < ( ) , LDNError > {
4160
+ let updated_application = application_file. clone ( ) . move_back_to_ready_to_sign ( ) ;
4161
+ self . update_and_commit_application_state (
4162
+ updated_application. clone ( ) ,
4163
+ self . github . owner . clone ( ) ,
4164
+ self . github . repo . clone ( ) ,
4165
+ self . file_sha . clone ( ) ,
4166
+ self . branch_name . clone ( ) ,
4167
+ self . file_name . clone ( ) ,
4168
+ "Revert pending allocation to ReadyToSign" . to_string ( ) ,
4169
+ )
4170
+ . await ?;
4171
+ Ok ( ( ) )
4172
+ }
4173
+
4174
+ async fn issue_updates (
4175
+ & self ,
4176
+ issue_number : & str ,
4177
+ comment : & str ,
4178
+ label : & str ,
4179
+ ) -> Result < ( ) , LDNError > {
4180
+ let issue_number = issue_number. parse :: < u64 > ( ) . map_err ( |e| {
4181
+ LDNError :: New ( format ! (
4182
+ "Parse issue number: {} to u64 failed. {}" ,
4183
+ issue_number, e
4184
+ ) )
4185
+ } ) ?;
4186
+ self . github
4187
+ . add_comment_to_issue ( issue_number, comment)
4188
+ . await
4189
+ . map_err ( |e| {
4190
+ LDNError :: New ( format ! (
4191
+ "Error adding comment to issue {} /// {}" ,
4192
+ issue_number, e
4193
+ ) )
4194
+ } ) ?;
4195
+ self . github
4196
+ . replace_issue_labels ( issue_number, & [ label. into ( ) ] )
4197
+ . await
4198
+ . map_err ( |e| {
4199
+ LDNError :: New ( format ! (
4200
+ "Error adding labels to issue {} /// {}" ,
4201
+ issue_number, e
4202
+ ) )
4203
+ } ) ?;
4204
+ Ok ( ( ) )
4205
+ }
4206
+
4207
+ async fn get_application_file_with_active_allocation (
4208
+ app_model : & ApplicationModel ,
4209
+ ) -> Result < ApplicationFile , LDNError > {
4210
+ if app_model. pr_number == 0 {
4211
+ return Err ( LDNError :: Load ( "Active pull request not found" . to_string ( ) ) ) ;
4212
+ }
4213
+
4214
+ let app_str = app_model. application . as_ref ( ) . ok_or_else ( || {
4215
+ LDNError :: New ( format ! (
4216
+ "Application {} does not have an application field" ,
4217
+ app_model. id
4218
+ ) )
4219
+ } ) ?;
4220
+
4221
+ let application_file = serde_json:: from_str :: < ApplicationFile > ( app_str) . map_err ( |e| {
4222
+ LDNError :: New ( format ! ( "Failed to parse string to ApplicationFile: {}" , e) )
4223
+ } ) ?;
4224
+
4225
+ application_file. get_active_allocation ( ) . ok_or_else ( || {
4226
+ LDNError :: Load ( format ! (
4227
+ "Application {} does not have an active allocation" ,
4228
+ app_model. id
4229
+ ) )
4230
+ } ) ?;
4231
+
4232
+ Ok ( application_file)
4233
+ }
4169
4234
}
4170
4235
4171
4236
#[ derive( Serialize , Deserialize , Debug ) ]
0 commit comments