|
1 | 1 | use ic_base_types::PrincipalId;
|
2 |
| -use ic_nns_common::pb::v1::NeuronId; |
| 2 | +use ic_nns_common::pb::v1::{NeuronId, ProposalId}; |
3 | 3 | use icp_ledger::protobuf::AccountIdentifier;
|
4 | 4 |
|
5 | 5 | /// The entity that owns the nodes that run the network.
|
@@ -1276,6 +1276,166 @@ pub mod manage_neuron_response {
|
1276 | 1276 | #[prost(message, tag = "14")]
|
1277 | 1277 | RefreshVotingPower(RefreshVotingPowerResponse),
|
1278 | 1278 | }
|
| 1279 | + |
| 1280 | + // Below, we should remove `manage_neuron_response::`, but that should be |
| 1281 | + // done later, so that the original PR that transplanted this code does not |
| 1282 | + // have "extra" refactoring in it. |
| 1283 | + impl ManageNeuronResponse { |
| 1284 | + pub fn is_err(&self) -> bool { |
| 1285 | + matches!( |
| 1286 | + &self.command, |
| 1287 | + Some(manage_neuron_response::Command::Error(_)) |
| 1288 | + ) |
| 1289 | + } |
| 1290 | + |
| 1291 | + pub fn err_ref(&self) -> Option<&GovernanceError> { |
| 1292 | + match &self.command { |
| 1293 | + Some(manage_neuron_response::Command::Error(err)) => Some(err), |
| 1294 | + _ => None, |
| 1295 | + } |
| 1296 | + } |
| 1297 | + |
| 1298 | + pub fn err(self) -> Option<GovernanceError> { |
| 1299 | + match self.command { |
| 1300 | + Some(manage_neuron_response::Command::Error(err)) => Some(err), |
| 1301 | + _ => None, |
| 1302 | + } |
| 1303 | + } |
| 1304 | + |
| 1305 | + pub fn is_ok(&self) -> bool { |
| 1306 | + !self.is_err() |
| 1307 | + } |
| 1308 | + |
| 1309 | + pub fn panic_if_error(self, msg: &str) -> Self { |
| 1310 | + if let Some(manage_neuron_response::Command::Error(err)) = &self.command { |
| 1311 | + panic!("{}: {:?}", msg, err); |
| 1312 | + } |
| 1313 | + self |
| 1314 | + } |
| 1315 | + |
| 1316 | + // This is generic so that callers can pass either GovernanceError from |
| 1317 | + // the ic_nns_governance crate (notice the lack of "_api" at the end of |
| 1318 | + // the name!), in addition to GovernanceError from this crate. |
| 1319 | + pub fn error<E>(err: E) -> Self |
| 1320 | + where |
| 1321 | + GovernanceError: From<E>, |
| 1322 | + { |
| 1323 | + ManageNeuronResponse { |
| 1324 | + command: Some(Command::Error(GovernanceError::from(err))), |
| 1325 | + } |
| 1326 | + } |
| 1327 | + |
| 1328 | + pub fn configure_response() -> Self { |
| 1329 | + ManageNeuronResponse { |
| 1330 | + command: Some(manage_neuron_response::Command::Configure( |
| 1331 | + manage_neuron_response::ConfigureResponse {}, |
| 1332 | + )), |
| 1333 | + } |
| 1334 | + } |
| 1335 | + |
| 1336 | + pub fn disburse_response(transfer_block_height: u64) -> Self { |
| 1337 | + ManageNeuronResponse { |
| 1338 | + command: Some(manage_neuron_response::Command::Disburse( |
| 1339 | + manage_neuron_response::DisburseResponse { |
| 1340 | + transfer_block_height, |
| 1341 | + }, |
| 1342 | + )), |
| 1343 | + } |
| 1344 | + } |
| 1345 | + |
| 1346 | + pub fn spawn_response(created_neuron_id: NeuronId) -> Self { |
| 1347 | + let created_neuron_id = Some(created_neuron_id); |
| 1348 | + ManageNeuronResponse { |
| 1349 | + command: Some(manage_neuron_response::Command::Spawn( |
| 1350 | + manage_neuron_response::SpawnResponse { created_neuron_id }, |
| 1351 | + )), |
| 1352 | + } |
| 1353 | + } |
| 1354 | + |
| 1355 | + pub fn merge_maturity_response(response: MergeMaturityResponse) -> Self { |
| 1356 | + ManageNeuronResponse { |
| 1357 | + command: Some(manage_neuron_response::Command::MergeMaturity(response)), |
| 1358 | + } |
| 1359 | + } |
| 1360 | + |
| 1361 | + pub fn stake_maturity_response(response: StakeMaturityResponse) -> Self { |
| 1362 | + ManageNeuronResponse { |
| 1363 | + command: Some(manage_neuron_response::Command::StakeMaturity(response)), |
| 1364 | + } |
| 1365 | + } |
| 1366 | + |
| 1367 | + pub fn follow_response() -> Self { |
| 1368 | + ManageNeuronResponse { |
| 1369 | + command: Some(manage_neuron_response::Command::Follow( |
| 1370 | + manage_neuron_response::FollowResponse {}, |
| 1371 | + )), |
| 1372 | + } |
| 1373 | + } |
| 1374 | + |
| 1375 | + pub fn make_proposal_response(proposal_id: ProposalId, message: String) -> Self { |
| 1376 | + let proposal_id = Some(proposal_id); |
| 1377 | + let message = Some(message); |
| 1378 | + ManageNeuronResponse { |
| 1379 | + command: Some(manage_neuron_response::Command::MakeProposal( |
| 1380 | + manage_neuron_response::MakeProposalResponse { |
| 1381 | + proposal_id, |
| 1382 | + message, |
| 1383 | + }, |
| 1384 | + )), |
| 1385 | + } |
| 1386 | + } |
| 1387 | + |
| 1388 | + pub fn register_vote_response() -> Self { |
| 1389 | + ManageNeuronResponse { |
| 1390 | + command: Some(manage_neuron_response::Command::RegisterVote( |
| 1391 | + manage_neuron_response::RegisterVoteResponse {}, |
| 1392 | + )), |
| 1393 | + } |
| 1394 | + } |
| 1395 | + |
| 1396 | + pub fn split_response(created_neuron_id: NeuronId) -> Self { |
| 1397 | + let created_neuron_id = Some(created_neuron_id); |
| 1398 | + ManageNeuronResponse { |
| 1399 | + command: Some(manage_neuron_response::Command::Split( |
| 1400 | + manage_neuron_response::SplitResponse { created_neuron_id }, |
| 1401 | + )), |
| 1402 | + } |
| 1403 | + } |
| 1404 | + |
| 1405 | + pub fn merge_response(merge_response: manage_neuron_response::MergeResponse) -> Self { |
| 1406 | + ManageNeuronResponse { |
| 1407 | + command: Some(manage_neuron_response::Command::Merge(merge_response)), |
| 1408 | + } |
| 1409 | + } |
| 1410 | + |
| 1411 | + pub fn disburse_to_neuron_response(created_neuron_id: NeuronId) -> Self { |
| 1412 | + let created_neuron_id = Some(created_neuron_id); |
| 1413 | + ManageNeuronResponse { |
| 1414 | + command: Some(manage_neuron_response::Command::DisburseToNeuron( |
| 1415 | + manage_neuron_response::DisburseToNeuronResponse { created_neuron_id }, |
| 1416 | + )), |
| 1417 | + } |
| 1418 | + } |
| 1419 | + |
| 1420 | + pub fn claim_or_refresh_neuron_response(refreshed_neuron_id: NeuronId) -> Self { |
| 1421 | + let refreshed_neuron_id = Some(refreshed_neuron_id); |
| 1422 | + ManageNeuronResponse { |
| 1423 | + command: Some(manage_neuron_response::Command::ClaimOrRefresh( |
| 1424 | + manage_neuron_response::ClaimOrRefreshResponse { |
| 1425 | + refreshed_neuron_id, |
| 1426 | + }, |
| 1427 | + )), |
| 1428 | + } |
| 1429 | + } |
| 1430 | + |
| 1431 | + pub fn refresh_voting_power_response(_: ()) -> Self { |
| 1432 | + ManageNeuronResponse { |
| 1433 | + command: Some(manage_neuron_response::Command::RefreshVotingPower( |
| 1434 | + manage_neuron_response::RefreshVotingPowerResponse {}, |
| 1435 | + )), |
| 1436 | + } |
| 1437 | + } |
| 1438 | + } |
1279 | 1439 | }
|
1280 | 1440 |
|
1281 | 1441 | #[derive(candid::CandidType, candid::Deserialize, serde::Serialize, comparable::Comparable)]
|
|
0 commit comments