Skip to content

Commit 66a5042

Browse files
Deleted ManageNeuronResponse from governance.proto.
1 parent 9e3652c commit 66a5042

File tree

13 files changed

+248
-583
lines changed

13 files changed

+248
-583
lines changed

rs/nns/governance/api/src/ic_nns_governance.pb.v1.rs

Lines changed: 161 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use ic_base_types::PrincipalId;
2-
use ic_nns_common::pb::v1::NeuronId;
2+
use ic_nns_common::pb::v1::{NeuronId, ProposalId};
33
use icp_ledger::protobuf::AccountIdentifier;
44

55
/// The entity that owns the nodes that run the network.
@@ -1276,6 +1276,166 @@ pub mod manage_neuron_response {
12761276
#[prost(message, tag = "14")]
12771277
RefreshVotingPower(RefreshVotingPowerResponse),
12781278
}
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+
}
12791439
}
12801440

12811441
#[derive(candid::CandidType, candid::Deserialize, serde::Serialize, comparable::Comparable)]

rs/nns/governance/api/src/pb.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@ pub mod v1;
1616
/// The number of e8s per ICP;
1717
const E8S_PER_ICP: u64 = TOKEN_SUBDIVIDABLE_BY;
1818

19-
impl ManageNeuronResponse {
20-
pub fn panic_if_error(self, msg: &str) -> Self {
21-
if let Some(manage_neuron_response::Command::Error(err)) = &self.command {
22-
panic!("{}: {:?}", msg, err);
23-
}
24-
self
25-
}
26-
}
27-
2819
impl GovernanceError {
2920
pub fn new(error_type: ErrorType) -> Self {
3021
Self {

rs/nns/governance/canbench/canbench_results.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ benches:
5555
scopes: {}
5656
compute_ballots_for_new_proposal_with_stable_neurons:
5757
total:
58-
instructions: 2169168
58+
instructions: 2220000
5959
heap_increase: 0
6060
stable_memory_increase: 0
6161
scopes: {}

0 commit comments

Comments
 (0)