Write state diff to CSV #2
@ -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
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user