mirror of
https://github.com/status-im/op-geth.git
synced 2025-01-15 17:24:36 +00:00
Removed some methods from the JS REPL
This commit is contained in:
parent
cc5c8a444d
commit
6ea7aae29c
@ -135,6 +135,12 @@ func Init() {
|
|||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
// When the javascript console is started log to a file instead
|
||||||
|
// of stdout
|
||||||
|
if StartJsConsole {
|
||||||
|
LogFile = path.Join(Datadir, "ethereum.log")
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if NAT, err = nat.Parse(*natstr); err != nil {
|
if NAT, err = nat.Parse(*natstr); err != nil {
|
||||||
log.Fatalf("-nat: %v", err)
|
log.Fatalf("-nat: %v", err)
|
||||||
|
@ -137,6 +137,9 @@ func main() {
|
|||||||
|
|
||||||
utils.StartEthereum(ethereum)
|
utils.StartEthereum(ethereum)
|
||||||
|
|
||||||
|
latestBlock := ethereum.ChainManager().CurrentBlock()
|
||||||
|
fmt.Printf("Welcome to the FRONTIER\n")
|
||||||
|
|
||||||
if StartJsConsole {
|
if StartJsConsole {
|
||||||
InitJsConsole(ethereum)
|
InitJsConsole(ethereum)
|
||||||
} else if len(InputFile) > 0 {
|
} else if len(InputFile) > 0 {
|
||||||
|
@ -60,6 +60,7 @@ func (self *JSRepl) Start() {
|
|||||||
if !self.running {
|
if !self.running {
|
||||||
self.running = true
|
self.running = true
|
||||||
repllogger.Infoln("init JS Console")
|
repllogger.Infoln("init JS Console")
|
||||||
|
|
||||||
reader := bufio.NewReader(self.history)
|
reader := bufio.NewReader(self.history)
|
||||||
for {
|
for {
|
||||||
line, err := reader.ReadString('\n')
|
line, err := reader.ReadString('\n')
|
||||||
|
@ -51,8 +51,6 @@ func GenesisBlock(db ethutil.Database) *types.Block {
|
|||||||
statedb.Sync()
|
statedb.Sync()
|
||||||
genesis.Header().Root = statedb.Root()
|
genesis.Header().Root = statedb.Root()
|
||||||
|
|
||||||
fmt.Printf("+++ genesis +++\nRoot: %x\nHash: %x\n", genesis.Header().Root, genesis.Hash())
|
|
||||||
|
|
||||||
return genesis
|
return genesis
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ var jsrelogger = logger.NewLogger("JSRE")
|
|||||||
type JSRE struct {
|
type JSRE struct {
|
||||||
ethereum *eth.Ethereum
|
ethereum *eth.Ethereum
|
||||||
Vm *otto.Otto
|
Vm *otto.Otto
|
||||||
pipe *xeth.XEth
|
xeth *xeth.XEth
|
||||||
|
|
||||||
events event.Subscription
|
events event.Subscription
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
|
|||||||
// We have to make sure that, whoever calls this, calls "Stop"
|
// We have to make sure that, whoever calls this, calls "Stop"
|
||||||
go re.mainLoop()
|
go re.mainLoop()
|
||||||
|
|
||||||
re.Bind("eth", &JSEthereum{re.pipe, re.Vm, ethereum})
|
re.Bind("eth", &JSEthereum{re.xeth, re.Vm, ethereum})
|
||||||
|
|
||||||
re.initStdFuncs()
|
re.initStdFuncs()
|
||||||
|
|
||||||
@ -113,12 +113,10 @@ func (self *JSRE) mainLoop() {
|
|||||||
func (self *JSRE) initStdFuncs() {
|
func (self *JSRE) initStdFuncs() {
|
||||||
t, _ := self.Vm.Get("eth")
|
t, _ := self.Vm.Get("eth")
|
||||||
eth := t.Object()
|
eth := t.Object()
|
||||||
eth.Set("watch", self.watch)
|
eth.Set("connect", self.connect)
|
||||||
eth.Set("addPeer", self.addPeer)
|
|
||||||
eth.Set("require", self.require)
|
eth.Set("require", self.require)
|
||||||
eth.Set("stopMining", self.stopMining)
|
eth.Set("stopMining", self.stopMining)
|
||||||
eth.Set("startMining", self.startMining)
|
eth.Set("startMining", self.startMining)
|
||||||
eth.Set("execBlock", self.execBlock)
|
|
||||||
eth.Set("dump", self.dump)
|
eth.Set("dump", self.dump)
|
||||||
eth.Set("export", self.export)
|
eth.Set("export", self.export)
|
||||||
}
|
}
|
||||||
@ -152,7 +150,8 @@ func (self *JSRE) dump(call otto.FunctionCall) otto.Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
statedb := state.New(block.Root(), self.ethereum.Db())
|
statedb := state.New(block.Root(), self.ethereum.Db())
|
||||||
v, _ := self.Vm.ToValue(statedb.Dump())
|
|
||||||
|
v, _ := self.Vm.ToValue(statedb.RawDump())
|
||||||
|
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
@ -167,36 +166,7 @@ func (self *JSRE) startMining(call otto.FunctionCall) otto.Value {
|
|||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
// eth.watch
|
func (self *JSRE) connect(call otto.FunctionCall) otto.Value {
|
||||||
func (self *JSRE) watch(call otto.FunctionCall) otto.Value {
|
|
||||||
addr, _ := call.Argument(0).ToString()
|
|
||||||
var storageAddr string
|
|
||||||
var cb otto.Value
|
|
||||||
var storageCallback bool
|
|
||||||
if len(call.ArgumentList) > 2 {
|
|
||||||
storageCallback = true
|
|
||||||
storageAddr, _ = call.Argument(1).ToString()
|
|
||||||
cb = call.Argument(2)
|
|
||||||
} else {
|
|
||||||
cb = call.Argument(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if storageCallback {
|
|
||||||
self.objectCb[addr+storageAddr] = append(self.objectCb[addr+storageAddr], cb)
|
|
||||||
|
|
||||||
// event := "storage:" + string(ethutil.Hex2Bytes(addr)) + ":" + string(ethutil.Hex2Bytes(storageAddr))
|
|
||||||
// self.ethereum.EventMux().Subscribe(event, self.changeChan)
|
|
||||||
} else {
|
|
||||||
self.objectCb[addr] = append(self.objectCb[addr], cb)
|
|
||||||
|
|
||||||
// event := "object:" + string(ethutil.Hex2Bytes(addr))
|
|
||||||
// self.ethereum.EventMux().Subscribe(event, self.changeChan)
|
|
||||||
}
|
|
||||||
|
|
||||||
return otto.UndefinedValue()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *JSRE) addPeer(call otto.FunctionCall) otto.Value {
|
|
||||||
nodeURL, err := call.Argument(0).ToString()
|
nodeURL, err := call.Argument(0).ToString()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return otto.FalseValue()
|
return otto.FalseValue()
|
||||||
@ -222,22 +192,12 @@ func (self *JSRE) require(call otto.FunctionCall) otto.Value {
|
|||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *JSRE) execBlock(call otto.FunctionCall) otto.Value {
|
func (self *JSRE) export(call otto.FunctionCall) otto.Value {
|
||||||
hash, err := call.Argument(0).ToString()
|
if len(call.ArgumentList) == 0 {
|
||||||
if err != nil {
|
fmt.Println("err: require file name")
|
||||||
return otto.UndefinedValue()
|
|
||||||
}
|
|
||||||
|
|
||||||
err = utils.BlockDo(self.ethereum, ethutil.Hex2Bytes(hash))
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
return otto.FalseValue()
|
return otto.FalseValue()
|
||||||
}
|
}
|
||||||
|
|
||||||
return otto.TrueValue()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *JSRE) export(call otto.FunctionCall) otto.Value {
|
|
||||||
fn, err := call.Argument(0).ToString()
|
fn, err := call.Argument(0).ToString()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
@ -16,7 +16,7 @@ function pp(object) {
|
|||||||
str += " ]";
|
str += " ]";
|
||||||
} else if(typeof(object) === "object") {
|
} else if(typeof(object) === "object") {
|
||||||
str += "{ ";
|
str += "{ ";
|
||||||
var last = Object.keys(object).sort().pop()
|
var last = Object.keys(object).pop()
|
||||||
for(var k in object) {
|
for(var k in object) {
|
||||||
str += k + ": " + pp(object[k]);
|
str += k + ": " + pp(object[k]);
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ type World struct {
|
|||||||
Accounts map[string]Account `json:"accounts"`
|
Accounts map[string]Account `json:"accounts"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StateDB) Dump() []byte {
|
func (self *StateDB) RawDump() World {
|
||||||
world := World{
|
world := World{
|
||||||
Root: ethutil.Bytes2Hex(self.trie.Root()),
|
Root: ethutil.Bytes2Hex(self.trie.Root()),
|
||||||
Accounts: make(map[string]Account),
|
Accounts: make(map[string]Account),
|
||||||
@ -39,8 +39,11 @@ func (self *StateDB) Dump() []byte {
|
|||||||
}
|
}
|
||||||
world.Accounts[ethutil.Bytes2Hex(it.Key)] = account
|
world.Accounts[ethutil.Bytes2Hex(it.Key)] = account
|
||||||
}
|
}
|
||||||
|
return world
|
||||||
|
}
|
||||||
|
|
||||||
json, err := json.MarshalIndent(world, "", " ")
|
func (self *StateDB) Dump() []byte {
|
||||||
|
json, err := json.MarshalIndent(self.RawDump(), "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("dump err", err)
|
fmt.Println("dump err", err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user