Merge pull request #601 from nspcc-dev/refactoring/core

core: refactor out Block, BlockBase and Header, closes #597.
This commit is contained in:
Roman Khimov 2020-01-20 16:19:20 +03:00 committed by GitHub
commit 32213b1454
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 327 additions and 232 deletions

View file

@ -7,6 +7,7 @@ import (
"github.com/CityOfZion/neo-go/config"
"github.com/CityOfZion/neo-go/pkg/core"
"github.com/CityOfZion/neo-go/pkg/core/block"
"github.com/CityOfZion/neo-go/pkg/core/storage"
"github.com/CityOfZion/neo-go/pkg/io"
"github.com/CityOfZion/neo-go/pkg/network"
@ -193,10 +194,10 @@ func initServerWithInMemoryChain(t *testing.T) (*core.Blockchain, http.HandlerFu
nBlocks = br.ReadU32LE()
require.Nil(t, br.Err)
for i := 0; i < int(nBlocks); i++ {
block := &core.Block{}
block.DecodeBinary(br)
b := &block.Block{}
b.DecodeBinary(br)
require.Nil(t, br.Err)
require.NoError(t, chain.AddBlock(block))
require.NoError(t, chain.AddBlock(b))
}
serverConfig := network.NewServerConfig(cfg)

View file

@ -2,14 +2,15 @@ package wrappers
import (
"github.com/CityOfZion/neo-go/pkg/core"
"github.com/CityOfZion/neo-go/pkg/core/block"
"github.com/CityOfZion/neo-go/pkg/util"
)
type (
// Block wrapper used for the representation of
// core.Block / core.BlockBase on the RPC Server.
// block.Block / block.Base on the RPC Server.
Block struct {
*core.Block
*block.Block
Confirmations uint32 `json:"confirmations"`
NextBlockHash util.Uint256 `json:"nextblockhash,omitempty"`
Hash util.Uint256 `json:"hash"`
@ -17,7 +18,7 @@ type (
)
// NewBlock creates a new Block wrapper.
func NewBlock(block *core.Block, chain core.Blockchainer) Block {
func NewBlock(block *block.Block, chain core.Blockchainer) Block {
blockWrapper := Block{
Block: block,
Hash: block.Hash(),

View file

@ -2,6 +2,7 @@ package wrappers
import (
"github.com/CityOfZion/neo-go/pkg/core"
"github.com/CityOfZion/neo-go/pkg/core/block"
"github.com/CityOfZion/neo-go/pkg/core/transaction"
"github.com/CityOfZion/neo-go/pkg/io"
"github.com/CityOfZion/neo-go/pkg/util"
@ -21,9 +22,9 @@ type TransactionOutputRaw struct {
}
// NewTransactionOutputRaw returns a new ransactionOutputRaw object.
func NewTransactionOutputRaw(tx *transaction.Transaction, header *core.Header, chain core.Blockchainer) TransactionOutputRaw {
func NewTransactionOutputRaw(tx *transaction.Transaction, header *block.Header, chain core.Blockchainer) TransactionOutputRaw {
// confirmations formula
confirmations := int(chain.BlockHeight() - header.BlockBase.Index + 1)
confirmations := int(chain.BlockHeight() - header.Base.Index + 1)
// set index position
for i, o := range tx.Outputs {
o.Position = i