From 6e1aa91aaf0d3af7151a891fb1cc6f7aa0c6ab4c Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 19 Apr 2015 13:30:55 +0200 Subject: geth: added getBlockRlp for dumping block in rlp format --- cmd/geth/admin.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'cmd') 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 { -- cgit v1.2.3