44 "errors"
55 "time"
66
7+ transactionpb "github.com/code-payments/code-protobuf-api/generated/go/transaction/v2"
8+
79 "github.com/code-payments/code-server/pkg/currency"
810 "github.com/code-payments/code-server/pkg/phone"
911)
@@ -106,6 +108,15 @@ type SendPrivatePaymentMetadata struct {
106108 IsWithdrawal bool
107109 IsRemoteSend bool
108110 IsMicroPayment bool
111+ IsTip bool
112+
113+ // Set when IsTip = true
114+ TipMetadata * TipMetadata
115+ }
116+
117+ type TipMetadata struct {
118+ Platform transactionpb.TippedUser_Platform
119+ Username string
109120}
110121
111122type ReceivePaymentsPrivatelyMetadata struct {
@@ -545,6 +556,14 @@ func (m *OpenAccountsMetadata) Validate() error {
545556}
546557
547558func (m * SendPrivatePaymentMetadata ) Clone () SendPrivatePaymentMetadata {
559+ var tipMetadata * TipMetadata
560+ if m .TipMetadata != nil {
561+ tipMetadata = & TipMetadata {
562+ Platform : m .TipMetadata .Platform ,
563+ Username : m .TipMetadata .Username ,
564+ }
565+ }
566+
548567 return SendPrivatePaymentMetadata {
549568 DestinationOwnerAccount : m .DestinationOwnerAccount ,
550569 DestinationTokenAccount : m .DestinationTokenAccount ,
@@ -554,13 +573,25 @@ func (m *SendPrivatePaymentMetadata) Clone() SendPrivatePaymentMetadata {
554573 ExchangeRate : m .ExchangeRate ,
555574 NativeAmount : m .NativeAmount ,
556575 UsdMarketValue : m .UsdMarketValue ,
557- IsWithdrawal : m .IsWithdrawal ,
558- IsRemoteSend : m .IsRemoteSend ,
559- IsMicroPayment : m .IsMicroPayment ,
576+
577+ IsWithdrawal : m .IsWithdrawal ,
578+ IsRemoteSend : m .IsRemoteSend ,
579+ IsMicroPayment : m .IsMicroPayment ,
580+ IsTip : m .IsTip ,
581+
582+ TipMetadata : tipMetadata ,
560583 }
561584}
562585
563586func (m * SendPrivatePaymentMetadata ) CopyTo (dst * SendPrivatePaymentMetadata ) {
587+ var tipMetadata * TipMetadata
588+ if m .TipMetadata != nil {
589+ tipMetadata = & TipMetadata {
590+ Platform : m .TipMetadata .Platform ,
591+ Username : m .TipMetadata .Username ,
592+ }
593+ }
594+
564595 dst .DestinationOwnerAccount = m .DestinationOwnerAccount
565596 dst .DestinationTokenAccount = m .DestinationTokenAccount
566597 dst .Quantity = m .Quantity
@@ -569,9 +600,13 @@ func (m *SendPrivatePaymentMetadata) CopyTo(dst *SendPrivatePaymentMetadata) {
569600 dst .ExchangeRate = m .ExchangeRate
570601 dst .NativeAmount = m .NativeAmount
571602 dst .UsdMarketValue = m .UsdMarketValue
603+
572604 dst .IsWithdrawal = m .IsWithdrawal
573605 dst .IsRemoteSend = m .IsRemoteSend
574606 dst .IsMicroPayment = m .IsMicroPayment
607+ dst .IsTip = m .IsTip
608+
609+ dst .TipMetadata = tipMetadata
575610}
576611
577612func (m * SendPrivatePaymentMetadata ) Validate () error {
@@ -599,6 +634,22 @@ func (m *SendPrivatePaymentMetadata) Validate() error {
599634 return errors .New ("usd market value cannot be zero" )
600635 }
601636
637+ if m .IsTip {
638+ if m .TipMetadata == nil {
639+ return errors .New ("tip metadata required for tips" )
640+ }
641+
642+ if m .TipMetadata .Platform == transactionpb .TippedUser_UNKNOWN {
643+ return errors .New ("tip platform is required" )
644+ }
645+
646+ if len (m .TipMetadata .Username ) == 0 {
647+ return errors .New ("tip username is required" )
648+ }
649+ } else if m .TipMetadata != nil {
650+ return errors .New ("tip metadata can only be set for tips" )
651+ }
652+
602653 return nil
603654}
604655
0 commit comments