@@ -33,6 +33,7 @@ const (
3333 ReceivePaymentsPublicly
3434 EstablishRelationship // Deprecated privacy flow
3535 Login // Deprecated login flow
36+ PublicDistribution
3637)
3738
3839type Record struct {
@@ -47,6 +48,7 @@ type Record struct {
4748 ExternalDepositMetadata * ExternalDepositMetadata
4849 SendPublicPaymentMetadata * SendPublicPaymentMetadata
4950 ReceivePaymentsPubliclyMetadata * ReceivePaymentsPubliclyMetadata
51+ PublicDistributionMetadata * PublicDistributionMetadata
5052
5153 ExtendedMetadata []byte
5254
@@ -58,7 +60,7 @@ type Record struct {
5860}
5961
6062type OpenAccountsMetadata struct {
61- // Nothing yet
63+ // todo: What should be stored here given different flows?
6264}
6365
6466type ExternalDepositMetadata struct {
@@ -96,6 +98,12 @@ type ReceivePaymentsPubliclyMetadata struct {
9698 UsdMarketValue float64
9799}
98100
101+ type PublicDistributionMetadata struct {
102+ Source string
103+ Quantity uint64
104+ UsdMarketValue float64
105+ }
106+
99107func (r * Record ) IsCompleted () bool {
100108 return r .State == StateConfirmed
101109}
@@ -125,6 +133,12 @@ func (r *Record) Clone() Record {
125133 receivePaymentsPubliclyMetadata = & cloned
126134 }
127135
136+ var publicDistributionMetadata * PublicDistributionMetadata
137+ if r .PublicDistributionMetadata != nil {
138+ cloned := r .PublicDistributionMetadata .Clone ()
139+ publicDistributionMetadata = & cloned
140+ }
141+
128142 return Record {
129143 Id : r .Id ,
130144
@@ -137,6 +151,7 @@ func (r *Record) Clone() Record {
137151 ExternalDepositMetadata : externalDepositMetadata ,
138152 SendPublicPaymentMetadata : sendPublicPaymentMetadata ,
139153 ReceivePaymentsPubliclyMetadata : receivePaymentsPubliclyMetadata ,
154+ PublicDistributionMetadata : publicDistributionMetadata ,
140155
141156 ExtendedMetadata : r .ExtendedMetadata ,
142157
@@ -160,6 +175,7 @@ func (r *Record) CopyTo(dst *Record) {
160175 dst .ExternalDepositMetadata = r .ExternalDepositMetadata
161176 dst .SendPublicPaymentMetadata = r .SendPublicPaymentMetadata
162177 dst .ReceivePaymentsPubliclyMetadata = r .ReceivePaymentsPubliclyMetadata
178+ dst .PublicDistributionMetadata = r .PublicDistributionMetadata
163179
164180 dst .ExtendedMetadata = r .ExtendedMetadata
165181
@@ -227,6 +243,17 @@ func (r *Record) Validate() error {
227243 }
228244 }
229245
246+ if r .IntentType == PublicDistribution {
247+ if r .PublicDistributionMetadata == nil {
248+ return errors .New ("public distribution metadata must be present" )
249+ }
250+
251+ err := r .PublicDistributionMetadata .Validate ()
252+ if err != nil {
253+ return err
254+ }
255+ }
256+
230257 return nil
231258}
232259
@@ -388,6 +415,32 @@ func (m *ReceivePaymentsPubliclyMetadata) Validate() error {
388415 return nil
389416}
390417
418+ func (m * PublicDistributionMetadata ) Clone () PublicDistributionMetadata {
419+ return PublicDistributionMetadata {
420+ Source : m .Source ,
421+ Quantity : m .Quantity ,
422+ UsdMarketValue : m .UsdMarketValue ,
423+ }
424+ }
425+
426+ func (m * PublicDistributionMetadata ) CopyTo (dst * PublicDistributionMetadata ) {
427+ dst .Source = m .Source
428+ dst .Quantity = m .Quantity
429+ dst .UsdMarketValue = m .UsdMarketValue
430+ }
431+
432+ func (m * PublicDistributionMetadata ) Validate () error {
433+ if len (m .Source ) == 0 {
434+ return errors .New ("source is required" )
435+ }
436+
437+ if m .Quantity == 0 {
438+ return errors .New ("quantity is required" )
439+ }
440+
441+ return nil
442+ }
443+
391444func (s State ) IsTerminal () bool {
392445 switch s {
393446 case StateConfirmed :
@@ -439,6 +492,8 @@ func (t Type) String() string {
439492 return "establish_relationship"
440493 case Login :
441494 return "login"
495+ case PublicDistribution :
496+ return "public_distribution"
442497 }
443498
444499 return "unknown"
0 commit comments