Using polyproto v0.0.2 and removed type utils

This commit is contained in:
Krishna Upadhyaya 2022-07-26 11:16:11 +05:30
parent 385aff85f0
commit dbbacb8b19
5 changed files with 8 additions and 48 deletions

View file

@ -7,6 +7,7 @@ import (
"github.com/ethereum/go-ethereum/consensus/bor/heimdall/checkpoint"
proto "github.com/maticnetwork/polyproto/heimdall"
protoutils "github.com/maticnetwork/polyproto/utils"
)
func (h *HeimdallGRPCClient) FetchCheckpointCount(ctx context.Context) (int64, error) {
@ -31,8 +32,8 @@ func (h *HeimdallGRPCClient) FetchCheckpoint(ctx context.Context, number int64)
checkpoint := &checkpoint.Checkpoint{
StartBlock: new(big.Int).SetUint64(res.Result.StartBlock),
EndBlock: new(big.Int).SetUint64(res.Result.EndBlock),
RootHash: ConvertH256ToHash(res.Result.RootHash),
Proposer: ConvertH160toAddress(res.Result.Proposer),
RootHash: protoutils.ConvertH256ToHash(res.Result.RootHash),
Proposer: protoutils.ConvertH160toAddress(res.Result.Proposer),
BorChainID: res.Result.BorChainID,
Timestamp: uint64(res.Result.Timestamp.GetSeconds()),
}

View file

@ -7,6 +7,7 @@ import (
"github.com/ethereum/go-ethereum/consensus/bor/valset"
proto "github.com/maticnetwork/polyproto/heimdall"
protoutils "github.com/maticnetwork/polyproto/utils"
)
func (h *HeimdallGRPCClient) Span(ctx context.Context, spanID uint64) (*span.HeimdallSpan, error) {
@ -50,7 +51,7 @@ func parseSpan(protoSpan *proto.Span) *span.HeimdallSpan {
func parseValidator(validator *proto.Validator) *valset.Validator {
return &valset.Validator{
ID: validator.ID,
Address: ConvertH160toAddress(validator.Address),
Address: protoutils.ConvertH160toAddress(validator.Address),
VotingPower: validator.VotingPower,
ProposerPriority: validator.ProposerPriority,
}

View file

@ -1,42 +0,0 @@
package heimdallgrpc
import (
"encoding/binary"
proto "github.com/maticnetwork/polyproto/heimdall"
)
func ConvertH160toAddress(h160 *proto.H160) [20]byte {
var addr [20]byte
binary.BigEndian.PutUint64(addr[0:], h160.Hi.Hi)
binary.BigEndian.PutUint64(addr[8:], h160.Hi.Lo)
binary.BigEndian.PutUint32(addr[16:], h160.Lo)
return addr
}
func ConvertAddressToH160(addr [20]byte) *proto.H160 {
return &proto.H160{
Lo: binary.BigEndian.Uint32(addr[16:]),
Hi: &proto.H128{Lo: binary.BigEndian.Uint64(addr[8:]), Hi: binary.BigEndian.Uint64(addr[0:])},
}
}
func ConvertH256ToHash(h256 *proto.H256) [32]byte {
var hash [32]byte
binary.BigEndian.PutUint64(hash[0:], h256.Hi.Hi)
binary.BigEndian.PutUint64(hash[8:], h256.Hi.Lo)
binary.BigEndian.PutUint64(hash[16:], h256.Lo.Hi)
binary.BigEndian.PutUint64(hash[24:], h256.Lo.Lo)
return hash
}
func ConvertHashToH256(hash [32]byte) *proto.H256 {
return &proto.H256{
Lo: &proto.H128{Lo: binary.BigEndian.Uint64(hash[24:]), Hi: binary.BigEndian.Uint64(hash[16:])},
Hi: &proto.H128{Lo: binary.BigEndian.Uint64(hash[8:]), Hi: binary.BigEndian.Uint64(hash[0:])},
}
}

2
go.mod
View file

@ -44,7 +44,7 @@ require (
github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e
github.com/julienschmidt/httprouter v1.3.0
github.com/karalabe/usb v0.0.2
github.com/maticnetwork/polyproto v0.0.1
github.com/maticnetwork/polyproto v0.0.2
github.com/mattn/go-colorable v0.1.8
github.com/mattn/go-isatty v0.0.12
github.com/mitchellh/cli v1.1.2

4
go.sum
View file

@ -337,8 +337,8 @@ github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/maticnetwork/polyproto v0.0.1 h1:qdxoyGd9EkYs910n4crEQqZETpvpRSrprlDYtdbZrqg=
github.com/maticnetwork/polyproto v0.0.1/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o=
github.com/maticnetwork/polyproto v0.0.2 h1:cPxuxbIDItdwGnucc3lZB58U8Zfe1mH73PWTGd15554=
github.com/maticnetwork/polyproto v0.0.2/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o=
github.com/matryer/moq v0.0.0-20190312154309-6cfb0558e1bd/go.mod h1:9ELz6aaclSIGnZBoaSLZ3NAl1VTufbOrXBPvtcy6WiQ=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=