diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-08-10 10:39:29 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-10 10:39:29 +0800 |
commit | 99d9591e5f0af54bf06f41cfd2658cfcc9ee6436 (patch) | |
tree | 784fb11e9830c97056524bb1330df5b551453a80 /core/types | |
parent | 36cce13f83e6aa2e3ee67b787f6cb133066425a9 (diff) | |
download | dexon-consensus-99d9591e5f0af54bf06f41cfd2658cfcc9ee6436.tar dexon-consensus-99d9591e5f0af54bf06f41cfd2658cfcc9ee6436.tar.gz dexon-consensus-99d9591e5f0af54bf06f41cfd2658cfcc9ee6436.tar.bz2 dexon-consensus-99d9591e5f0af54bf06f41cfd2658cfcc9ee6436.tar.lz dexon-consensus-99d9591e5f0af54bf06f41cfd2658cfcc9ee6436.tar.xz dexon-consensus-99d9591e5f0af54bf06f41cfd2658cfcc9ee6436.tar.zst dexon-consensus-99d9591e5f0af54bf06f41cfd2658cfcc9ee6436.zip |
core: Add block hash signature functions in core/ctypto.go. (#39)
Diffstat (limited to 'core/types')
-rw-r--r-- | core/types/block.go | 12 | ||||
-rw-r--r-- | core/types/validator.go | 29 |
2 files changed, 35 insertions, 6 deletions
diff --git a/core/types/block.go b/core/types/block.go index e35ab8d..363de3a 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -60,6 +60,7 @@ type Block struct { Timestamps map[ValidatorID]time.Time `json:"timestamps"` Acks map[common.Hash]struct{} `json:"acks"` CompactionChainAck CompactionChainAck `json:"compaction_chain_ack"` + Signature crypto.Signature `json:"signature"` ConsensusInfo ConsensusInfo `json:"consensus_info"` // ConsensusInfoParentHash is the hash value of Block.ConsensusInfoParentHash @@ -72,10 +73,21 @@ type Block struct { Status Status `json:"-"` } +// Block implements BlockConverter interface. +func (b *Block) Block() *Block { + return b +} + +// GetPayloads impelmemnts BlockConverter interface. +func (b *Block) GetPayloads() [][]byte { + return [][]byte{} +} + // BlockConverter interface define the interface for extracting block // information from an existing object. type BlockConverter interface { Block() *Block + GetPayloads() [][]byte } func (b *Block) String() string { diff --git a/core/types/validator.go b/core/types/validator.go index 48ce586..86c3acc 100644 --- a/core/types/validator.go +++ b/core/types/validator.go @@ -1,15 +1,15 @@ // 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 +// 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. +// 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 @@ -18,6 +18,8 @@ package types import ( + "bytes" + "github.com/dexon-foundation/dexon-consensus-core/common" ) @@ -25,3 +27,18 @@ import ( type ValidatorID struct { common.Hash } + +// ValidatorIDs implements sort.Interface for ValidatorID. +type ValidatorIDs []ValidatorID + +func (v ValidatorIDs) Len() int { + return len(v) +} + +func (v ValidatorIDs) Less(i int, j int) bool { + return bytes.Compare([]byte(v[i].Hash[:]), []byte(v[j].Hash[:])) == -1 +} + +func (v ValidatorIDs) Swap(i int, j int) { + v[i], v[j] = v[j], v[i] +} |