11use std:: collections:: HashMap ;
22
33use 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.
4163pub ( 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) ]
72110pub mod tests;
0 commit comments