Skip to content

Commit 9c9d58c

Browse files
Self describing action for ApproveGenesisKyc
1 parent d039613 commit 9c9d58c

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

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

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::collections::HashMap;
22

33
use crate::pb::v1::{
4-
Motion, SelfDescribingProposalAction, Value, ValueMap,
5-
value::Value::{Map, Text},
4+
ApproveGenesisKyc, Motion, SelfDescribingProposalAction, Value, ValueArray, ValueMap,
5+
value::Value::{Array, Map, Text},
66
};
77

88
/// A proposal action that can be described locally, without having to call `canister_metadata`
@@ -37,6 +37,28 @@ impl LocallyDescribableProposalAction for Motion {
3737
}
3838
}
3939

40+
impl LocallyDescribableProposalAction for ApproveGenesisKyc {
41+
const TYPE_NAME: &'static str = "Approve Genesis KYC";
42+
const TYPE_DESCRIPTION: &'static str = "When new neurons are created at Genesis, they have \
43+
GenesisKYC=false. This restricts what actions they can perform. Specifically, they cannot spawn \
44+
new neurons, and once their dissolve delays are zero, they cannot be disbursed and their balances \
45+
unlocked to new accounts. This proposal sets GenesisKYC=true for batches of principals. \
46+
(Special note: The Genesis event disburses all ICP in the form of neurons, whose principals \
47+
must be KYCed. Consequently, all neurons created after Genesis have GenesisKYC=true set \
48+
automatically since they must have been derived from balances that have already been KYCed.)";
49+
50+
fn to_value(&self) -> Value {
51+
ValueBuilder::new()
52+
.add_array_field(
53+
"principals".to_string(),
54+
self.principals
55+
.iter()
56+
.map(|principal| string_to_value(principal.to_string()))
57+
.collect(),
58+
)
59+
.build()
60+
}
61+
}
4062
/// A builder for `Value` objects.
4163
pub(crate) struct ValueBuilder {
4264
fields: HashMap<String, Value>,
@@ -56,6 +78,15 @@ impl ValueBuilder {
5678
value: Some(Text(value.to_string())),
5779
},
5880
);
81+
}
82+
83+
pub fn add_array_field(mut self, key: impl ToString, values: Vec<Value>) -> Self {
84+
self.fields.insert(
85+
key,
86+
Value {
87+
value: Some(Array(ValueArray { values })),
88+
},
89+
);
5990
self
6091
}
6192

@@ -67,6 +98,13 @@ impl ValueBuilder {
6798
}
6899
}
69100

101+
/// Converts a string to a `Value` object.
102+
fn string_to_value(value: String) -> Value {
103+
Value {
104+
value: Some(Text(value)),
105+
}
106+
}
107+
70108
#[path = "self_describing_tests.rs"]
71109
#[cfg(test)]
72110
pub mod tests;

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::*;
22

3+
use ic_base_types::PrincipalId;
34
use ic_nns_governance_api::Value as ApiValue;
45
use maplit::hashmap;
56

@@ -27,3 +28,22 @@ fn test_motion_to_self_describing() {
2728
}),
2829
);
2930
}
31+
32+
#[test]
33+
fn test_approve_genesis_kyc_to_self_describing() {
34+
let approve_genesis_kyc = ApproveGenesisKyc {
35+
principals: vec![
36+
PrincipalId::new_user_test_id(1),
37+
PrincipalId::new_user_test_id(2),
38+
],
39+
};
40+
assert_self_describing_value_is(
41+
approve_genesis_kyc,
42+
ApiValue::Map(hashmap! {
43+
"principals".to_string() => ApiValue::Array(vec![
44+
ApiValue::Text("6fyp7-3ibaa-aaaaa-aaaap-4ai".to_string()),
45+
ApiValue::Text("djduj-3qcaa-aaaaa-aaaap-4ai".to_string()),
46+
]),
47+
}),
48+
);
49+
}

0 commit comments

Comments
 (0)