Skip to content

Commit 9664efe

Browse files
feat(nns): Support SelfDescribingValue::Bool (#8366)
Use a new variant `Bool` rather than `Nat(1)`/`Nat(0)`. This is more intuitive and more readable than `Nat`.
1 parent a8fa4b4 commit 9664efe

File tree

9 files changed

+22
-7
lines changed

9 files changed

+22
-7
lines changed

rs/nns/governance/api/src/types.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4598,6 +4598,7 @@ pub enum SelfDescribingValue {
45984598
Null,
45994599
Array(Vec<SelfDescribingValue>),
46004600
Map(HashMap<String, SelfDescribingValue>),
4601+
Bool(bool),
46014602
}
46024603

46034604
impl From<String> for SelfDescribingValue {
@@ -4636,6 +4637,12 @@ impl From<PrincipalId> for SelfDescribingValue {
46364637
}
46374638
}
46384639

4640+
impl From<bool> for SelfDescribingValue {
4641+
fn from(value: bool) -> Self {
4642+
SelfDescribingValue::Bool(value)
4643+
}
4644+
}
4645+
46394646
#[derive(candid::CandidType, candid::Deserialize, serde::Serialize, Debug, Clone, PartialEq)]
46404647
pub struct SelfDescribingProposalAction {
46414648
pub type_name: Option<String>,

rs/nns/governance/canister/governance.did

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,7 @@ type SelfDescribingProposalAction = record {
14891489
type SelfDescribingValue = variant {
14901490
Blob : blob;
14911491
Text : text;
1492+
Bool : bool;
14921493
Nat : nat;
14931494
Int : int;
14941495
Array : vec SelfDescribingValue;

rs/nns/governance/proto/ic_nns_governance/pb/v1/governance.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2672,6 +2672,7 @@ message SelfDescribingValue {
26722672
SelfDescribingValueArray array = 5;
26732673
SelfDescribingValueMap map = 6;
26742674
Empty null = 7;
2675+
bool bool = 8;
26752676
}
26762677
}
26772678

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4191,7 +4191,10 @@ pub struct FinalizeDisburseMaturity {
41914191
::prost::Message,
41924192
)]
41934193
pub struct SelfDescribingValue {
4194-
#[prost(oneof = "self_describing_value::Value", tags = "1, 2, 3, 4, 5, 6, 7")]
4194+
#[prost(
4195+
oneof = "self_describing_value::Value",
4196+
tags = "1, 2, 3, 4, 5, 6, 7, 8"
4197+
)]
41954198
pub value: ::core::option::Option<self_describing_value::Value>,
41964199
}
41974200
/// Nested message and enum types in `SelfDescribingValue`.
@@ -4221,6 +4224,8 @@ pub mod self_describing_value {
42214224
Map(super::SelfDescribingValueMap),
42224225
#[prost(message, tag = "7")]
42234226
Null(super::Empty),
4227+
#[prost(bool, tag = "8")]
4228+
Bool(bool),
42244229
}
42254230
}
42264231
#[derive(

rs/nns/governance/src/pb/proposal_conversions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ fn convert_self_describing_value(
407407
api::SelfDescribingValue::Int(int)
408408
}
409409
pb::self_describing_value::Value::Null(_) => api::SelfDescribingValue::Null,
410+
pb::self_describing_value::Value::Bool(v) => api::SelfDescribingValue::Bool(*v),
410411
pb::self_describing_value::Value::Array(v) => api::SelfDescribingValue::Array(
411412
v.values
412413
.iter()

rs/nns/governance/src/proposals/install_code.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ mod tests {
476476
"install_mode".to_string() => SelfDescribingValue::from("Upgrade"),
477477
"wasm_module_hash".to_string() => SelfDescribingValue::from(wasm_hash),
478478
"arg_hash".to_string() => SelfDescribingValue::from(arg_hash),
479-
"skip_stopping_before_installing".to_string() => SelfDescribingValue::from(1_u64),
479+
"skip_stopping_before_installing".to_string() => SelfDescribingValue::from(true),
480480
})
481481
);
482482
}
@@ -503,7 +503,7 @@ mod tests {
503503
"install_mode".to_string() => SelfDescribingValue::from("Install"),
504504
"wasm_module_hash".to_string() => SelfDescribingValue::from(Sha256::hash(&[1, 2, 3]).to_vec()),
505505
"arg_hash".to_string() => SelfDescribingValue::from(Sha256::hash(&[]).to_vec()),
506-
"skip_stopping_before_installing".to_string() => SelfDescribingValue::from(0_u64),
506+
"skip_stopping_before_installing".to_string() => SelfDescribingValue::from(false),
507507
})
508508
);
509509
}

rs/nns/governance/src/proposals/manage_neuron_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ fn test_command_configure_change_auto_stake_maturity_to_self_describing() {
332332
}),
333333
SelfDescribingValue::Map(hashmap! {
334334
"ChangeAutoStakeMaturity".to_string() => SelfDescribingValue::Map(hashmap! {
335-
"requested_setting_for_auto_stake_maturity".to_string() => SelfDescribingValue::from(1_u64),
335+
"requested_setting_for_auto_stake_maturity".to_string() => SelfDescribingValue::from(true),
336336
}),
337337
}),
338338
);
@@ -389,7 +389,7 @@ fn test_command_disburse_to_neuron_to_self_describing() {
389389
"new_controller".to_string() => SelfDescribingValue::from(principal),
390390
"amount_e8s".to_string() => SelfDescribingValue::from(200_000_000_u64),
391391
"dissolve_delay_seconds".to_string() => SelfDescribingValue::from(31_536_000_u64),
392-
"kyc_verified".to_string() => SelfDescribingValue::from(1_u64),
392+
"kyc_verified".to_string() => SelfDescribingValue::from(true),
393393
"nonce".to_string() => SelfDescribingValue::from(7_777_u64),
394394
}),
395395
}),

rs/nns/governance/src/proposals/self_describing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl From<Vec<u8>> for SelfDescribingValue {
141141
impl From<bool> for SelfDescribingValue {
142142
fn from(value: bool) -> Self {
143143
SelfDescribingValue {
144-
value: Some(to_self_describing_nat(if value { 1_u8 } else { 0_u8 })),
144+
value: Some(Value::Bool(value)),
145145
}
146146
}
147147
}

rs/nns/governance/src/proposals/self_describing_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ fn test_create_service_nervous_system_to_self_describing() {
293293
"duration".to_string() => SelfDescribingValue::Map(hashmap! {
294294
"seconds".to_string() => SelfDescribingValue::from(604_800_u64),
295295
}),
296-
"neurons_fund_participation".to_string() => SelfDescribingValue::from(0_u64),
296+
"neurons_fund_participation".to_string() => SelfDescribingValue::from(false),
297297
"minimum_icp".to_string() => SelfDescribingValue::Null,
298298
"maximum_icp".to_string() => SelfDescribingValue::Null,
299299
"neurons_fund_investment_icp".to_string() => SelfDescribingValue::Null,

0 commit comments

Comments
 (0)