diff --git a/statediff/builder.go b/statediff/builder/builder.go
similarity index 99%
rename from statediff/builder.go
rename to statediff/builder/builder.go
index da58b3bf4..30479a60c 100644
--- a/statediff/builder.go
+++ b/statediff/builder/builder.go
@@ -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"
diff --git a/statediff/builder/builder_suite_test.go b/statediff/builder/builder_suite_test.go
new file mode 100644
index 000000000..bbbf63078
--- /dev/null
+++ b/statediff/builder/builder_suite_test.go
@@ -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 .
+
+// 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")
+}
\ No newline at end of file
diff --git a/statediff/builder_test.go b/statediff/builder/builder_test.go
similarity index 99%
rename from statediff/builder_test.go
rename to statediff/builder/builder_test.go
index 64986af10..793a6347d 100644
--- a/statediff/builder_test.go
+++ b/statediff/builder/builder_test.go
@@ -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"
)
diff --git a/statediff/helpers.go b/statediff/builder/helpers.go
similarity index 99%
rename from statediff/helpers.go
rename to statediff/builder/helpers.go
index 8a0a6466e..31aae926b 100644
--- a/statediff/helpers.go
+++ b/statediff/builder/helpers.go
@@ -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"
diff --git a/statediff/struct.go b/statediff/builder/struct.go
similarity index 99%
rename from statediff/struct.go
rename to statediff/builder/struct.go
index 009af4c2e..7b48bba72 100644
--- a/statediff/struct.go
+++ b/statediff/builder/struct.go
@@ -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"
diff --git a/statediff/extractor.go b/statediff/extractor/extractor.go
similarity index 77%
rename from statediff/extractor.go
rename to statediff/extractor/extractor.go
index 9d9b1f080..d485f5e13 100644
--- a/statediff/extractor.go
+++ b/statediff/extractor/extractor.go
@@ -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
}
diff --git a/statediff/extractor/extractor_suite_test.go b/statediff/extractor/extractor_suite_test.go
new file mode 100644
index 000000000..fe7719032
--- /dev/null
+++ b/statediff/extractor/extractor_suite_test.go
@@ -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 .
+
+// 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")
+}
\ No newline at end of file
diff --git a/statediff/extractor_test.go b/statediff/extractor/extractor_test.go
similarity index 87%
rename from statediff/extractor_test.go
rename to statediff/extractor/extractor_test.go
index 9ccd250f6..d76329726 100644
--- a/statediff/extractor_test.go
+++ b/statediff/extractor/extractor_test.go
@@ -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))
diff --git a/statediff/ipfs/adder.go b/statediff/publisher/ipfs/adder.go
similarity index 96%
rename from statediff/ipfs/adder.go
rename to statediff/publisher/ipfs/adder.go
index 23eea1c1f..eb8e012c5 100644
--- a/statediff/ipfs/adder.go
+++ b/statediff/publisher/ipfs/adder.go
@@ -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 {
diff --git a/statediff/ipfs/dag_putter.go b/statediff/publisher/ipfs/dag_putter.go
similarity index 82%
rename from statediff/ipfs/dag_putter.go
rename to statediff/publisher/ipfs/dag_putter.go
index 4f99bdae3..2f2ff02e2 100644
--- a/statediff/ipfs/dag_putter.go
+++ b/statediff/publisher/ipfs/dag_putter.go
@@ -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)
diff --git a/statediff/ipfs/helpers.go b/statediff/publisher/ipfs/helpers.go
similarity index 94%
rename from statediff/ipfs/helpers.go
rename to statediff/publisher/ipfs/helpers.go
index a9904afa5..ea6ca5ab5 100644
--- a/statediff/ipfs/helpers.go
+++ b/statediff/publisher/ipfs/helpers.go
@@ -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
}
\ No newline at end of file
diff --git a/statediff/ipfs/node.go b/statediff/publisher/ipfs/node.go
similarity index 87%
rename from statediff/ipfs/node.go
rename to statediff/publisher/ipfs/node.go
index dd7447a80..1d8daa5e8 100644
--- a/statediff/ipfs/node.go
+++ b/statediff/publisher/ipfs/node.go
@@ -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 {
diff --git a/statediff/publisher.go b/statediff/publisher/publisher.go
similarity index 75%
rename from statediff/publisher.go
rename to statediff/publisher/publisher.go
index 48ad7cf64..404871405 100644
--- a/statediff/publisher.go
+++ b/statediff/publisher/publisher.go
@@ -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:
}
diff --git a/statediff/publisher/publisher_suite_test.go b/statediff/publisher/publisher_suite_test.go
new file mode 100644
index 000000000..29d10e2a1
--- /dev/null
+++ b/statediff/publisher/publisher_suite_test.go
@@ -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 .
+
+// 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")
+}
\ No newline at end of file
diff --git a/statediff/publisher/publisher_test.go b/statediff/publisher/publisher_test.go
new file mode 100644
index 000000000..520163ddc
--- /dev/null
+++ b/statediff/publisher/publisher_test.go
@@ -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 .
+
+// 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
\ No newline at end of file
diff --git a/statediff/service.go b/statediff/service.go
deleted file mode 100644
index 86839cf3b..000000000
--- a/statediff/service.go
+++ /dev/null
@@ -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
-}
diff --git a/statediff/service/service.go b/statediff/service/service.go
new file mode 100644
index 000000000..b3da7532d
--- /dev/null
+++ b/statediff/service/service.go
@@ -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 .
+
+// 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
+}
diff --git a/statediff/service/service_suite_test.go b/statediff/service/service_suite_test.go
new file mode 100644
index 000000000..60212a8fd
--- /dev/null
+++ b/statediff/service/service_suite_test.go
@@ -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 .
+
+// 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")
+}
\ No newline at end of file
diff --git a/statediff/service/service_test.go b/statediff/service/service_test.go
new file mode 100644
index 000000000..99e6cfd63
--- /dev/null
+++ b/statediff/service/service_test.go
@@ -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 .
+
+// 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
\ No newline at end of file
diff --git a/statediff/publisher_test.go b/statediff/statediff_integration_test.go
similarity index 100%
rename from statediff/publisher_test.go
rename to statediff/statediff_integration_test.go
diff --git a/statediff/statediff_suite_test.go b/statediff/statediff_suite_test.go
index 7118ea792..99834db48 100644
--- a/statediff/statediff_suite_test.go
+++ b/statediff/statediff_suite_test.go
@@ -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 .
+
+// 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")
}
diff --git a/statediff/testhelpers/mocks.go b/statediff/testhelpers/mocks.go
index 4bff3c028..b4608e455 100644
--- a/statediff/testhelpers/mocks.go
+++ b/statediff/testhelpers/mocks.go
@@ -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 .
+
+// 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
}