aboutsummaryrefslogtreecommitdiffstats
path: root/ethereum/repl/javascript_runtime.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-08-06 15:53:12 +0800
committerobscuren <geffobscura@gmail.com>2014-08-06 15:53:12 +0800
commit852d1ee395feabaa0e72265106374a0df197db9a (patch)
tree2700d53ad6d5d415e2d91c7b71b1e23ba95e4602 /ethereum/repl/javascript_runtime.go
parent3c319f93f2a0e66bc131cfa1e81be840b3242182 (diff)
downloaddexon-852d1ee395feabaa0e72265106374a0df197db9a.tar.gz
dexon-852d1ee395feabaa0e72265106374a0df197db9a.tar.zst
dexon-852d1ee395feabaa0e72265106374a0df197db9a.zip
State dumps
Diffstat (limited to 'ethereum/repl/javascript_runtime.go')
-rw-r--r--ethereum/repl/javascript_runtime.go41
1 files changed, 37 insertions, 4 deletions
diff --git a/ethereum/repl/javascript_runtime.go b/ethereum/repl/javascript_runtime.go
index f5aea2dd9..29b5f442f 100644
--- a/ethereum/repl/javascript_runtime.go
+++ b/ethereum/repl/javascript_runtime.go
@@ -2,6 +2,11 @@ package ethrepl
import (
"fmt"
+ "io/ioutil"
+ "os"
+ "path"
+ "path/filepath"
+
"github.com/ethereum/eth-go"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethlog"
@@ -11,10 +16,6 @@ import (
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/go-ethereum/utils"
"github.com/obscuren/otto"
- "io/ioutil"
- "os"
- "path"
- "path/filepath"
)
var jsrelogger = ethlog.NewLogger("JSRE")
@@ -147,12 +148,44 @@ func (self *JSRE) initStdFuncs() {
eth.Set("stopMining", self.stopMining)
eth.Set("startMining", self.startMining)
eth.Set("execBlock", self.execBlock)
+ eth.Set("dump", self.dump)
}
/*
* 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 {
v, _ := self.vm.ToValue(utils.StopMining(self.ethereum))
return v