forked from tokenized/inspector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort.go
More file actions
36 lines (31 loc) · 1.01 KB
/
sort.go
File metadata and controls
36 lines (31 loc) · 1.01 KB
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
package inspector
// Timestamp returns the timestamp of the response action. Other action types will return nil.
// The timestamp is used to ensure the order that the smart contract originally processed the
// request is retained.
func (itx *Transaction) Timestamp() *uint64 {
return GetProtocolTimestamp(itx, itx.MsgProto)
}
// Implement sort.Interface to sort outgoing inspector transactions by timestamp. This is so during
// recovery of off chain state from on chain txs, the outgoing txs can be processed in the
// original order.
type TransactionList []*Transaction
// Len is part of sort.Interface.
func (s *TransactionList) Len() int {
return len(*s)
}
// Swap is part of sort.Interface.
func (s *TransactionList) Swap(i, j int) {
(*s)[i], (*s)[j] = (*s)[j], (*s)[i]
}
// Less is part of sort.Interface.
func (s *TransactionList) Less(i, j int) bool {
iTime := (*s)[i].Timestamp()
if iTime == nil {
return false
}
jTime := (*s)[j].Timestamp()
if jTime == nil {
return false
}
return *iTime < *jTime
}