aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/geth
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-04-20 18:29:02 +0800
committerobscuren <geffobscura@gmail.com>2015-04-20 18:29:02 +0800
commit45da3e17e2ada226d7c82db667d263f8e004cbfc (patch)
tree627499fa3e24bbe70ed5c0c526d30d713205b106 /cmd/geth
parent52584596d4c9cee7adcc1c343addd19279aaac84 (diff)
downloadgo-tangerine-45da3e17e2ada226d7c82db667d263f8e004cbfc.tar.gz
go-tangerine-45da3e17e2ada226d7c82db667d263f8e004cbfc.tar.zst
go-tangerine-45da3e17e2ada226d7c82db667d263f8e004cbfc.zip
core: added chain head reset to known block
Diffstat (limited to 'cmd/geth')
-rw-r--r--cmd/geth/admin.go47
1 files changed, 37 insertions, 10 deletions
diff --git a/cmd/geth/admin.go b/cmd/geth/admin.go
index c42e91615..1cd0aa2a9 100644
--- a/cmd/geth/admin.go
+++ b/cmd/geth/admin.go
@@ -1,6 +1,7 @@
package main
import (
+ "errors"
"fmt"
"os"
"time"
@@ -50,15 +51,10 @@ func (js *jsre) adminBindings() {
debug.Set("printBlock", js.printBlock)
debug.Set("dumpBlock", js.dumpBlock)
debug.Set("getBlockRlp", js.getBlockRlp)
+ debug.Set("setHead", js.setHead)
}
-func (js *jsre) downloadProgress(call otto.FunctionCall) otto.Value {
- current, max := js.ethereum.Downloader().Stats()
-
- return js.re.ToVal(fmt.Sprintf("%d/%d", current, max))
-}
-
-func (js *jsre) getBlockRlp(call otto.FunctionCall) otto.Value {
+func (js *jsre) getBlock(call otto.FunctionCall) (*types.Block, error) {
var block *types.Block
if len(call.ArgumentList) > 0 {
if call.Argument(0).IsNumber() {
@@ -68,12 +64,43 @@ func (js *jsre) getBlockRlp(call otto.FunctionCall) otto.Value {
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")
+ return nil, errors.New("invalid argument for dump. Either hex string or number")
}
+ return block, nil
+ }
- } else {
- block = js.ethereum.ChainManager().CurrentBlock()
+ return nil, errors.New("requires block number or block hash as argument")
+}
+
+func (js *jsre) setHead(call otto.FunctionCall) otto.Value {
+ block, err := js.getBlock(call)
+ if err != nil {
+ fmt.Println(err)
+ return otto.UndefinedValue()
}
+
+ if block == nil {
+ fmt.Println("block not found")
+ return otto.UndefinedValue()
+ }
+
+ js.ethereum.ChainManager().SetHead(block)
+ return otto.UndefinedValue()
+}
+
+func (js *jsre) downloadProgress(call otto.FunctionCall) otto.Value {
+ current, max := js.ethereum.Downloader().Stats()
+
+ return js.re.ToVal(fmt.Sprintf("%d/%d", current, max))
+}
+
+func (js *jsre) getBlockRlp(call otto.FunctionCall) otto.Value {
+ block, err := js.getBlock(call)
+ if err != nil {
+ fmt.Println(err)
+ return otto.UndefinedValue()
+ }
+
if block == nil {
fmt.Println("block not found")
return otto.UndefinedValue()