@@ -9,7 +9,8 @@ use crate::{
99 } ,
1010 pallet_permission0:: permission:: {
1111 PermissionDuration , PermissionScope , RevocationTerms ,
12- emission:: { DistributionControl , EmissionAllocation } ,
12+ stream:: { DistributionControl , StreamAllocation } ,
13+ wallet:: WalletScopeType ,
1314 } ,
1415 } ,
1516} ;
@@ -57,7 +58,8 @@ pub struct PermissionSummaryResponse {
5758pub enum Permission {
5859 Namespace ( ( NamespacePermission , Direction ) ) ,
5960 Curator ( ( CuratorPermission , Direction ) ) ,
60- Emission ( ( EmissionPermission , Direction ) ) ,
61+ Stream ( ( StreamPermission , Direction ) ) ,
62+ Wallet ( ( WalletPermission , Direction ) ) ,
6163}
6264
6365#[ derive( Clone , schemars:: JsonSchema , serde:: Deserialize , serde:: Serialize ) ]
@@ -76,10 +78,10 @@ pub struct NamespacePermission {
7678pub struct CuratorPermission { }
7779
7880#[ derive( schemars:: JsonSchema , serde:: Deserialize , serde:: Serialize ) ]
79- pub struct EmissionPermission {
81+ pub struct StreamPermission {
8082 allocation : Allocation ,
8183 distribution : Distribution ,
82- targets : HashMap < String , u16 > ,
84+ recipients : HashMap < String , u16 > ,
8385 accumulating : bool ,
8486}
8587
@@ -89,6 +91,19 @@ pub enum Allocation {
8991 FixedAmount ( u128 ) ,
9092}
9193
94+ #[ derive( schemars:: JsonSchema , serde:: Deserialize , serde:: Serialize ) ]
95+ pub struct WalletPermission {
96+ r#type : WalletPermissionType ,
97+ }
98+
99+ #[ derive( schemars:: JsonSchema , serde:: Deserialize , serde:: Serialize ) ]
100+ pub enum WalletPermissionType {
101+ Stake {
102+ can_transfer_stake : bool ,
103+ exclusive_stake_access : bool ,
104+ } ,
105+ }
106+
92107pub async fn create_namespace_for_agent (
93108 torus_client : & Client ,
94109 request : NamespaceCreationRequest ,
@@ -206,57 +221,54 @@ pub async fn get_permission_summary_for_agent(
206221 } ;
207222
208223 match contract. scope {
209- PermissionScope :: Emission ( emission ) => {
224+ PermissionScope :: Stream ( stream ) => {
210225 let direction = if contract. delegator == account_id {
211- let mut recipients = vec ! [ name_or_key( & contract. recipient) ] ;
212- recipients. append (
213- & mut emission
214- . targets
215- . 0
216- . iter ( )
217- . map ( |( target, _) | name_or_key ( target) )
218- . collect :: < Vec < String > > ( ) ,
219- ) ;
226+ let recipients: Vec < _ > = stream
227+ . recipients
228+ . 0
229+ . iter ( )
230+ . map ( |( target, _) | name_or_key ( target) )
231+ . collect ( ) ;
220232 Direction :: DelegatingTo ( recipients)
221233 } else {
222234 Direction :: DelegatedFrom ( name_or_key ( & contract. delegator ) )
223235 } ;
224236
225- let allocation = match emission . allocation {
226- EmissionAllocation :: Streams ( bounded_btree_map) => Allocation :: Streams (
237+ let allocation = match stream . allocation {
238+ StreamAllocation :: Streams ( bounded_btree_map) => Allocation :: Streams (
227239 bounded_btree_map
228240 . 0
229241 . iter ( )
230242 . map ( |( stream, percent) | ( stream. to_string ( ) , percent. 0 ) )
231243 . collect :: < HashMap < _ , _ > > ( ) ,
232244 ) ,
233- EmissionAllocation :: FixedAmount ( amount) => Allocation :: FixedAmount ( amount) ,
245+ StreamAllocation :: FixedAmount ( amount) => Allocation :: FixedAmount ( amount) ,
234246 } ;
235247
236- let distribution = match emission . distribution {
248+ let distribution = match stream . distribution {
237249 DistributionControl :: Manual => Distribution :: Manual ,
238250 DistributionControl :: Automatic ( value) => Distribution :: Automatic ( value) ,
239251 DistributionControl :: AtBlock ( value) => Distribution :: AtBlock ( value) ,
240252 DistributionControl :: Interval ( value) => Distribution :: Interval ( value) ,
241253 } ;
242254
243- let permission = EmissionPermission {
255+ let permission = StreamPermission {
244256 allocation,
245257 distribution,
246- targets : emission
247- . targets
258+ recipients : stream
259+ . recipients
248260 . 0
249261 . iter ( )
250262 . map ( |( account, amount) | ( name_or_key ( account) , * amount) )
251263 . collect ( ) ,
252- accumulating : emission . accumulating ,
264+ accumulating : stream . accumulating ,
253265 } ;
254266
255- permissions. push ( Permission :: Emission ( ( permission, direction) ) ) ;
267+ permissions. push ( Permission :: Stream ( ( permission, direction) ) ) ;
256268 }
257- PermissionScope :: Curator ( _ ) => {
269+ PermissionScope :: Curator ( curator ) => {
258270 let direction = if contract. delegator == account_id {
259- Direction :: DelegatingTo ( vec ! [ name_or_key( & contract . recipient) ] )
271+ Direction :: DelegatingTo ( vec ! [ name_or_key( & curator . recipient) ] )
260272 } else {
261273 Direction :: DelegatedFrom ( name_or_key ( & contract. delegator ) )
262274 } ;
@@ -265,7 +277,7 @@ pub async fn get_permission_summary_for_agent(
265277 }
266278 PermissionScope :: Namespace ( namespace) => {
267279 let direction = if contract. delegator == account_id {
268- Direction :: DelegatingTo ( vec ! [ name_or_key( & contract . recipient) ] )
280+ Direction :: DelegatingTo ( vec ! [ name_or_key( & namespace . recipient) ] )
269281 } else {
270282 Direction :: DelegatedFrom ( name_or_key ( & contract. delegator ) )
271283 } ;
@@ -281,6 +293,24 @@ pub async fn get_permission_summary_for_agent(
281293 }
282294 }
283295 }
296+ PermissionScope :: Wallet ( wallet) => {
297+ let direction = if contract. delegator == account_id {
298+ Direction :: DelegatingTo ( vec ! [ name_or_key( & wallet. recipient) ] )
299+ } else {
300+ Direction :: DelegatedFrom ( name_or_key ( & contract. delegator ) )
301+ } ;
302+
303+ let permission = WalletPermission {
304+ r#type : match wallet. r#type {
305+ WalletScopeType :: Stake ( stake) => WalletPermissionType :: Stake {
306+ can_transfer_stake : stake. can_transfer_stake ,
307+ exclusive_stake_access : stake. exclusive_stake_access ,
308+ } ,
309+ } ,
310+ } ;
311+
312+ permissions. push ( Permission :: Wallet ( ( permission, direction) ) ) ;
313+ }
284314 }
285315 }
286316
0 commit comments