forked from TrueCloudLab/neoneo-go
core: move Blockchainer interface to a separate package
This commit is contained in:
parent
efddcf3bfe
commit
a7c19d445b
12 changed files with 27 additions and 21 deletions
|
@ -12,6 +12,7 @@ import (
|
||||||
"github.com/nspcc-dev/dbft/payload"
|
"github.com/nspcc-dev/dbft/payload"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core"
|
"github.com/nspcc-dev/neo-go/pkg/core"
|
||||||
coreb "github.com/nspcc-dev/neo-go/pkg/core/block"
|
coreb "github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/mempool"
|
"github.com/nspcc-dev/neo-go/pkg/core/mempool"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
@ -77,7 +78,7 @@ type Config struct {
|
||||||
// about the new block that needs to be broadcasted.
|
// about the new block that needs to be broadcasted.
|
||||||
RelayBlock func(b *coreb.Block)
|
RelayBlock func(b *coreb.Block)
|
||||||
// Chain is a core.Blockchainer instance.
|
// Chain is a core.Blockchainer instance.
|
||||||
Chain core.Blockchainer
|
Chain blockchainer.Blockchainer
|
||||||
// RequestTx is a callback to which will be called
|
// RequestTx is a callback to which will be called
|
||||||
// when a node lacks transactions present in a block.
|
// when a node lacks transactions present in a block.
|
||||||
RequestTx func(h ...util.Uint256)
|
RequestTx func(h ...util.Uint256)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package core
|
package blockchainer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config"
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
|
@ -32,7 +33,7 @@ type StorageContext struct {
|
||||||
// getBlockHashFromElement converts given vm.Element to block hash using given
|
// getBlockHashFromElement converts given vm.Element to block hash using given
|
||||||
// Blockchainer if needed. Interop functions accept both block numbers and
|
// Blockchainer if needed. Interop functions accept both block numbers and
|
||||||
// block hashes as parameters, thus this function is needed.
|
// block hashes as parameters, thus this function is needed.
|
||||||
func getBlockHashFromElement(bc Blockchainer, element *vm.Element) (util.Uint256, error) {
|
func getBlockHashFromElement(bc blockchainer.Blockchainer, element *vm.Element) (util.Uint256, error) {
|
||||||
var hash util.Uint256
|
var hash util.Uint256
|
||||||
hashbytes := element.Bytes()
|
hashbytes := element.Bytes()
|
||||||
if len(hashbytes) <= 5 {
|
if len(hashbytes) <= 5 {
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
|
@ -22,7 +23,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type interopContext struct {
|
type interopContext struct {
|
||||||
bc Blockchainer
|
bc blockchainer.Blockchainer
|
||||||
trigger trigger.Type
|
trigger trigger.Type
|
||||||
block *block.Block
|
block *block.Block
|
||||||
tx *transaction.Transaction
|
tx *transaction.Transaction
|
||||||
|
@ -31,7 +32,7 @@ type interopContext struct {
|
||||||
log *zap.Logger
|
log *zap.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func newInteropContext(trigger trigger.Type, bc Blockchainer, d dao.DAO, block *block.Block, tx *transaction.Transaction, log *zap.Logger) *interopContext {
|
func newInteropContext(trigger trigger.Type, bc blockchainer.Blockchainer, d dao.DAO, block *block.Block, tx *transaction.Transaction, log *zap.Logger) *interopContext {
|
||||||
dao := dao.NewCached(d)
|
dao := dao.NewCached(d)
|
||||||
nes := make([]state.NotificationEvent, 0)
|
nes := make([]state.NotificationEvent, 0)
|
||||||
return &interopContext{bc, trigger, block, tx, dao, nes, log}
|
return &interopContext{bc, trigger, block, tx, dao, nes, log}
|
||||||
|
|
|
@ -2,8 +2,8 @@ package network
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Workiva/go-datastructures/queue"
|
"github.com/Workiva/go-datastructures/queue"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,11 +11,11 @@ type blockQueue struct {
|
||||||
log *zap.Logger
|
log *zap.Logger
|
||||||
queue *queue.PriorityQueue
|
queue *queue.PriorityQueue
|
||||||
checkBlocks chan struct{}
|
checkBlocks chan struct{}
|
||||||
chain core.Blockchainer
|
chain blockchainer.Blockchainer
|
||||||
relayF func(*block.Block)
|
relayF func(*block.Block)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newBlockQueue(capacity int, bc core.Blockchainer, log *zap.Logger, relayer func(*block.Block)) *blockQueue {
|
func newBlockQueue(capacity int, bc blockchainer.Blockchainer, log *zap.Logger, relayer func(*block.Block)) *blockQueue {
|
||||||
if log == nil {
|
if log == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/consensus"
|
"github.com/nspcc-dev/neo-go/pkg/consensus"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core"
|
"github.com/nspcc-dev/neo-go/pkg/core"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
@ -53,7 +54,7 @@ type (
|
||||||
|
|
||||||
transport Transporter
|
transport Transporter
|
||||||
discovery Discoverer
|
discovery Discoverer
|
||||||
chain core.Blockchainer
|
chain blockchainer.Blockchainer
|
||||||
bQueue *blockQueue
|
bQueue *blockQueue
|
||||||
consensus consensus.Service
|
consensus consensus.Service
|
||||||
|
|
||||||
|
@ -84,7 +85,7 @@ func randomID() uint32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServer returns a new Server, initialized with the given configuration.
|
// NewServer returns a new Server, initialized with the given configuration.
|
||||||
func NewServer(config ServerConfig, chain core.Blockchainer, log *zap.Logger) (*Server, error) {
|
func NewServer(config ServerConfig, chain blockchainer.Blockchainer, log *zap.Logger) (*Server, error) {
|
||||||
if log == nil {
|
if log == nil {
|
||||||
return nil, errors.New("logger is a required parameter")
|
return nil, errors.New("logger is a required parameter")
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
@ -50,7 +50,7 @@ type (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewBlock creates a new Block wrapper.
|
// NewBlock creates a new Block wrapper.
|
||||||
func NewBlock(b *block.Block, chain core.Blockchainer) Block {
|
func NewBlock(b *block.Block, chain blockchainer.Blockchainer) Block {
|
||||||
res := Block{
|
res := Block{
|
||||||
Version: b.Version,
|
Version: b.Version,
|
||||||
Hash: b.Hash(),
|
Hash: b.Hash(),
|
||||||
|
|
|
@ -3,8 +3,8 @@ package result
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
@ -31,7 +31,7 @@ type (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewHeader creates a new Header wrapper.
|
// NewHeader creates a new Header wrapper.
|
||||||
func NewHeader(h *block.Header, chain core.Blockchainer) Header {
|
func NewHeader(h *block.Header, chain blockchainer.Blockchainer) Header {
|
||||||
res := Header{
|
res := Header{
|
||||||
Hash: h.Hash(),
|
Hash: h.Hash(),
|
||||||
Size: io.GetVarSize(h),
|
Size: io.GetVarSize(h),
|
||||||
|
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
)
|
)
|
||||||
|
@ -27,7 +27,7 @@ type TransactionMetadata struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTransactionOutputRaw returns a new ransactionOutputRaw object.
|
// NewTransactionOutputRaw returns a new ransactionOutputRaw object.
|
||||||
func NewTransactionOutputRaw(tx *transaction.Transaction, header *block.Header, chain core.Blockchainer) TransactionOutputRaw {
|
func NewTransactionOutputRaw(tx *transaction.Transaction, header *block.Header, chain blockchainer.Blockchainer) TransactionOutputRaw {
|
||||||
// confirmations formula
|
// confirmations formula
|
||||||
confirmations := int(chain.BlockHeight() - header.Base.Index + 1)
|
confirmations := int(chain.BlockHeight() - header.Base.Index + 1)
|
||||||
// set index position
|
// set index position
|
||||||
|
|
|
@ -2,6 +2,7 @@ package result
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core"
|
"github.com/nspcc-dev/neo-go/pkg/core"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
)
|
)
|
||||||
|
@ -14,7 +15,7 @@ type Unclaimed struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewUnclaimed creates a new Unclaimed wrapper using given Blockchainer.
|
// NewUnclaimed creates a new Unclaimed wrapper using given Blockchainer.
|
||||||
func NewUnclaimed(a *state.Account, chain core.Blockchainer) (*Unclaimed, error) {
|
func NewUnclaimed(a *state.Account, chain blockchainer.Blockchainer) (*Unclaimed, error) {
|
||||||
var (
|
var (
|
||||||
available util.Fixed8
|
available util.Fixed8
|
||||||
unavailable util.Fixed8
|
unavailable util.Fixed8
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package result
|
package result
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core"
|
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
)
|
)
|
||||||
|
@ -29,7 +29,7 @@ var GlobalAssets = map[string]string{
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewUnspents creates a new Account wrapper using given Blockchainer.
|
// NewUnspents creates a new Account wrapper using given Blockchainer.
|
||||||
func NewUnspents(a *state.Account, chain core.Blockchainer, addr string) Unspents {
|
func NewUnspents(a *state.Account, chain blockchainer.Blockchainer, addr string) Unspents {
|
||||||
res := Unspents{
|
res := Unspents{
|
||||||
Address: addr,
|
Address: addr,
|
||||||
Balance: make([]UnspentBalanceInfo, 0, len(a.Balances)),
|
Balance: make([]UnspentBalanceInfo, 0, len(a.Balances)),
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc"
|
"github.com/nspcc-dev/neo-go/pkg/rpc"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core"
|
"github.com/nspcc-dev/neo-go/pkg/core"
|
||||||
|
@ -35,7 +36,7 @@ type (
|
||||||
// Server represents the JSON-RPC 2.0 server.
|
// Server represents the JSON-RPC 2.0 server.
|
||||||
Server struct {
|
Server struct {
|
||||||
*http.Server
|
*http.Server
|
||||||
chain core.Blockchainer
|
chain blockchainer.Blockchainer
|
||||||
config rpc.Config
|
config rpc.Config
|
||||||
coreServer *network.Server
|
coreServer *network.Server
|
||||||
log *zap.Logger
|
log *zap.Logger
|
||||||
|
@ -81,7 +82,7 @@ var invalidBlockHeightError = func(index int, height int) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new Server struct.
|
// New creates a new Server struct.
|
||||||
func New(chain core.Blockchainer, conf rpc.Config, coreServer *network.Server, log *zap.Logger) Server {
|
func New(chain blockchainer.Blockchainer, conf rpc.Config, coreServer *network.Server, log *zap.Logger) Server {
|
||||||
httpServer := &http.Server{
|
httpServer := &http.Server{
|
||||||
Addr: conf.Address + ":" + strconv.FormatUint(uint64(conf.Port), 10),
|
Addr: conf.Address + ":" + strconv.FormatUint(uint64(conf.Port), 10),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue