|
|
@ -2,28 +2,9 @@ package types |
|
|
|
|
|
|
|
import ( |
|
|
|
abci "github.com/tendermint/tendermint/abci/types" |
|
|
|
"github.com/tendermint/tendermint/crypto" |
|
|
|
"github.com/tendermint/tendermint/crypto/ed25519" |
|
|
|
cryptoenc "github.com/tendermint/tendermint/crypto/encoding" |
|
|
|
"github.com/tendermint/tendermint/crypto/secp256k1" |
|
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" |
|
|
|
) |
|
|
|
|
|
|
|
//-------------------------------------------------------
|
|
|
|
// Use strings to distinguish types in ABCI messages
|
|
|
|
|
|
|
|
const ( |
|
|
|
ABCIPubKeyTypeEd25519 = ed25519.KeyType |
|
|
|
ABCIPubKeyTypeSecp256k1 = secp256k1.KeyType |
|
|
|
) |
|
|
|
|
|
|
|
// TODO: Make non-global by allowing for registration of more pubkey types
|
|
|
|
|
|
|
|
var ABCIPubKeyTypesToNames = map[string]string{ |
|
|
|
ABCIPubKeyTypeEd25519: ed25519.PubKeyName, |
|
|
|
ABCIPubKeyTypeSecp256k1: secp256k1.PubKeyName, |
|
|
|
} |
|
|
|
|
|
|
|
//-------------------------------------------------------
|
|
|
|
|
|
|
|
// TM2PB is used for converting Tendermint ABCI to protobuf ABCI.
|
|
|
@ -32,29 +13,6 @@ var TM2PB = tm2pb{} |
|
|
|
|
|
|
|
type tm2pb struct{} |
|
|
|
|
|
|
|
func (tm2pb) Header(header *Header) tmproto.Header { |
|
|
|
return tmproto.Header{ |
|
|
|
Version: header.Version.ToProto(), |
|
|
|
ChainID: header.ChainID, |
|
|
|
Height: header.Height, |
|
|
|
Time: header.Time, |
|
|
|
|
|
|
|
LastBlockId: header.LastBlockID.ToProto(), |
|
|
|
|
|
|
|
LastCommitHash: header.LastCommitHash, |
|
|
|
DataHash: header.DataHash, |
|
|
|
|
|
|
|
ValidatorsHash: header.ValidatorsHash, |
|
|
|
NextValidatorsHash: header.NextValidatorsHash, |
|
|
|
ConsensusHash: header.ConsensusHash, |
|
|
|
AppHash: header.AppHash, |
|
|
|
LastResultsHash: header.LastResultsHash, |
|
|
|
|
|
|
|
EvidenceHash: header.EvidenceHash, |
|
|
|
ProposerAddress: header.ProposerAddress, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func (tm2pb) Validator(val *Validator) abci.Validator { |
|
|
|
return abci.Validator{ |
|
|
|
Address: val.PubKey.Address(), |
|
|
@ -62,20 +20,6 @@ func (tm2pb) Validator(val *Validator) abci.Validator { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func (tm2pb) BlockID(blockID BlockID) tmproto.BlockID { |
|
|
|
return tmproto.BlockID{ |
|
|
|
Hash: blockID.Hash, |
|
|
|
PartSetHeader: TM2PB.PartSetHeader(blockID.PartSetHeader), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func (tm2pb) PartSetHeader(header PartSetHeader) tmproto.PartSetHeader { |
|
|
|
return tmproto.PartSetHeader{ |
|
|
|
Total: header.Total, |
|
|
|
Hash: header.Hash, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// XXX: panics on unknown pubkey type
|
|
|
|
func (tm2pb) ValidatorUpdate(val *Validator) abci.ValidatorUpdate { |
|
|
|
pk, err := cryptoenc.PubKeyToProto(val.PubKey) |
|
|
@ -97,18 +41,6 @@ func (tm2pb) ValidatorUpdates(vals *ValidatorSet) []abci.ValidatorUpdate { |
|
|
|
return validators |
|
|
|
} |
|
|
|
|
|
|
|
// XXX: panics on nil or unknown pubkey type
|
|
|
|
func (tm2pb) NewValidatorUpdate(pubkey crypto.PubKey, power int64) abci.ValidatorUpdate { |
|
|
|
pubkeyABCI, err := cryptoenc.PubKeyToProto(pubkey) |
|
|
|
if err != nil { |
|
|
|
panic(err) |
|
|
|
} |
|
|
|
return abci.ValidatorUpdate{ |
|
|
|
PubKey: pubkeyABCI, |
|
|
|
Power: power, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// PB2TM is used for converting protobuf ABCI to Tendermint ABCI.
|
|
|
|