reorganize to fix unallowed import cycles between statediff and statediff/ipfs

This commit is contained in:
Ian Norden 2018-12-12 11:54:51 -06:00
parent 097a9071cc
commit c1e3af0093
22 changed files with 369 additions and 129 deletions

View File

@ -17,7 +17,7 @@
// Contains a batch of utility type declarations used by the tests. As the node
// operates on unique types, a lot of them are needed to check various features.
package statediff
package builder
import (
"github.com/ethereum/go-ethereum/common"

View File

@ -0,0 +1,32 @@
// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Contains a batch of utility type declarations used by the tests. As the node
// operates on unique types, a lot of them are needed to check various features.
package builder_test
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func TestStateDiffBuilder(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "StateDiff Builder Suite")
}

View File

@ -17,20 +17,22 @@
// Contains a batch of utility type declarations used by the tests. As the node
// operates on unique types, a lot of them are needed to check various features.
package statediff_test
package builder_test
import (
"math/big"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/ethash"
"math/big"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/statediff"
"github.com/onsi/gomega"
statediff "github.com/ethereum/go-ethereum/statediff/builder"
)

View File

@ -17,7 +17,7 @@
// Contains a batch of utility type declarations used by the tests. As the node
// operates on unique types, a lot of them are needed to check various features.
package statediff
package builder
import (
"sort"

View File

@ -17,7 +17,7 @@
// Contains a batch of utility type declarations used by the tests. As the node
// operates on unique types, a lot of them are needed to check various features.
package statediff
package builder
import (
"encoding/json"

View File

@ -17,10 +17,12 @@
// Contains a batch of utility type declarations used by the tests. As the node
// operates on unique types, a lot of them are needed to check various features.
package statediff
package extractor
import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/statediff/builder"
"github.com/ethereum/go-ethereum/statediff/publisher"
)
type Extractor interface {
@ -28,14 +30,14 @@ type Extractor interface {
}
type extractor struct {
Builder Builder // Interface for building state diff objects from two blocks
Publisher Publisher // Interface for publishing state diff objects to a datastore (e.g. IPFS)
Builder builder.Builder // Interface for building state diff objects from two blocks
Publisher publisher.Publisher // Interface for publishing state diff objects to a datastore (e.g. IPFS)
}
func NewExtractor(builder Builder, publisher Publisher) (*extractor, error) {
func NewExtractor(b builder.Builder, p publisher.Publisher) (*extractor, error) {
return &extractor{
Builder: builder,
Publisher: publisher,
Builder: b,
Publisher: p,
}, nil
}

View File

@ -0,0 +1,32 @@
// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Contains a batch of utility type declarations used by the tests. As the node
// operates on unique types, a lot of them are needed to check various features.
package extractor_test
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func TestStateDiffExtractor(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "StateDiff Extractor Suite")
}

View File

@ -17,16 +17,19 @@
// Contains a batch of utility type declarations used by the tests. As the node
// operates on unique types, a lot of them are needed to check various features.
package statediff_test
package extractor_test
import (
"github.com/onsi/ginkgo"
"github.com/ethereum/go-ethereum/statediff"
"github.com/onsi/gomega"
"github.com/ethereum/go-ethereum/core/types"
"math/rand"
"github.com/ethereum/go-ethereum/statediff/testhelpers"
"math/big"
"math/rand"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
"github.com/ethereum/go-ethereum/statediff/extractor"
statediff "github.com/ethereum/go-ethereum/statediff/builder"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/statediff/testhelpers"
)
var _ = ginkgo.Describe("Extractor", func() {
var publisher testhelpers.MockPublisher
@ -34,13 +37,13 @@ var _ = ginkgo.Describe("Extractor", func() {
var currentBlockNumber *big.Int
var parentBlock, currentBlock *types.Block
var expectedStateDiff statediff.StateDiff
var extractor statediff.Extractor
var ex extractor.Extractor
var err error
ginkgo.BeforeEach(func() {
publisher = testhelpers.MockPublisher{}
builder = testhelpers.MockBuilder{}
extractor, err = statediff.NewExtractor(&builder, &publisher)
ex, err = extractor.NewExtractor(&builder, &publisher)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
blockNumber := rand.Int63()
@ -61,7 +64,7 @@ var _ = ginkgo.Describe("Extractor", func() {
ginkgo.It("builds a state diff struct", func() {
builder.SetStateDiffToBuild(&expectedStateDiff)
_, err = extractor.ExtractStateDiff(*parentBlock, *currentBlock)
_, err = ex.ExtractStateDiff(*parentBlock, *currentBlock)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(builder.OldStateRoot).To(gomega.Equal(parentBlock.Root()))
@ -73,7 +76,7 @@ var _ = ginkgo.Describe("Extractor", func() {
ginkgo.It("returns an error if building the state diff fails", func() {
builder.SetBuilderError(testhelpers.MockError)
_, err = extractor.ExtractStateDiff(*parentBlock, *currentBlock)
_, err = ex.ExtractStateDiff(*parentBlock, *currentBlock)
gomega.Expect(err).To(gomega.HaveOccurred())
gomega.Expect(err).To(gomega.MatchError(testhelpers.MockError))
@ -82,7 +85,7 @@ var _ = ginkgo.Describe("Extractor", func() {
ginkgo.It("publishes the state diff struct", func() {
builder.SetStateDiffToBuild(&expectedStateDiff)
_, err = extractor.ExtractStateDiff(*parentBlock, *currentBlock)
_, err = ex.ExtractStateDiff(*parentBlock, *currentBlock)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(publisher.StateDiff).To(gomega.Equal(&expectedStateDiff))
@ -91,7 +94,7 @@ var _ = ginkgo.Describe("Extractor", func() {
ginkgo.It("returns an error if publishing the diff fails", func() {
publisher.SetPublisherError(testhelpers.MockError)
_, err = extractor.ExtractStateDiff(*parentBlock, *currentBlock)
_, err = ex.ExtractStateDiff(*parentBlock, *currentBlock)
gomega.Expect(err).To(gomega.HaveOccurred())
gomega.Expect(err).To(gomega.MatchError(testhelpers.MockError))

View File

@ -24,7 +24,7 @@ import (
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/repo/fsrepo"
ipld "gx/ipfs/QmWi2BYBL5gJ3CiAiQchg6rn1A8iBsrWy51EYxvHVjFvLb/go-ipld-format"
ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
)
type Adder interface {

View File

@ -23,9 +23,9 @@ import (
"bytes"
"encoding/gob"
ipld "gx/ipfs/QmWi2BYBL5gJ3CiAiQchg6rn1A8iBsrWy51EYxvHVjFvLb/go-ipld-format"
"github.com/ethereum/go-ethereum/statediff"
"github.com/ethereum/go-ethereum/common"
ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
"github.com/ethereum/go-ethereum/statediff/builder"
)
const (
@ -33,7 +33,7 @@ const (
)
type DagPutter interface {
DagPut(sd *statediff.StateDiff) (string, error)
DagPut(sd *builder.StateDiff) (string, error)
}
type dagPutter struct {
@ -44,7 +44,7 @@ func NewDagPutter(adder Adder) *dagPutter {
return &dagPutter{Adder: adder}
}
func (bhdp *dagPutter) DagPut(sd *statediff.StateDiff) (string, error) {
func (bhdp *dagPutter) DagPut(sd *builder.StateDiff) (string, error) {
nd, err := bhdp.getNode(sd)
if err != nil {
return "", err
@ -56,7 +56,7 @@ func (bhdp *dagPutter) DagPut(sd *statediff.StateDiff) (string, error) {
return nd.Cid().String(), nil
}
func (bhdp *dagPutter) getNode(sd *statediff.StateDiff) (ipld.Node, error) {
func (bhdp *dagPutter) getNode(sd *builder.StateDiff) (ipld.Node, error) {
var buff bytes.Buffer
enc := gob.NewEncoder(&buff)

View File

@ -21,7 +21,7 @@ package ipfs
import (
mh "gx/ipfs/QmZyZDi491cCNTLfAhwcaDii2Kg4pwKRkhqQzURGDvY6ua/go-multihash"
"gx/ipfs/QmapdYm1b22Frv3k17fqrBYTFRxwiaVJkB299Mfn33edeB/go-cid"
"gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
)
func RawToCid(codec uint64, raw []byte) (*cid.Cid, error) {
@ -34,5 +34,5 @@ func RawToCid(codec uint64, raw []byte) (*cid.Cid, error) {
if err != nil {
return nil, err
}
return c, nil
return &c, nil
}

View File

@ -20,14 +20,14 @@
package ipfs
import (
ipld "gx/ipfs/QmWi2BYBL5gJ3CiAiQchg6rn1A8iBsrWy51EYxvHVjFvLb/go-ipld-format"
"gx/ipfs/QmapdYm1b22Frv3k17fqrBYTFRxwiaVJkB299Mfn33edeB/go-cid"
"gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
"github.com/i-norden/go-ethereum/statediff"
"github.com/ethereum/go-ethereum/statediff/builder"
)
type StateDiffNode struct {
*statediff.StateDiff
*builder.StateDiff
cid *cid.Cid
rawdata []byte
@ -37,8 +37,8 @@ func (sdn *StateDiffNode) RawData() []byte {
return sdn.rawdata
}
func (sdn *StateDiffNode) Cid() *cid.Cid {
return sdn.cid
func (sdn *StateDiffNode) Cid() cid.Cid {
return *sdn.cid
}
func (sdn StateDiffNode) String() string {

View File

@ -17,23 +17,26 @@
// Contains a batch of utility type declarations used by the tests. As the node
// operates on unique types, a lot of them are needed to check various features.
package statediff
package publisher
import (
"errors"
"github.com/ethereum/go-ethereum/statediff/ipfs"
"github.com/ethereum/go-ethereum/statediff"
"github.com/ethereum/go-ethereum/statediff/builder"
"github.com/ethereum/go-ethereum/statediff/publisher/ipfs"
)
type Publisher interface {
PublishStateDiff(sd *StateDiff) (string, error)
PublishStateDiff(sd *builder.StateDiff) (string, error)
}
type publisher struct {
ipfs.DagPutter
Config
statediff.Config
}
func NewPublisher(config Config) (*publisher, error) {
func NewPublisher(config statediff.Config) (*publisher, error) {
adder, err := ipfs.NewAdder(config.Path)
if err != nil {
return nil, err
@ -45,17 +48,17 @@ func NewPublisher(config Config) (*publisher, error) {
}, nil
}
func (p *publisher) PublishStateDiff(sd *StateDiff) (string, error) {
func (p *publisher) PublishStateDiff(sd *builder.StateDiff) (string, error) {
switch p.Mode {
case IPLD:
case statediff.IPLD:
cidStr, err := p.DagPut(sd)
if err != nil {
return "", err
}
return cidStr, err
case LDB:
case SQL:
case statediff.LDB:
case statediff.SQL:
default:
}

View File

@ -0,0 +1,32 @@
// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Contains a batch of utility type declarations used by the tests. As the node
// operates on unique types, a lot of them are needed to check various features.
package publisher_test
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func TestStateDiffPublisher(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "StateDiff Publisher Suite")
}

View File

@ -0,0 +1,20 @@
// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Contains a batch of utility type declarations used by the tests. As the node
// operates on unique types, a lot of them are needed to check various features.
package publisher_test

View File

@ -1,70 +0,0 @@
package statediff
import (
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/event"
"log"
)
type StateDiffService struct {
builder *builder
extractor *extractor
blockchain *core.BlockChain
}
func NewStateDiffService(db ethdb.Database, blockChain *core.BlockChain) (*StateDiffService, error) {
config := Config{}
builder := NewBuilder(db)
publisher, err := NewPublisher(config)
if err != nil {
return nil, nil
}
extractor, _ := NewExtractor(builder, publisher)
return &StateDiffService{
blockchain: blockChain,
extractor: extractor,
}, nil
}
func (StateDiffService) Protocols() []p2p.Protocol {
return []p2p.Protocol{}
}
func (StateDiffService) APIs() []rpc.API {
return []rpc.API{}
}
func (sds *StateDiffService) loop (sub event.Subscription, events chan core.ChainHeadEvent) {
defer sub.Unsubscribe()
for {
select {
case ev, ok := <-events:
if !ok {
log.Fatalf("Error getting chain head event from subscription.")
}
log.Println("doing something with an event", ev)
previousBlock := ev.Block
//TODO: figure out the best way to get the previous block
currentBlock := ev.Block
sds.extractor.ExtractStateDiff(*previousBlock, *currentBlock)
}
}
}
func (sds *StateDiffService) Start(server *p2p.Server) error {
events := make(chan core.ChainHeadEvent, 10)
sub := sds.blockchain.SubscribeChainHeadEvent(events)
go sds.loop(sub, events)
return nil
}
func (StateDiffService) Stop() error {
return nil
}

View File

@ -0,0 +1,94 @@
// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Contains a batch of utility type declarations used by the tests. As the node
// operates on unique types, a lot of them are needed to check various features.
package service
import (
"log"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/statediff"
"github.com/ethereum/go-ethereum/statediff/builder"
"github.com/ethereum/go-ethereum/statediff/extractor"
"github.com/ethereum/go-ethereum/statediff/publisher"
)
type StateDiffService struct {
builder builder.Builder
extractor extractor.Extractor
blockchain *core.BlockChain
}
func NewStateDiffService(db ethdb.Database, blockChain *core.BlockChain) (*StateDiffService, error) {
config := statediff.Config{}
b := builder.NewBuilder(db)
p, err := publisher.NewPublisher(config)
if err != nil {
return nil, nil
}
e, _ := extractor.NewExtractor(b, p)
return &StateDiffService{
blockchain: blockChain,
extractor: e,
}, nil
}
func (StateDiffService) Protocols() []p2p.Protocol {
return []p2p.Protocol{}
}
func (StateDiffService) APIs() []rpc.API {
return []rpc.API{}
}
func (sds *StateDiffService) loop (sub event.Subscription, events chan core.ChainHeadEvent) {
defer sub.Unsubscribe()
for {
select {
case ev, ok := <-events:
if !ok {
log.Fatalf("Error getting chain head event from subscription.")
}
log.Println("doing something with an event", ev)
previousBlock := ev.Block
//TODO: figure out the best way to get the previous block
currentBlock := ev.Block
sds.extractor.ExtractStateDiff(*previousBlock, *currentBlock)
}
}
}
func (sds *StateDiffService) Start(server *p2p.Server) error {
events := make(chan core.ChainHeadEvent, 10)
sub := sds.blockchain.SubscribeChainHeadEvent(events)
go sds.loop(sub, events)
return nil
}
func (StateDiffService) Stop() error {
return nil
}

View File

@ -0,0 +1,32 @@
// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Contains a batch of utility type declarations used by the tests. As the node
// operates on unique types, a lot of them are needed to check various features.
package service_test
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func TestStateDiffService(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "StateDiff Service Suite")
}

View File

@ -0,0 +1,20 @@
// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Contains a batch of utility type declarations used by the tests. As the node
// operates on unique types, a lot of them are needed to check various features.
package service_test

View File

@ -1,3 +1,22 @@
// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Contains a batch of utility type declarations used by the tests. As the node
// operates on unique types, a lot of them are needed to check various features.
package statediff_test
import (
@ -7,7 +26,7 @@ import (
. "github.com/onsi/gomega"
)
func TestStatediff(t *testing.T) {
func TestStateDiff(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Statediff Suite")
RunSpecs(t, "StateDiff Suite")
}

View File

@ -1,9 +1,28 @@
// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Contains a batch of utility type declarations used by the tests. As the node
// operates on unique types, a lot of them are needed to check various features.
package testhelpers
import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/statediff"
"errors"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/statediff/builder"
)
var MockError = errors.New("mock error")
@ -13,11 +32,11 @@ type MockBuilder struct {
NewStateRoot common.Hash
BlockNumber int64
BlockHash common.Hash
stateDiff *statediff.StateDiff
stateDiff *builder.StateDiff
builderError error
}
func (builder *MockBuilder) BuildStateDiff(oldStateRoot, newStateRoot common.Hash, blockNumber int64, blockHash common.Hash) (*statediff.StateDiff, error) {
func (builder *MockBuilder) BuildStateDiff(oldStateRoot, newStateRoot common.Hash, blockNumber int64, blockHash common.Hash) (*builder.StateDiff, error) {
builder.OldStateRoot = oldStateRoot
builder.NewStateRoot = newStateRoot
builder.BlockNumber = blockNumber
@ -26,7 +45,7 @@ func (builder *MockBuilder) BuildStateDiff(oldStateRoot, newStateRoot common.Has
return builder.stateDiff, builder.builderError
}
func (builder *MockBuilder) SetStateDiffToBuild(stateDiff *statediff.StateDiff) {
func (builder *MockBuilder) SetStateDiffToBuild(stateDiff *builder.StateDiff) {
builder.stateDiff = stateDiff
}
@ -35,11 +54,11 @@ func (builder *MockBuilder) SetBuilderError(err error) {
}
type MockPublisher struct{
StateDiff *statediff.StateDiff
StateDiff *builder.StateDiff
publisherError error
}
func (publisher *MockPublisher) PublishStateDiff(sd *statediff.StateDiff) (string, error) {
func (publisher *MockPublisher) PublishStateDiff(sd *builder.StateDiff) (string, error) {
publisher.StateDiff = sd
return "", publisher.publisherError
}