-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpurchase.go
65 lines (49 loc) · 1006 Bytes
/
purchase.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
package onramp
import (
"bytes"
"errors"
"time"
"github.com/google/uuid"
)
// todo: We can track provider, fulfillment state, time to fulfillment, etc.
type Record struct {
Id uint64
Owner string
Currency string
Amount float64
Nonce uuid.UUID
CreatedAt time.Time
}
func (r *Record) Validate() error {
if len(r.Owner) == 0 {
return errors.New("owner is required")
}
if len(r.Currency) == 0 {
return errors.New("currency is required")
}
if r.Amount <= 0 {
return errors.New("amount must be positive")
}
if bytes.Equal(r.Nonce[:], uuid.Nil[:]) {
return errors.New("nonce is required")
}
return nil
}
func (r *Record) Clone() Record {
return Record{
Id: r.Id,
Owner: r.Owner,
Currency: r.Currency,
Amount: r.Amount,
Nonce: r.Nonce,
CreatedAt: r.CreatedAt,
}
}
func (r *Record) CopyTo(dst *Record) {
dst.Id = r.Id
dst.Owner = r.Owner
dst.Currency = r.Currency
dst.Amount = r.Amount
dst.Nonce = r.Nonce
dst.CreatedAt = r.CreatedAt
}