result: drop NewBlock/NewHeader/LedgerAux

Client's don't care about any of these.
This commit is contained in:
Roman Khimov 2022-07-08 14:50:00 +03:00
parent 04fc737e2e
commit 4333ad4949
3 changed files with 23 additions and 45 deletions

View file

@ -5,16 +5,10 @@ import (
"errors"
"github.com/nspcc-dev/neo-go/pkg/core/block"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/util"
)
type (
// LedgerAux is a set of methods needed to construct some outputs.
LedgerAux interface {
BlockHeight() uint32
GetHeaderHash(int) util.Uint256
}
// Block wrapper used for the representation of
// block.Block / block.Base on the RPC Server.
Block struct {
@ -31,24 +25,6 @@ type (
}
)
// NewBlock creates a new Block wrapper.
func NewBlock(b *block.Block, chain LedgerAux) Block {
res := Block{
Block: *b,
BlockMetadata: BlockMetadata{
Size: io.GetVarSize(b),
Confirmations: chain.BlockHeight() - b.Index + 1,
},
}
hash := chain.GetHeaderHash(int(b.Index) + 1)
if !hash.Equals(util.Uint256{}) {
res.NextBlockHash = &hash
}
return res
}
// MarshalJSON implements the json.Marshaler interface.
func (b Block) MarshalJSON() ([]byte, error) {
output, err := json.Marshal(b.BlockMetadata)

View file

@ -5,8 +5,6 @@ import (
"errors"
"github.com/nspcc-dev/neo-go/pkg/core/block"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/util"
)
type (
@ -18,23 +16,6 @@ type (
}
)
// NewHeader creates a new Header wrapper.
func NewHeader(h *block.Header, chain LedgerAux) Header {
res := Header{
Header: *h,
BlockMetadata: BlockMetadata{
Size: io.GetVarSize(h),
Confirmations: chain.BlockHeight() - h.Index + 1,
},
}
hash := chain.GetHeaderHash(int(h.Index) + 1)
if !hash.Equals(util.Uint256{}) {
res.NextBlockHash = &hash
}
return res
}
// MarshalJSON implements the json.Marshaler interface.
func (h Header) MarshalJSON() ([]byte, error) {
output, err := json.Marshal(h.BlockMetadata)

View file

@ -582,6 +582,19 @@ func (s *Server) blockHashFromParam(param *params.Param) (util.Uint256, *respons
return hash, nil
}
func (s *Server) fillBlockMetadata(obj io.Serializable, h *block.Header) result.BlockMetadata {
res := result.BlockMetadata{
Size: io.GetVarSize(obj), // obj can be a Block or a Header.
Confirmations: s.chain.BlockHeight() - h.Index + 1,
}
hash := s.chain.GetHeaderHash(int(h.Index) + 1)
if !hash.Equals(util.Uint256{}) {
res.NextBlockHash = &hash
}
return res
}
func (s *Server) getBlock(reqParams params.Params) (interface{}, *response.Error) {
param := reqParams.Value(0)
hash, respErr := s.blockHashFromParam(param)
@ -595,7 +608,11 @@ func (s *Server) getBlock(reqParams params.Params) (interface{}, *response.Error
}
if v, _ := reqParams.Value(1).GetBoolean(); v {
return result.NewBlock(block, s.chain), nil
res := result.Block{
Block: *block,
BlockMetadata: s.fillBlockMetadata(block, &block.Header),
}
return res, nil
}
writer := io.NewBufBinWriter()
block.EncodeBinary(writer.BinWriter)
@ -1639,7 +1656,11 @@ func (s *Server) getBlockHeader(reqParams params.Params) (interface{}, *response
}
if verbose {
return result.NewHeader(h, s.chain), nil
res := result.Header{
Header: *h,
BlockMetadata: s.fillBlockMetadata(h, h),
}
return res, nil
}
buf := io.NewBufBinWriter()