-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrecord.go
90 lines (65 loc) · 1.68 KB
/
record.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package paywall
import (
"errors"
"time"
"github.com/code-payments/code-server/pkg/currency"
)
type Record struct {
Id uint64
OwnerAccount string
DestinationTokenAccount string
ExchangeCurrency currency.Code
NativeAmount float64
RedirectUrl string
ShortPath string
Signature string
CreatedAt time.Time
}
func (r *Record) Validate() error {
if len(r.OwnerAccount) == 0 {
return errors.New("owner account is required")
}
if len(r.DestinationTokenAccount) == 0 {
return errors.New("destination token account is required")
}
if len(r.ExchangeCurrency) == 0 {
return errors.New("exchange currency is required")
}
if r.NativeAmount == 0 {
return errors.New("native amount cannot be zero")
}
if len(r.RedirectUrl) == 0 {
return errors.New("redirect url is required")
}
if len(r.ShortPath) == 0 {
return errors.New("short path is required")
}
if len(r.Signature) == 0 {
return errors.New("signature is required")
}
return nil
}
func (r *Record) Clone() Record {
return Record{
Id: r.Id,
OwnerAccount: r.OwnerAccount,
DestinationTokenAccount: r.DestinationTokenAccount,
ExchangeCurrency: r.ExchangeCurrency,
NativeAmount: r.NativeAmount,
RedirectUrl: r.RedirectUrl,
ShortPath: r.ShortPath,
Signature: r.Signature,
CreatedAt: r.CreatedAt,
}
}
func (r *Record) CopyTo(dst *Record) {
dst.Id = r.Id
dst.OwnerAccount = r.OwnerAccount
dst.DestinationTokenAccount = r.DestinationTokenAccount
dst.ExchangeCurrency = r.ExchangeCurrency
dst.NativeAmount = r.NativeAmount
dst.RedirectUrl = r.RedirectUrl
dst.ShortPath = r.ShortPath
dst.Signature = r.Signature
dst.CreatedAt = r.CreatedAt
}