Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rs/nns/governance/api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4567,6 +4567,7 @@ pub enum SelfDescribingValue {
Text(String),
Nat(Nat),
Int(Int),
Null,
Array(Vec<SelfDescribingValue>),
Map(HashMap<String, SelfDescribingValue>),
}
Expand Down
1 change: 1 addition & 0 deletions rs/nns/governance/canister/governance.did
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,7 @@ type SelfDescribingValue = variant {
Int : int;
Array : vec SelfDescribingValue;
Map : vec record { text; SelfDescribingValue };
Null;
};

type GetPendingProposalsRequest = record {
Expand Down
4 changes: 2 additions & 2 deletions rs/nns/governance/derive_self_describing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ fn derive_mixed_enum(name: &Ident, data_enum: &DataEnum) -> Result<TokenStream2,
})
}
Fields::Unit => {
// Unit variant in mixed enum: map with variant name as key, empty array as value
// Unit variant in mixed enum: map with variant name as key, null value as value
Ok(quote! {
#name::#variant_name => {
crate::proposals::self_describing::ValueBuilder::new()
.add_empty_field(#variant_name_str)
.add_field(#variant_name_str, crate::proposals::self_describing::SelfDescribingValue::NULL)
.build()
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2651,6 +2651,7 @@ message SelfDescribingValue {
bytes int = 4;
SelfDescribingValueArray array = 5;
SelfDescribingValueMap map = 6;
Empty null = 7;
}
}

Expand Down
4 changes: 3 additions & 1 deletion rs/nns/governance/src/gen/ic_nns_governance.pb.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4138,7 +4138,7 @@ pub struct FinalizeDisburseMaturity {
::prost::Message,
)]
pub struct SelfDescribingValue {
#[prost(oneof = "self_describing_value::Value", tags = "1, 2, 3, 4, 5, 6")]
#[prost(oneof = "self_describing_value::Value", tags = "1, 2, 3, 4, 5, 6, 7")]
pub value: ::core::option::Option<self_describing_value::Value>,
}
/// Nested message and enum types in `SelfDescribingValue`.
Expand Down Expand Up @@ -4166,6 +4166,8 @@ pub mod self_describing_value {
Array(super::SelfDescribingValueArray),
#[prost(message, tag = "6")]
Map(super::SelfDescribingValueMap),
#[prost(message, tag = "7")]
Null(super::Empty),
}
}
#[derive(
Expand Down
4 changes: 4 additions & 0 deletions rs/nns/governance/src/pb/conversions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4202,6 +4202,7 @@ impl From<pb::SelfDescribingValue> for pb_api::SelfDescribingValue {
.map(|(k, v)| (k, Self::from(v)))
.collect(),
),
pb::self_describing_value::Value::Null(_) => Self::Null,
}
}
}
Expand Down Expand Up @@ -4231,6 +4232,9 @@ impl From<pb_api::SelfDescribingValue> for pb::SelfDescribingValue {
values: v.into_iter().map(|(k, v)| (k, Self::from(v))).collect(),
})
}
pb_api::SelfDescribingValue::Null => {
pb::self_describing_value::Value::Null(pb::Empty {})
}
};
Self { value: Some(value) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,7 @@ fn test_to_self_describing_value() {
SelfDescribingValue::Map(hashmap! {
"ToAdd".to_string() => SelfDescribingValue::Map(hashmap! {
"id".to_string() => SelfDescribingValue::Text("6fyp7-3ibaa-aaaaa-aaaap-4ai".to_string()),
"reward_account".to_string() => SelfDescribingValue::Array(vec![
SelfDescribingValue::Text(account.to_hex())
])
"reward_account".to_string() => SelfDescribingValue::Text(account.to_hex())
})
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl LocallyDescribableProposalAction for DeregisterKnownNeuron {

fn to_self_describing_value(&self) -> SelfDescribingValue {
ValueBuilder::new()
.add_field_with_empty_as_fallback("neuron_id", self.id.map(|id| id.id))
.add_field("neuron_id", self.id.map(|id| id.id))
.build()
}
}
Expand Down
8 changes: 4 additions & 4 deletions rs/nns/governance/src/proposals/install_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ impl LocallyDescribableProposalAction for InstallCode {
let install_mode = install_mode.map(SelfDescribingProstEnum::<CanisterInstallMode>::new);

ValueBuilder::new()
.add_field_with_empty_as_fallback("canister_id", *canister_id)
.add_field_with_empty_as_fallback("install_mode", install_mode)
.add_field_with_empty_as_fallback("wasm_module_hash", wasm_module_hash.clone())
.add_field_with_empty_as_fallback("arg_hash", arg_hash.clone())
.add_field("canister_id", *canister_id)
.add_field("install_mode", install_mode)
.add_field("wasm_module_hash", wasm_module_hash.clone())
.add_field("arg_hash", arg_hash.clone())
.add_field(
"skip_stopping_before_installing",
skip_stopping_before_installing.unwrap_or_default(),
Expand Down
24 changes: 11 additions & 13 deletions rs/nns/governance/src/proposals/manage_neuron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ impl LocallyDescribableProposalAction for ManageNeuron {
"A ManageNeuron proposal is created with an empty or conflicting \
values of id and neuron_id_or_subaccount. This should never happen."
);
builder.add_empty_field("neuron_id_or_subaccount")
builder.add_field("neuron_id_or_subaccount", SelfDescribingValue::NULL)
}
};

builder
.add_field_with_empty_as_fallback("command", self.command.clone())
.build()
builder.add_field("command", self.command.clone()).build()
}
}

Expand Down Expand Up @@ -99,13 +97,13 @@ impl From<Command> for SelfDescribingValue {
println!(
"A ManageNeuron proposal is created with a MergeMaturity command. This should never happen."
);
Self::singleton_map("MergeMaturity", Self::EMPTY)
Self::singleton_map("MergeMaturity", Self::NULL)
}
C::MakeProposal(_) => {
println!(
"A ManageNeuron proposal is created with a MakeProposal command. This should never happen."
);
Self::singleton_map("MakeProposal", Self::EMPTY)
Self::singleton_map("MakeProposal", Self::NULL)
}
}
}
Expand All @@ -117,7 +115,7 @@ impl From<Configure> for SelfDescribingValue {
println!(
"A ManageNeuron proposal is created with an empty operation. This should never happen."
);
return Self::EMPTY;
return Self::NULL;
};

use Operation as O;
Expand Down Expand Up @@ -161,14 +159,14 @@ impl From<IncreaseDissolveDelay> for SelfDescribingValue {
impl From<StartDissolving> for SelfDescribingValue {
fn from(value: StartDissolving) -> Self {
let StartDissolving {} = value;
SelfDescribingValue::EMPTY
SelfDescribingValue::NULL
}
}

impl From<StopDissolving> for SelfDescribingValue {
fn from(value: StopDissolving) -> Self {
let StopDissolving {} = value;
SelfDescribingValue::EMPTY
SelfDescribingValue::NULL
}
}

Expand Down Expand Up @@ -198,14 +196,14 @@ impl From<SetDissolveTimestamp> for SelfDescribingValue {
impl From<JoinCommunityFund> for SelfDescribingValue {
fn from(value: JoinCommunityFund) -> Self {
let JoinCommunityFund {} = value;
SelfDescribingValue::EMPTY
SelfDescribingValue::NULL
}
}

impl From<LeaveCommunityFund> for SelfDescribingValue {
fn from(value: LeaveCommunityFund) -> Self {
let LeaveCommunityFund {} = value;
SelfDescribingValue::EMPTY
SelfDescribingValue::NULL
}
}

Expand Down Expand Up @@ -320,7 +318,7 @@ impl From<ClaimOrRefresh> for SelfDescribingValue {
println!(
"A ManageNeuron proposal is created with an empty by. This should never happen."
);
return Self::EMPTY;
return Self::NULL;
};

match by {
Expand Down Expand Up @@ -359,7 +357,7 @@ impl From<Merge> for SelfDescribingValue {
impl From<RefreshVotingPower> for SelfDescribingValue {
fn from(value: RefreshVotingPower) -> Self {
let RefreshVotingPower {} = value;
SelfDescribingValue::EMPTY
SelfDescribingValue::NULL
}
}

Expand Down
Loading
Loading