forked from cerc-io/plugeth
State dumps
This commit is contained in:
parent
3c319f93f2
commit
852d1ee395
@ -3,10 +3,11 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/ethereum/eth-go/ethlog"
|
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
|
"github.com/ethereum/eth-go/ethlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Identifier string
|
var Identifier string
|
||||||
@ -31,6 +32,9 @@ var LogFile string
|
|||||||
var ConfigFile string
|
var ConfigFile string
|
||||||
var DebugFile string
|
var DebugFile string
|
||||||
var LogLevel int
|
var LogLevel int
|
||||||
|
var Dump bool
|
||||||
|
var DumpHash string
|
||||||
|
var DumpNumber int
|
||||||
|
|
||||||
// flags specific to cli client
|
// flags specific to cli client
|
||||||
var StartMining bool
|
var StartMining bool
|
||||||
@ -71,6 +75,10 @@ func Init() {
|
|||||||
flag.BoolVar(&DiffTool, "difftool", false, "creates output for diff'ing. Sets LogLevel=0")
|
flag.BoolVar(&DiffTool, "difftool", false, "creates output for diff'ing. Sets LogLevel=0")
|
||||||
flag.StringVar(&DiffType, "diff", "all", "sets the level of diff output [vm, all]. Has no effect if difftool=false")
|
flag.StringVar(&DiffType, "diff", "all", "sets the level of diff output [vm, all]. Has no effect if difftool=false")
|
||||||
|
|
||||||
|
flag.BoolVar(&Dump, "dump", false, "output the ethereum state in JSON format. Sub args [number, hash]")
|
||||||
|
flag.StringVar(&DumpHash, "hash", "", "specify arg in hex")
|
||||||
|
flag.IntVar(&DumpNumber, "number", -1, "specify arg in number")
|
||||||
|
|
||||||
flag.BoolVar(&StartMining, "mine", false, "start dagger mining")
|
flag.BoolVar(&StartMining, "mine", false, "start dagger mining")
|
||||||
flag.BoolVar(&StartJsConsole, "js", false, "launches javascript console")
|
flag.BoolVar(&StartJsConsole, "js", false, "launches javascript console")
|
||||||
|
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
"github.com/ethereum/eth-go/ethchain"
|
||||||
"github.com/ethereum/eth-go/ethlog"
|
"github.com/ethereum/eth-go/ethlog"
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
"github.com/ethereum/go-ethereum/utils"
|
"github.com/ethereum/go-ethereum/utils"
|
||||||
@ -24,7 +27,7 @@ func main() {
|
|||||||
Init() // parsing command line
|
Init() // parsing command line
|
||||||
|
|
||||||
// If the difftool option is selected ignore all other log output
|
// If the difftool option is selected ignore all other log output
|
||||||
if DiffTool {
|
if DiffTool || Dump {
|
||||||
LogLevel = 0
|
LogLevel = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,6 +50,32 @@ func main() {
|
|||||||
|
|
||||||
ethereum := utils.NewEthereum(db, clientIdentity, keyManager, UseUPnP, OutboundPort, MaxPeer)
|
ethereum := utils.NewEthereum(db, clientIdentity, keyManager, UseUPnP, OutboundPort, MaxPeer)
|
||||||
|
|
||||||
|
if Dump {
|
||||||
|
var block *ethchain.Block
|
||||||
|
|
||||||
|
if len(DumpHash) == 0 && DumpNumber == -1 {
|
||||||
|
block = ethereum.BlockChain().CurrentBlock
|
||||||
|
} else if len(DumpHash) > 0 {
|
||||||
|
block = ethereum.BlockChain().GetBlock(ethutil.Hex2Bytes(DumpHash))
|
||||||
|
} else {
|
||||||
|
block = ethereum.BlockChain().GetBlockByNumber(uint64(DumpNumber))
|
||||||
|
}
|
||||||
|
|
||||||
|
if block == nil {
|
||||||
|
fmt.Fprintln(os.Stderr, "block not found")
|
||||||
|
|
||||||
|
// We want to output valid JSON
|
||||||
|
fmt.Println("{}")
|
||||||
|
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Leave the Println. This needs clean output for piping
|
||||||
|
fmt.Println(block.State().Dump())
|
||||||
|
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
if ShowGenesis {
|
if ShowGenesis {
|
||||||
utils.ShowGenesis(ethereum)
|
utils.ShowGenesis(ethereum)
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,11 @@ package ethrepl
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/ethereum/eth-go"
|
"github.com/ethereum/eth-go"
|
||||||
"github.com/ethereum/eth-go/ethchain"
|
"github.com/ethereum/eth-go/ethchain"
|
||||||
"github.com/ethereum/eth-go/ethlog"
|
"github.com/ethereum/eth-go/ethlog"
|
||||||
@ -11,10 +16,6 @@ import (
|
|||||||
"github.com/ethereum/eth-go/ethutil"
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
"github.com/ethereum/go-ethereum/utils"
|
"github.com/ethereum/go-ethereum/utils"
|
||||||
"github.com/obscuren/otto"
|
"github.com/obscuren/otto"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var jsrelogger = ethlog.NewLogger("JSRE")
|
var jsrelogger = ethlog.NewLogger("JSRE")
|
||||||
@ -147,12 +148,44 @@ func (self *JSRE) initStdFuncs() {
|
|||||||
eth.Set("stopMining", self.stopMining)
|
eth.Set("stopMining", self.stopMining)
|
||||||
eth.Set("startMining", self.startMining)
|
eth.Set("startMining", self.startMining)
|
||||||
eth.Set("execBlock", self.execBlock)
|
eth.Set("execBlock", self.execBlock)
|
||||||
|
eth.Set("dump", self.dump)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The following methods are natively implemented javascript functions
|
* The following methods are natively implemented javascript functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
func (self *JSRE) dump(call otto.FunctionCall) otto.Value {
|
||||||
|
var state *ethstate.State
|
||||||
|
|
||||||
|
if len(call.ArgumentList) > 0 {
|
||||||
|
var block *ethchain.Block
|
||||||
|
if call.Argument(0).IsNumber() {
|
||||||
|
num, _ := call.Argument(0).ToInteger()
|
||||||
|
block = self.ethereum.BlockChain().GetBlockByNumber(uint64(num))
|
||||||
|
} else if call.Argument(0).IsString() {
|
||||||
|
hash, _ := call.Argument(0).ToString()
|
||||||
|
block = self.ethereum.BlockChain().GetBlock(ethutil.Hex2Bytes(hash))
|
||||||
|
} else {
|
||||||
|
fmt.Println("invalid argument for dump. Either hex string or number")
|
||||||
|
}
|
||||||
|
|
||||||
|
if block == nil {
|
||||||
|
fmt.Println("block not found")
|
||||||
|
|
||||||
|
return otto.UndefinedValue()
|
||||||
|
}
|
||||||
|
|
||||||
|
state = block.State()
|
||||||
|
} else {
|
||||||
|
state = self.ethereum.StateManager().CurrentState()
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(state.Dump())
|
||||||
|
|
||||||
|
return otto.UndefinedValue()
|
||||||
|
}
|
||||||
|
|
||||||
func (self *JSRE) stopMining(call otto.FunctionCall) otto.Value {
|
func (self *JSRE) stopMining(call otto.FunctionCall) otto.Value {
|
||||||
v, _ := self.vm.ToValue(utils.StopMining(self.ethereum))
|
v, _ := self.vm.ToValue(utils.StopMining(self.ethereum))
|
||||||
return v
|
return v
|
||||||
|
Loading…
Reference in New Issue
Block a user