aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-10-04 17:19:28 +0800
committerGitHub <noreply@github.com>2018-10-04 17:19:28 +0800
commit604dd7e52c8cbffd7646205c464f7333d215ceb6 (patch)
tree9f4b8ade150981f5491b27ffee07bdf6e4e74918 /common
parentb4764a67bc19b2b9ea6f07d45a1275f530060c68 (diff)
downloaddexon-consensus-604dd7e52c8cbffd7646205c464f7333d215ceb6.tar
dexon-consensus-604dd7e52c8cbffd7646205c464f7333d215ceb6.tar.gz
dexon-consensus-604dd7e52c8cbffd7646205c464f7333d215ceb6.tar.bz2
dexon-consensus-604dd7e52c8cbffd7646205c464f7333d215ceb6.tar.lz
dexon-consensus-604dd7e52c8cbffd7646205c464f7333d215ceb6.tar.xz
dexon-consensus-604dd7e52c8cbffd7646205c464f7333d215ceb6.tar.zst
dexon-consensus-604dd7e52c8cbffd7646205c464f7333d215ceb6.zip
core: Check sorted ack in sanity check (#173)
Diffstat (limited to 'common')
-rw-r--r--common/types.go24
1 files changed, 23 insertions, 1 deletions
diff --git a/common/types.go b/common/types.go
index bd15c5b..1bda164 100644
--- a/common/types.go
+++ b/common/types.go
@@ -1,6 +1,23 @@
// Copyright 2018 The dexon-consensus-core Authors
// This file is part of the dexon-consensus-core library.
//
+// The dexon-consensus-core library is free software: you can redistribute it
+// and/or modify it under the terms of the GNU Lesser General Public License as
+// published by the Free Software Foundation, either version 3 of the License,
+// or (at your option) any later version.
+//
+// The dexon-consensus-core library is distributed in the hope that it will be
+// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
+// General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with the dexon-consensus-core library. If not, see
+// <http://www.gnu.org/licenses/>.
+
+// Copyright 2018 The dexon-consensus-core Authors
+// This file is part of the dexon-consensus-core library.
+//
// The dexon-consensus-core library is free software: you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the License,
@@ -41,6 +58,11 @@ func (h Hash) Equal(hp Hash) bool {
return h == hp
}
+// Less compares if current hash is lesser.
+func (h Hash) Less(hp Hash) bool {
+ return bytes.Compare(h[:], hp[:]) < 0
+}
+
// MarshalText implements the encoding.TextMarhsaler interface.
func (h Hash) MarshalText() ([]byte, error) {
result := make([]byte, hex.EncodedLen(HashLength))
@@ -58,7 +80,7 @@ func (h *Hash) UnmarshalText(text []byte) error {
type Hashes []Hash
func (hs Hashes) Len() int { return len(hs) }
-func (hs Hashes) Less(i, j int) bool { return bytes.Compare(hs[i][:], hs[j][:]) < 0 }
+func (hs Hashes) Less(i, j int) bool { return hs[i].Less(hs[j]) }
func (hs Hashes) Swap(i, j int) { hs[i], hs[j] = hs[j], hs[i] }
// SortedHashes is a slice of hashes sorted in ascending order.