/
order.go
114 lines (101 loc) · 5.22 KB
/
order.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package base
import (
"fmt"
"github.com/AssetMantle/schema/go/data"
"github.com/AssetMantle/schema/go/documents"
"github.com/AssetMantle/schema/go/ids"
"github.com/AssetMantle/schema/go/properties"
"github.com/AssetMantle/schema/go/properties/constants"
"github.com/AssetMantle/schema/go/qualified"
"github.com/AssetMantle/schema/go/types"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
)
type order struct {
documents.Document
}
var _ documents.Order = (*order)(nil)
func (order order) ValidateBasic() error {
if err := order.Document.ValidateBasic(); err != nil {
return err
}
if property := order.GetProperty(constants.MakerIDProperty.GetID()); property == nil || !property.IsMeta() {
return fmt.Errorf("order must have a revealed %s", constants.MakerIDProperty.GetID())
}
if property := order.GetProperty(constants.MakerAssetIDProperty.GetID()); property == nil || !property.IsMeta() {
return fmt.Errorf("order must have a revealed %s", constants.MakerAssetIDProperty.GetID())
}
if property := order.GetProperty(constants.MakerSplitProperty.GetID()); property == nil || !property.IsMeta() {
return fmt.Errorf("order must have a revealed %s", constants.MakerSplitProperty.GetID())
}
if property := order.GetProperty(constants.ExpiryHeightProperty.GetID()); property == nil || !property.IsMeta() {
return fmt.Errorf("order must have a revealed %s", constants.ExpiryHeightProperty.GetID())
}
if property := order.GetProperty(constants.TakerAssetIDProperty.GetID()); property == nil {
return fmt.Errorf("order must have a %s", constants.TakerAssetIDProperty.GetID())
}
if property := order.GetProperty(constants.TakerSplitProperty.GetID()); property == nil {
return fmt.Errorf("order must have a %s", constants.TakerSplitProperty.GetID())
}
return nil
}
func (order order) GetMakerID() ids.IdentityID {
if property := order.GetProperty(constants.MakerIDProperty.GetID()); property != nil && property.IsMeta() {
return property.Get().(properties.MetaProperty).GetData().Get().(data.IDData).Get().Get().(ids.IdentityID)
}
return constants.MakerIDProperty.GetData().Get().(data.IDData).Get().Get().(ids.IdentityID)
}
func (order order) GetMakerAssetID() ids.AssetID {
if property := order.GetProperty(constants.MakerAssetIDProperty.GetID()); property != nil && property.IsMeta() {
return property.Get().(properties.MetaProperty).GetData().Get().(data.IDData).Get().Get().(ids.AssetID)
}
return constants.MakerAssetIDProperty.GetData().Get().(data.IDData).Get().Get().(ids.AssetID)
}
func (order order) GetTakerAssetID() ids.AssetID {
if property := order.GetProperty(constants.TakerAssetIDProperty.GetID()); property != nil && property.IsMeta() {
return property.Get().(properties.MetaProperty).GetData().Get().(data.IDData).Get().Get().(ids.AssetID)
}
return constants.TakerAssetIDProperty.GetData().Get().(data.IDData).Get().Get().(ids.AssetID)
}
func (order order) GetMakerSplit() sdkTypes.Int {
if property := order.GetProperty(constants.MakerSplitProperty.GetID()); property != nil && property.IsMeta() {
return property.Get().(properties.MetaProperty).GetData().Get().(data.NumberData).Get()
}
return constants.MakerSplitProperty.GetData().Get().(data.NumberData).Get()
}
func (order order) GetTakerSplit() sdkTypes.Int {
if property := order.GetProperty(constants.TakerSplitProperty.GetID()); property != nil && property.IsMeta() {
return property.Get().(properties.MetaProperty).GetData().Get().(data.NumberData).Get()
}
return constants.TakerSplitProperty.GetData().Get().(data.NumberData).Get()
}
func (order order) GetExpiryHeight() types.Height {
if property := order.GetProperty(constants.ExpiryHeightProperty.GetID()); property != nil && property.IsMeta() {
return property.Get().(properties.MetaProperty).GetData().Get().(data.HeightData).Get()
}
return constants.ExpiryHeightProperty.GetData().Get().(data.HeightData).Get()
}
func (order order) GetTakerID() ids.IdentityID {
if property := order.GetProperty(constants.TakerIDProperty.GetID()); property != nil && property.IsMeta() {
return property.Get().(properties.MetaProperty).GetData().Get().(data.IDData).Get().Get().(ids.IdentityID)
}
return constants.TakerIDProperty.GetData().Get().(data.IDData).Get().Get().(ids.IdentityID)
}
func (order order) GetExchangeRate() sdkTypes.Dec {
// TODO change definition to maker/taker exchange rate
if property := order.GetProperty(constants.ExchangeRateProperty.GetID()); property != nil && property.IsMeta() {
return property.Get().(properties.MetaProperty).GetData().Get().(data.DecData).Get()
}
return constants.ExchangeRateProperty.GetData().Get().(data.DecData).Get()
}
func (order order) GetExecutionHeight() types.Height {
if property := order.GetProperty(constants.ExecutionHeightProperty.GetID()); property != nil && property.IsMeta() {
return property.Get().(properties.MetaProperty).GetData().Get().(data.HeightData).Get()
}
return constants.ExecutionHeightProperty.GetData().Get().(data.HeightData).Get()
}
func NewOrder(classificationID ids.ClassificationID, immutables qualified.Immutables, mutables qualified.Mutables) documents.Order {
return order{Document: NewDocument(classificationID, immutables, mutables)}
}
func NewOrderFromDocument(document documents.Document) documents.Order {
return order{Document: document}
}