diff options
author | obscuren <geffobscura@gmail.com> | 2015-04-19 19:30:55 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-04-19 19:30:55 +0800 |
commit | 6e1aa91aaf0d3af7151a891fb1cc6f7aa0c6ab4c (patch) | |
tree | 997c86399779eaaa7643fee09f97ebedc4ebea43 /cmd | |
parent | c58918c84ad6825ca20cc9170b0a79eb1033c50a (diff) | |
download | go-tangerine-6e1aa91aaf0d3af7151a891fb1cc6f7aa0c6ab4c.tar go-tangerine-6e1aa91aaf0d3af7151a891fb1cc6f7aa0c6ab4c.tar.gz go-tangerine-6e1aa91aaf0d3af7151a891fb1cc6f7aa0c6ab4c.tar.bz2 go-tangerine-6e1aa91aaf0d3af7151a891fb1cc6f7aa0c6ab4c.tar.lz go-tangerine-6e1aa91aaf0d3af7151a891fb1cc6f7aa0c6ab4c.tar.xz go-tangerine-6e1aa91aaf0d3af7151a891fb1cc6f7aa0c6ab4c.tar.zst go-tangerine-6e1aa91aaf0d3af7151a891fb1cc6f7aa0c6ab4c.zip |
geth: added getBlockRlp for dumping block in rlp format
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/geth/admin.go | 26 |
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 { |