@@ -30,6 +30,10 @@ access(all) contract PDS{
3030 ///
3131 access (all ) event DistributionCreated (DistId : UInt64 , title : String , metadata : {String : String }, state : UInt8 )
3232
33+ /// Emitted when an issuer has updated a distribution.
34+ ///
35+ access (all ) event DistributionUpdated (DistId : UInt64 , title : String , metadata : {String : String }, state : UInt8 )
36+
3337 /// Emmitted when a distribution manager has updated a distribution state.
3438 ///
3539 access (all ) event DistributionStateUpdated (DistId : UInt64 , state : UInt8 )
@@ -45,14 +49,19 @@ access(all) contract PDS{
4549 /// Struct that defines the details of a Distribution.
4650 ///
4751 access (all ) struct DistInfo {
48- access (all ) let title : String
49- access (all ) let metadata : {String : String }
52+ access (all ) var title : String
53+ access (all ) var metadata : {String : String }
5054 access (all ) var state : PDS .DistState
5155
5256 access (contract ) fun setState (newState : PDS .DistState ) {
5357 self .state = newState
5458 }
5559
60+ access (contract ) fun update (title : String , metadata : {String : String }) {
61+ self .title = title
62+ self .metadata = metadata
63+ }
64+
5665 /// DistInfo struct initializer.
5766 ///
5867 view init (title : String , metadata : {String : String }) {
@@ -209,11 +218,23 @@ access(all) contract PDS{
209218 }
210219
211220 access (Operate ) fun createDist (sharedCap : @SharedCapabilities , title : String , metadata : {String : String }) {
212- assert (title .length > 0 , message : " Title must not be empty" )
221+ pre {
222+ title .length > 0 : " Title must not be empty"
223+ }
213224 let c = self .cap ! .borrow ()!
214225 c .createNewDist (sharedCap : <- sharedCap , title : title , metadata : metadata )
215226 }
216227
228+ access (Operate ) fun updateDist (distId : UInt64 , title : String , metadata : {String : String }) {
229+ pre {
230+ title .length > 0 : " Title must not be empty"
231+ }
232+ let d = PDS .Distributions .remove (key : distId ) ?? panic (" No such distribution" )
233+ d .update (title : title , metadata : metadata )
234+ PDS .Distributions .insert (key : distId , d )
235+ emit DistributionUpdated (DistId : distId , title : title , metadata : metadata , state : d .state .rawValue )
236+ }
237+
217238 /// PackIssuer resource initializer.
218239 ///
219240 view init () {
0 commit comments