-
Notifications
You must be signed in to change notification settings - Fork 35
feat(context): introduce GroupRequest and ContextGroupId types for group management #2043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
c4a74ea
9fed2b3
073b252
5a3aa4e
787e4cd
35dc878
261b77c
53ac74d
cc28965
a11cc45
ee32493
a8269ef
2781dd3
d704238
f8b5908
5ed088c
cd1c7dc
9c7a209
83004c1
2a926f3
8bbb685
ddb8423
57c9221
b7d24e1
40a34ae
781c1ff
36404bd
2e6e71b
6dc04c5
badaf5c
e6253ba
c671613
c7b5f5a
384367b
71e5f43
a669c61
c52f3b3
92e3261
b70531d
0fa675b
e5643bf
f87bbea
13c1126
6fd4407
446740c
29bff4f
1889796
14b0708
55b505c
0a93f8d
f69394f
cbd2c7d
a4cee5b
af82536
6845238
d7c7d8f
89a5cec
a8ef7c7
375d35d
0d97589
f0b129b
bac3f1f
b429d75
3a03672
aad2273
cb19ab4
f821603
dcb4192
060b2bb
d2d66ba
3768dda
db06adc
159b70e
7aed757
1a33042
294b403
c7babef
839f8c2
d7555ff
b69fb22
7f32fdb
aa720f0
79d086f
37c6975
3fc2165
8f2a126
89fa042
f1396d9
1dcb00d
8fe6e15
0510256
e583faa
317cfbb
9263ff8
0814e2d
f4e7f7b
c5c129e
6ffcbcf
6d90322
db9ae5f
e7c8201
6e64680
b89cd59
3c9d30b
5e0e559
710d012
f99c63d
e509f0f
a3c42ea
df1c30e
d90d289
05033b9
9b40075
14f50e8
59980d4
de21a28
6dc4b02
76829bd
e5fc75b
de457cc
af83204
fc6adc2
525d22d
231bc27
125f298
7d3a2c3
b73d448
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,8 +12,8 @@ pub mod types; | |
|
|
||
| use repr::Repr; | ||
| use types::{ | ||
| Application, BlockHeight, Capability, ContextId, ContextIdentity, ProposalId, | ||
| SignedRevealPayload, SignerId, | ||
| AppKey, Application, BlockHeight, Capability, ContextGroupId, ContextId, ContextIdentity, | ||
| ProposalId, SignedRevealPayload, SignerId, | ||
| }; | ||
|
|
||
| pub type Timestamp = u64; | ||
|
|
@@ -47,6 +47,8 @@ impl<'a> Request<'a> { | |
| pub enum RequestKind<'a> { | ||
| #[serde(borrow)] | ||
| Context(ContextRequest<'a>), | ||
| #[serde(borrow)] | ||
| Group(GroupRequest<'a>), | ||
| } | ||
|
|
||
| #[derive(Debug, Serialize, Deserialize)] | ||
|
|
@@ -103,6 +105,58 @@ pub enum ContextRequestKind<'a> { | |
| UpdateProxyContract, | ||
rtb-12 marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 New GroupRequest and GroupRequestKind lack doc comments The new Suggested fix: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 GroupRequest and GroupRequestKind could benefit from #[non_exhaustive] While Suggested fix: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 GroupRequest and GroupRequestKind lack serialization tests New protocol types Suggested fix: |
||
| } | ||
|
|
||
| #[derive(Debug, Serialize, Deserialize)] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 Nit: GroupRequest lacks documentation The new Suggested fix: |
||
| #[serde(rename_all = "camelCase")] | ||
| #[serde(deny_unknown_fields)] | ||
| #[non_exhaustive] | ||
| pub struct GroupRequest<'a> { | ||
| pub group_id: Repr<ContextGroupId>, | ||
|
|
||
| #[serde(borrow, flatten)] | ||
| pub kind: GroupRequestKind<'a>, | ||
| } | ||
|
|
||
| impl<'a> GroupRequest<'a> { | ||
| #[must_use] | ||
| pub const fn new(group_id: Repr<ContextGroupId>, kind: GroupRequestKind<'a>) -> Self { | ||
| GroupRequest { group_id, kind } | ||
| } | ||
| } | ||
rtb-12 marked this conversation as resolved.
Show resolved
Hide resolved
rtb-12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
rtb-12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #[derive(Debug, Serialize, Deserialize)] | ||
| #[serde(tag = "scope", content = "params")] | ||
| #[serde(deny_unknown_fields)] | ||
| #[expect(clippy::exhaustive_enums, reason = "Considered to be exhaustive")] | ||
| pub enum GroupRequestKind<'a> { | ||
| Create { | ||
rtb-12 marked this conversation as resolved.
Show resolved
Hide resolved
rtb-12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| app_key: Repr<AppKey>, | ||
| #[serde(borrow)] | ||
| target_application: Application<'a>, | ||
| }, | ||
| Delete, | ||
| AddMembers { | ||
| members: Cow<'a, [Repr<SignerId>]>, | ||
| }, | ||
| RemoveMembers { | ||
| members: Cow<'a, [Repr<SignerId>]>, | ||
| }, | ||
| RegisterContext { | ||
| context_id: Repr<ContextId>, | ||
| }, | ||
| UnregisterContext { | ||
| context_id: Repr<ContextId>, | ||
| }, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 ApproveContextRegistration comment implies pre-approval but lacks expiration The Suggested fix: |
||
| SetTargetApplication { | ||
| #[serde(borrow)] | ||
| target_application: Application<'a>, | ||
| }, | ||
rtb-12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// Pre-approve a specific context to register via its proxy contract. | ||
| /// Must be called by a group admin before the proxy path is exercised. | ||
| ApproveContextRegistration { | ||
| context_id: Repr<ContextId>, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 Nit: ProposalAction variants lack documentation New Suggested fix: |
||
| }, | ||
| } | ||
|
|
||
| #[derive(Copy, Clone, Debug, Serialize, Deserialize)] | ||
| #[serde(tag = "scope", content = "params")] | ||
| #[serde(deny_unknown_fields)] | ||
|
|
@@ -156,6 +210,12 @@ pub enum ProposalAction { | |
| DeleteProposal { | ||
rtb-12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| proposal_id: Repr<ProposalId>, | ||
| }, | ||
| RegisterInGroup { | ||
| group_id: Repr<ContextGroupId>, | ||
| }, | ||
| UnregisterFromGroup { | ||
| group_id: Repr<ContextGroupId>, | ||
| }, | ||
| } | ||
|
|
||
| // The proposal the user makes specifying the receiving account and actions they want to execute (1 tx) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -226,6 +226,98 @@ impl From<[u8; 32]> for ContextIdentity { | |
| } | ||
rtb-12 marked this conversation as resolved.
Show resolved
Hide resolved
rtb-12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| #[derive( | ||
rtb-12 marked this conversation as resolved.
Show resolved
Hide resolved
rtb-12 marked this conversation as resolved.
Show resolved
Hide resolved
rtb-12 marked this conversation as resolved.
Show resolved
Hide resolved
rtb-12 marked this conversation as resolved.
Show resolved
Hide resolved
rtb-12 marked this conversation as resolved.
Show resolved
Hide resolved
rtb-12 marked this conversation as resolved.
Show resolved
Hide resolved
rtb-12 marked this conversation as resolved.
Show resolved
Hide resolved
rtb-12 marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 Nit: ContextGroupId and AppKey have nearly identical implementations Both types wrap Identity with the same trait implementations and methods; a macro could reduce the ~90 lines of duplication. Suggested fix: |
||
| Eq, | ||
| Ord, | ||
| Copy, | ||
| Debug, | ||
| Deserialize, | ||
| Clone, | ||
| PartialEq, | ||
| PartialOrd, | ||
| BorshSerialize, | ||
| BorshDeserialize, | ||
| Serialize, | ||
| Hash, | ||
| )] | ||
| pub struct ContextGroupId(Identity); | ||
|
|
||
| impl ContextGroupId { | ||
| pub fn to_bytes(&self) -> [u8; 32] { | ||
| self.0.to_bytes() | ||
| } | ||
| } | ||
|
|
||
| impl ReprBytes for ContextGroupId { | ||
| type EncodeBytes<'a> = [u8; 32]; | ||
| type DecodeBytes = [u8; 32]; | ||
|
|
||
| type Error = LengthMismatch; | ||
|
|
||
| fn as_bytes(&self) -> Self::EncodeBytes<'_> { | ||
| self.0.as_bytes() | ||
| } | ||
|
|
||
| fn from_bytes<F>(f: F) -> repr::Result<Self, Self::Error> | ||
| where | ||
| F: FnOnce(&mut Self::DecodeBytes) -> Bs58Result<usize>, | ||
| { | ||
| ReprBytes::from_bytes(f).map(Self) | ||
| } | ||
| } | ||
|
|
||
| impl From<[u8; 32]> for ContextGroupId { | ||
| fn from(value: [u8; 32]) -> Self { | ||
| Self(Identity(value)) | ||
| } | ||
| } | ||
|
|
||
| #[derive( | ||
| Eq, | ||
| Ord, | ||
| Copy, | ||
| Debug, | ||
| Deserialize, | ||
| Clone, | ||
| PartialEq, | ||
| PartialOrd, | ||
| BorshSerialize, | ||
| BorshDeserialize, | ||
| Serialize, | ||
| Hash, | ||
| )] | ||
| pub struct AppKey(Identity); | ||
|
|
||
| impl AppKey { | ||
| pub fn to_bytes(&self) -> [u8; 32] { | ||
| self.0.to_bytes() | ||
| } | ||
| } | ||
|
|
||
| impl ReprBytes for AppKey { | ||
| type EncodeBytes<'a> = [u8; 32]; | ||
| type DecodeBytes = [u8; 32]; | ||
|
|
||
| type Error = LengthMismatch; | ||
|
|
||
| fn as_bytes(&self) -> Self::EncodeBytes<'_> { | ||
| self.0.as_bytes() | ||
| } | ||
|
|
||
| fn from_bytes<F>(f: F) -> repr::Result<Self, Self::Error> | ||
| where | ||
| F: FnOnce(&mut Self::DecodeBytes) -> Bs58Result<usize>, | ||
| { | ||
| ReprBytes::from_bytes(f).map(Self) | ||
| } | ||
| } | ||
|
|
||
| impl From<[u8; 32]> for AppKey { | ||
| fn from(value: [u8; 32]) -> Self { | ||
| Self(Identity(value)) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Eq, Ord, Copy, Debug, Clone, PartialEq, PartialOrd, BorshSerialize, BorshDeserialize)] | ||
| pub struct BlobId(Identity); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.