Write state diff to CSV #2

Merged
elizabethengelman merged 47 commits from ee-state-diff into statediff-for-archive-node 2019-01-28 21:31:02 +00:00
Showing only changes of commit 71147861f7 - Show all commits

View File

@ -1,11 +1,12 @@
package statediff package statediff
import ( import (
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"fmt" "github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/event"
"log"
) )
type StateDiffService struct { type StateDiffService struct {
@ -32,23 +33,32 @@ func (StateDiffService) APIs() []rpc.API {
return []rpc.API{} return []rpc.API{}
} }
func (sds *StateDiffService) Start(server *p2p.Server) error { func (sds *StateDiffService) loop (sub event.Subscription, events chan core.ChainHeadEvent) {
fmt.Println("starting the state diff service") defer sub.Unsubscribe()
blockChannel := make(chan core.ChainHeadEvent)
sds.blockchain.SubscribeChainHeadEvent(blockChannel)
for { for {
select { select {
case <-blockChannel: case ev, ok := <-events:
headOfChainEvent := <-blockChannel if !ok {
previousBlock := headOfChainEvent.Block 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 //TODO: figure out the best way to get the previous block
currentBlock := headOfChainEvent.Block currentBlock := ev.Block
sds.extractor.ExtractStateDiff(*previousBlock, *currentBlock) 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 return nil
} }
func (StateDiffService) Stop() error { func (StateDiffService) Stop() error {
fmt.Println("stopping the state diff service")
return nil return nil
} }