func (self *JSRE) require(call otto.FunctionCall) otto.Value { file, err := call.Argument(0).ToString() if err != nil { return otto.UndefinedValue() } if err := self.Require(file); err != nil { fmt.Println("err:", err) return otto.UndefinedValue() } t, _ := self.vm.Get("exports") return t }
// eth.watch 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.Reactor().Subscribe(event, self.changeChan) } else { self.objectCb[addr] = append(self.objectCb[addr], cb) event := "object:" + string(ethutil.Hex2Bytes(addr)) self.ethereum.Reactor().Subscribe(event, self.changeChan) } return otto.UndefinedValue() }
func (self *JSRE) dump(call otto.FunctionCall) otto.Value { var state *ethstate.State if len(call.ArgumentList) > 0 { var block *ethchain.Block if call.Argument(0).IsNumber() { num, _ := call.Argument(0).ToInteger() block = self.ethereum.BlockChain().GetBlockByNumber(uint64(num)) } else if call.Argument(0).IsString() { hash, _ := call.Argument(0).ToString() block = self.ethereum.BlockChain().GetBlock(ethutil.Hex2Bytes(hash)) } else { fmt.Println("invalid argument for dump. Either hex string or number") } if block == nil { fmt.Println("block not found") return otto.UndefinedValue() } state = block.State() } else { state = self.ethereum.StateManager().CurrentState() } v, _ := self.Vm.ToValue(state.Dump()) return v }
func (self *JSEthereum) Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr string) otto.Value { r, err := self.JSPipe.Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr) if err != nil { fmt.Println(err) return otto.UndefinedValue() } return self.toVal(r) }
func (self *JSStateObject) EachStorage(call otto.FunctionCall) otto.Value { cb := call.Argument(0) self.JSObject.EachStorage(func(key string, value *ethutil.Value) { value.Decode() cb.Call(self.eth.toVal(self), self.eth.toVal(key), self.eth.toVal(ethutil.Bytes2Hex(value.Bytes()))) }) return otto.UndefinedValue() }
func (self *JSEthereum) toVal(v interface{}) otto.Value { result, err := self.vm.ToValue(v) if err != nil { fmt.Println("Value unknown:", err) return otto.UndefinedValue() } return result }
func (self *JSEthereum) Create(key, valueStr, gasStr, gasPriceStr, scriptStr string) otto.Value { r, err := self.JSPipe.Transact(key, "", valueStr, gasStr, gasPriceStr, scriptStr) if err != nil { fmt.Println(err) return otto.UndefinedValue() } return self.toVal(r) }
func (self *JSRE) execBlock(call otto.FunctionCall) otto.Value { hash, err := call.Argument(0).ToString() if err != nil { return otto.UndefinedValue() } err = utils.BlockDo(self.ethereum, ethutil.Hex2Bytes(hash)) if err != nil { fmt.Println(err) return otto.FalseValue() } return otto.TrueValue() }