Skip to content

Commit

Permalink
isactive getter for core type
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 committed Jan 24, 2024
1 parent 09e6c07 commit 66f2c87
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions client/core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,27 @@ type Match struct {
IsCancel bool `json:"isCancel"`
}

// IsActive blah blah blah... copied from db.MatchIsActive.
func (m *Match) IsActive() bool {
if m.Status == order.MatchConfirmed {
return false
}
if m.Status == order.MatchComplete && m.Swap == nil {
return false
}
if m.Refund != nil {
return false
}
if m.Revoked {
status, side := m.Status, m.Side
if status == order.NewlyMatched ||
(status == order.MakerSwapCast && side == order.Taker) {
return false
}
}
return true
}

// Coin encodes both the coin ID and the asset-dependent string representation
// of the coin ID.
type Coin struct {
Expand Down Expand Up @@ -414,6 +435,19 @@ type Order struct {
ReadyToTick bool `json:"readyToTick"`
}

func (ord *Order) IsActive() bool {
if ord.Status == order.OrderStatusBooked ||
ord.Status == order.OrderStatusEpoch {
return true
}
for _, m := range ord.Matches {
if m.IsActive() {
return true
}
}
return false
}

// InFlightOrder is an Order that is not stamped yet, but has a temporary ID
// to match once order submission is complete.
type InFlightOrder struct {
Expand Down

0 comments on commit 66f2c87

Please sign in to comment.