diff --git a/README.md b/README.md index a864c210b..ba71d055e 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ based library dependencies (`libbls` and `mcl`) setup correctly for you. You can versions easily, an example: ``` -$ eval $(gimme 1.12.6) +$ eval $(gimme 1.13.6) ``` Note that changing the go version might mean that dependencies won't work out right when trying to @@ -129,7 +129,7 @@ brew install openssl ## Dev Environment Setup -The required go version is: **go1.12** +The required go version is: **go1.13.6** ```bash export GOPATH=$HOME/ diff --git a/core/types/crosslink.go b/core/types/crosslink.go index df073f4c6..61788db05 100644 --- a/core/types/crosslink.go +++ b/core/types/crosslink.go @@ -2,6 +2,7 @@ package types import ( "encoding/hex" + "encoding/json" "math/big" "sort" @@ -24,16 +25,6 @@ type CrossLink struct { EpochF *big.Int } -// RPCCrossLink is used for returning data to RPC calls, converting byte arrays to hex encoded strings -type RPCCrossLink struct { - HashF common.Hash `json:"parentHash"` - BlockNumberF *big.Int `json:"blockNumber"` - SignatureF string `json:"signature"` - BitmapF string `json:"signatureBitmap"` - ShardIDF uint32 `json:"shardId"` - EpochF *big.Int `json:"epochNumber"` -} - // NewCrossLink returns a new cross link object // epoch is the parentHeader's epoch func NewCrossLink(header *block.Header, epoch *big.Int) CrossLink { @@ -80,16 +71,23 @@ func (cl CrossLink) Signature() [96]byte { return cl.SignatureF } -// ConvertForRPC converts CrossLink into RPCCrossLink -func (cl CrossLink) ConvertForRPC() *RPCCrossLink { - return &RPCCrossLink{ - HashF: cl.HashF, - BlockNumberF: cl.BlockNumberF, - SignatureF: hex.EncodeToString(cl.SignatureF[:]), - BitmapF: hex.EncodeToString(cl.BitmapF), - ShardIDF: cl.ShardIDF, - EpochF: cl.EpochF, - } +// MarshalJSON .. +func (cl CrossLink) MarshalJSON() ([]byte, error) { + return json.Marshal(struct { + Hash common.Hash `json:"hash"` + BlockNumber *big.Int `json:"block-number"` + Signature string `json:"signature"` + Bitmap string `json:"signature-bitmap"` + ShardID uint32 `json:"shard-id"` + EpochNumber *big.Int `json:"epoch-number"` + }{ + cl.HashF, + cl.BlockNumberF, + hex.EncodeToString(cl.SignatureF[:]), + hex.EncodeToString(cl.BitmapF), + cl.ShardIDF, + cl.EpochF, + }) } // Serialize returns bytes of cross link rlp-encoded content diff --git a/hmy/api_backend.go b/hmy/api_backend.go index 2be9999e7..d93ae932d 100644 --- a/hmy/api_backend.go +++ b/hmy/api_backend.go @@ -581,15 +581,15 @@ func (b *APIBackend) GetCurrentBadBlocks() []core.BadBlock { } // GetLastCrossLinks .. -func (b *APIBackend) GetLastCrossLinks() ([]*types.RPCCrossLink, error) { - lastCrossLinks := []*types.RPCCrossLink{} +func (b *APIBackend) GetLastCrossLinks() ([]*types.CrossLink, error) { + crossLinks := []*types.CrossLink{} for i := uint32(1); i < shard.Schedule.InstanceForEpoch(b.CurrentBlock().Epoch()).NumShards(); i++ { link, err := b.hmy.BlockChain().ReadShardLastCrossLink(i) if err != nil { return nil, err } - lastCrossLinks = append(lastCrossLinks, link.ConvertForRPC()) + crossLinks = append(crossLinks, link) } - return lastCrossLinks, nil + return crossLinks, nil } diff --git a/internal/hmyapi/apiv1/backend.go b/internal/hmyapi/apiv1/backend.go index fbb1f525f..9e2ea5e77 100644 --- a/internal/hmyapi/apiv1/backend.go +++ b/internal/hmyapi/apiv1/backend.go @@ -87,5 +87,5 @@ type Backend interface { GetSuperCommittees() (*quorum.Transition, error) GetTotalStakingSnapshot() *big.Int GetCurrentBadBlocks() []core.BadBlock - GetLastCrossLinks() ([]*types.RPCCrossLink, error) + GetLastCrossLinks() ([]*types.CrossLink, error) } diff --git a/internal/hmyapi/apiv1/blockchain.go b/internal/hmyapi/apiv1/blockchain.go index 37cdd54bd..fe9e9821f 100644 --- a/internal/hmyapi/apiv1/blockchain.go +++ b/internal/hmyapi/apiv1/blockchain.go @@ -848,6 +848,9 @@ func (s *PublicBlockChainAPI) GetStakingNetworkInfo(ctx context.Context) (*Staki } // GetLastCrossLinks .. -func (s *PublicBlockChainAPI) GetLastCrossLinks() ([]*types.RPCCrossLink, error) { - return s.b.GetLastCrossLinks() +func (s *PublicBlockChainAPI) GetLastCrossLinks() ([]*types.CrossLink, error) { + if s.b.GetShardID() == shard.BeaconChainShardID { + return s.b.GetLastCrossLinks() + } + return nil, errNotBeaconChainShard } diff --git a/internal/hmyapi/apiv2/backend.go b/internal/hmyapi/apiv2/backend.go index 9918e1493..8235d4610 100644 --- a/internal/hmyapi/apiv2/backend.go +++ b/internal/hmyapi/apiv2/backend.go @@ -87,5 +87,5 @@ type Backend interface { GetSuperCommittees() (*quorum.Transition, error) GetTotalStakingSnapshot() *big.Int GetCurrentBadBlocks() []core.BadBlock - GetLastCrossLinks() ([]*types.RPCCrossLink, error) + GetLastCrossLinks() ([]*types.CrossLink, error) } diff --git a/internal/hmyapi/apiv2/blockchain.go b/internal/hmyapi/apiv2/blockchain.go index 85970db52..2f651db4d 100644 --- a/internal/hmyapi/apiv2/blockchain.go +++ b/internal/hmyapi/apiv2/blockchain.go @@ -813,6 +813,9 @@ func (s *PublicBlockChainAPI) GetStakingNetworkInfo(ctx context.Context) (*Staki } // GetLastCrossLinks .. -func (s *PublicBlockChainAPI) GetLastCrossLinks() ([]*types.RPCCrossLink, error) { - return s.b.GetLastCrossLinks() +func (s *PublicBlockChainAPI) GetLastCrossLinks() ([]*types.CrossLink, error) { + if s.b.GetShardID() == shard.BeaconChainShardID { + return s.b.GetLastCrossLinks() + } + return nil, errNotBeaconChainShard } diff --git a/internal/hmyapi/backend.go b/internal/hmyapi/backend.go index 742007c53..6d778e3da 100644 --- a/internal/hmyapi/backend.go +++ b/internal/hmyapi/backend.go @@ -89,7 +89,7 @@ type Backend interface { GetSuperCommittees() (*quorum.Transition, error) GetTotalStakingSnapshot() *big.Int GetCurrentBadBlocks() []core.BadBlock - GetLastCrossLinks() ([]*types.RPCCrossLink, error) + GetLastCrossLinks() ([]*types.CrossLink, error) } // GetAPIs returns all the APIs.