aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/geth
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-04-19 19:30:55 +0800
committerobscuren <geffobscura@gmail.com>2015-04-19 19:30:55 +0800
commit6e1aa91aaf0d3af7151a891fb1cc6f7aa0c6ab4c (patch)
tree997c86399779eaaa7643fee09f97ebedc4ebea43 /cmd/geth
parentc58918c84ad6825ca20cc9170b0a79eb1033c50a (diff)
downloaddexon-6e1aa91aaf0d3af7151a891fb1cc6f7aa0c6ab4c.tar.gz
dexon-6e1aa91aaf0d3af7151a891fb1cc6f7aa0c6ab4c.tar.zst
dexon-6e1aa91aaf0d3af7151a891fb1cc6f7aa0c6ab4c.zip
geth: added getBlockRlp for dumping block in rlp format
Diffstat (limited to 'cmd/geth')
-rw-r--r--cmd/geth/admin.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/cmd/geth/admin.go b/cmd/geth/admin.go
index f8c717187..2ac155e33 100644
--- a/cmd/geth/admin.go
+++ b/cmd/geth/admin.go
@@ -48,6 +48,32 @@ func (js *jsre) adminBindings() {
debug := t.Object()
debug.Set("printBlock", js.printBlock)
debug.Set("dumpBlock", js.dumpBlock)
+ debug.Set("getBlockRlp", js.getBlockRlp)
+}
+
+func (js *jsre) getBlockRlp(call otto.FunctionCall) otto.Value {
+ var block *types.Block
+ if len(call.ArgumentList) > 0 {
+ if call.Argument(0).IsNumber() {
+ num, _ := call.Argument(0).ToInteger()
+ block = js.ethereum.ChainManager().GetBlockByNumber(uint64(num))
+ } else if call.Argument(0).IsString() {
+ hash, _ := call.Argument(0).ToString()
+ block = js.ethereum.ChainManager().GetBlock(common.HexToHash(hash))
+ } else {
+ fmt.Println("invalid argument for dump. Either hex string or number")
+ }
+
+ } else {
+ block = js.ethereum.ChainManager().CurrentBlock()
+ }
+ if block == nil {
+ fmt.Println("block not found")
+ return otto.UndefinedValue()
+ }
+
+ encoded, _ := rlp.EncodeToBytes(block)
+ return js.re.ToVal(fmt.Sprintf("%x", encoded))
}
func (js *jsre) setExtra(call otto.FunctionCall) otto.Value {