-
Notifications
You must be signed in to change notification settings - Fork 29
/
batch.go
56 lines (48 loc) · 1.72 KB
/
batch.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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
didexported "github.com/ixofoundation/ixo-blockchain/lib/legacydid"
iidtypes "github.com/ixofoundation/ixo-blockchain/x/iid/types"
)
func (b Batch) MoreBuysThanSells() bool { return b.TotalSellAmount.IsLT(b.TotalBuyAmount) }
func (b Batch) MoreSellsThanBuys() bool { return b.TotalBuyAmount.IsLT(b.TotalSellAmount) }
func (b Batch) EqualBuysAndSells() bool { return b.TotalBuyAmount.IsEqual(b.TotalSellAmount) }
func (b Batch) HasNextAlpha() bool { return !b.NextPublicAlpha.IsNegative() }
func (b Batch) Empty() bool { return len(b.Buys) == 0 && len(b.Sells) == 0 && len(b.Swaps) == 0 }
func NewBatch(bondDid didexported.Did, token string, blocks sdk.Uint) Batch {
return Batch{
BondDid: bondDid,
BlocksRemaining: blocks,
NextPublicAlpha: sdk.OneDec().Neg(),
TotalBuyAmount: sdk.NewInt64Coin(token, 0),
TotalSellAmount: sdk.NewInt64Coin(token, 0),
}
}
func NewBaseOrder(accountDid iidtypes.DIDFragment, amount sdk.Coin) BaseOrder {
return BaseOrder{
AccountDid: accountDid,
Amount: amount,
Cancelled: false,
CancelReason: "",
}
}
func (bo BaseOrder) IsCancelled() bool {
return bo.Cancelled == true
}
func NewBuyOrder(buyerDid iidtypes.DIDFragment, amount sdk.Coin, maxPrices sdk.Coins) BuyOrder {
return BuyOrder{
BaseOrder: NewBaseOrder(buyerDid, amount),
MaxPrices: maxPrices,
}
}
func NewSellOrder(sellerDid iidtypes.DIDFragment, amount sdk.Coin) SellOrder {
return SellOrder{
BaseOrder: NewBaseOrder(sellerDid, amount),
}
}
func NewSwapOrder(swapperDid iidtypes.DIDFragment, from sdk.Coin, toToken string) SwapOrder {
return SwapOrder{
BaseOrder: NewBaseOrder(swapperDid, from),
ToToken: toToken,
}
}