From dbbacb8b19a27ed9a4f42dadfea6620807b923ac Mon Sep 17 00:00:00 2001 From: Krishna Upadhyaya Date: Tue, 26 Jul 2022 11:16:11 +0530 Subject: [PATCH] Using polyproto v0.0.2 and removed type utils --- consensus/bor/heimdallgrpc/checkpoint.go | 5 +-- consensus/bor/heimdallgrpc/span.go | 3 +- consensus/bor/heimdallgrpc/type_utils.go | 42 ------------------------ go.mod | 2 +- go.sum | 4 +-- 5 files changed, 8 insertions(+), 48 deletions(-) delete mode 100644 consensus/bor/heimdallgrpc/type_utils.go diff --git a/consensus/bor/heimdallgrpc/checkpoint.go b/consensus/bor/heimdallgrpc/checkpoint.go index ef25897237..eebf13a398 100644 --- a/consensus/bor/heimdallgrpc/checkpoint.go +++ b/consensus/bor/heimdallgrpc/checkpoint.go @@ -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()), } diff --git a/consensus/bor/heimdallgrpc/span.go b/consensus/bor/heimdallgrpc/span.go index cfd9d7ffd9..1bc5a07021 100644 --- a/consensus/bor/heimdallgrpc/span.go +++ b/consensus/bor/heimdallgrpc/span.go @@ -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, } diff --git a/consensus/bor/heimdallgrpc/type_utils.go b/consensus/bor/heimdallgrpc/type_utils.go deleted file mode 100644 index daa58da115..0000000000 --- a/consensus/bor/heimdallgrpc/type_utils.go +++ /dev/null @@ -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:])}, - } -} diff --git a/go.mod b/go.mod index 85d4ba5ece..a8fd2f9a02 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 90c3d5d229..53d933fb6c 100644 --- a/go.sum +++ b/go.sum @@ -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=