Skip to content

Commit e1c7a14

Browse files
author
Ivan Bozhytskyi
committed
[TX] implement sorting & add helper func
1 parent ebef664 commit e1c7a14

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

types/v1/marshal.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,8 @@ func (t *Tx) MarshalJSON() ([]byte, error) {
7979
// Wrap the Tx type to avoid infinite recursion
8080
return json.Marshal(wrappedTx(*t))
8181
}
82+
83+
// Sort sorts the response by date, descending
84+
func (txs Txs) Len() int { return len(txs) }
85+
func (txs Txs) Less(i, j int) bool { return txs[i].Date > txs[j].Date }
86+
func (txs Txs) Swap(i, j int) { txs[i], txs[j] = txs[j], txs[i] }

types/v1/tx.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,3 +406,15 @@ func InferDirection(transfer *Transfer, addressSet mapset.Set) Direction {
406406
}
407407
return DirectionOutgoing
408408
}
409+
410+
func IsTxTypeAmong(txType TransactionType, types []TransactionType) bool {
411+
result := false
412+
for _, t := range types {
413+
if txType == t {
414+
result = true
415+
break
416+
}
417+
}
418+
419+
return result
420+
}

0 commit comments

Comments
 (0)