|
@ -1,7 +1,11 @@ |
|
|
package types |
|
|
package types |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
|
|
|
"fmt" |
|
|
|
|
|
"reflect" |
|
|
|
|
|
|
|
|
"github.com/tendermint/abci/types" |
|
|
"github.com/tendermint/abci/types" |
|
|
|
|
|
crypto "github.com/tendermint/go-crypto" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
// TM2PB is used for converting Tendermint types to protobuf types.
|
|
|
// TM2PB is used for converting Tendermint types to protobuf types.
|
|
@ -12,38 +16,39 @@ type tm2pb struct{} |
|
|
|
|
|
|
|
|
func (tm2pb) Header(header *Header) types.Header { |
|
|
func (tm2pb) Header(header *Header) types.Header { |
|
|
return types.Header{ |
|
|
return types.Header{ |
|
|
ChainID: header.ChainID, |
|
|
|
|
|
Height: header.Height, |
|
|
|
|
|
Time: header.Time.Unix(), |
|
|
|
|
|
NumTxs: int32(header.NumTxs), // XXX: overflow
|
|
|
|
|
|
LastBlockID: TM2PB.BlockID(header.LastBlockID), |
|
|
|
|
|
LastCommitHash: header.LastCommitHash, |
|
|
|
|
|
DataHash: header.DataHash, |
|
|
|
|
|
AppHash: header.AppHash, |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (tm2pb) BlockID(blockID BlockID) types.BlockID { |
|
|
|
|
|
return types.BlockID{ |
|
|
|
|
|
Hash: blockID.Hash, |
|
|
|
|
|
Parts: TM2PB.PartSetHeader(blockID.PartsHeader), |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (tm2pb) PartSetHeader(partSetHeader PartSetHeader) types.PartSetHeader { |
|
|
|
|
|
return types.PartSetHeader{ |
|
|
|
|
|
Total: int32(partSetHeader.Total), // XXX: overflow
|
|
|
|
|
|
Hash: partSetHeader.Hash, |
|
|
|
|
|
|
|
|
ChainId: header.ChainID, |
|
|
|
|
|
Height: header.Height, |
|
|
|
|
|
Time: header.Time.Unix(), |
|
|
|
|
|
NumTxs: int32(header.NumTxs), // XXX: overflow
|
|
|
|
|
|
LastBlockHash: header.LastBlockID.Hash, |
|
|
|
|
|
AppHash: header.AppHash, |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (tm2pb) Validator(val *Validator) types.Validator { |
|
|
func (tm2pb) Validator(val *Validator) types.Validator { |
|
|
return types.Validator{ |
|
|
return types.Validator{ |
|
|
PubKey: val.PubKey.Bytes(), |
|
|
|
|
|
|
|
|
PubKey: TM2PB.PubKey(val.PubKey), |
|
|
Power: val.VotingPower, |
|
|
Power: val.VotingPower, |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (tm2pb) PubKey(pubKey crypto.PubKey) *types.PubKey { |
|
|
|
|
|
switch pk := pubKey.(type) { |
|
|
|
|
|
case crypto.PubKeyEd25519: |
|
|
|
|
|
return &types.PubKey{ |
|
|
|
|
|
Type: "ed25519", |
|
|
|
|
|
Data: pk[:], |
|
|
|
|
|
} |
|
|
|
|
|
case crypto.PubKeySecp256k1: |
|
|
|
|
|
return &types.PubKey{ |
|
|
|
|
|
Type: "secp256k1", |
|
|
|
|
|
Data: pk[:], |
|
|
|
|
|
} |
|
|
|
|
|
default: |
|
|
|
|
|
panic(fmt.Sprintf("unknown pubkey type: %v %v", pubKey, reflect.TypeOf(pubKey))) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func (tm2pb) Validators(vals *ValidatorSet) []types.Validator { |
|
|
func (tm2pb) Validators(vals *ValidatorSet) []types.Validator { |
|
|
validators := make([]types.Validator, len(vals.Validators)) |
|
|
validators := make([]types.Validator, len(vals.Validators)) |
|
|
for i, val := range vals.Validators { |
|
|
for i, val := range vals.Validators { |
|
|