@@ -32,7 +32,6 @@ func (js *jsre) adminBindings() {
3232 admin .Set ("unlock" , js .unlock )
3333 admin .Set ("import" , js .importChain )
3434 admin .Set ("export" , js .exportChain )
35- admin .Set ("dumpBlock" , js .dumpBlock )
3635 admin .Set ("verbosity" , js .verbosity )
3736 admin .Set ("backtrace" , js .backtrace )
3837
@@ -43,6 +42,12 @@ func (js *jsre) adminBindings() {
4342 miner .Set ("stop" , js .stopMining )
4443 miner .Set ("hashrate" , js .hashrate )
4544 miner .Set ("setExtra" , js .setExtra )
45+
46+ admin .Set ("debug" , struct {}{})
47+ t , _ = admin .Get ("debug" )
48+ debug := t .Object ()
49+ debug .Set ("printBlock" , js .printBlock )
50+ debug .Set ("dumpBlock" , js .dumpBlock )
4651}
4752
4853func (js * jsre ) setExtra (call otto.FunctionCall ) otto.Value {
@@ -284,6 +289,32 @@ func (js *jsre) exportChain(call otto.FunctionCall) otto.Value {
284289 return otto .TrueValue ()
285290}
286291
292+ func (js * jsre ) printBlock (call otto.FunctionCall ) otto.Value {
293+ var block * types.Block
294+ if len (call .ArgumentList ) > 0 {
295+ if call .Argument (0 ).IsNumber () {
296+ num , _ := call .Argument (0 ).ToInteger ()
297+ block = js .ethereum .ChainManager ().GetBlockByNumber (uint64 (num ))
298+ } else if call .Argument (0 ).IsString () {
299+ hash , _ := call .Argument (0 ).ToString ()
300+ block = js .ethereum .ChainManager ().GetBlock (common .HexToHash (hash ))
301+ } else {
302+ fmt .Println ("invalid argument for dump. Either hex string or number" )
303+ }
304+
305+ } else {
306+ block = js .ethereum .ChainManager ().CurrentBlock ()
307+ }
308+ if block == nil {
309+ fmt .Println ("block not found" )
310+ return otto .UndefinedValue ()
311+ }
312+
313+ fmt .Println (block )
314+
315+ return otto .UndefinedValue ()
316+ }
317+
287318func (js * jsre ) dumpBlock (call otto.FunctionCall ) otto.Value {
288319 var block * types.Block
289320 if len (call .ArgumentList ) > 0 {
0 commit comments