当前位置: 首页>>代码示例>>Golang>>正文


Golang otto.FalseValue函数代码示例

本文整理汇总了Golang中github.com/robertkrimen/otto.FalseValue函数的典型用法代码示例。如果您正苦于以下问题:Golang FalseValue函数的具体用法?Golang FalseValue怎么用?Golang FalseValue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了FalseValue函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: NewAccount

// NewAccount asks the user for the password and than executes the jeth.newAccount callback in the jsre
func (self *Jeth) NewAccount(call otto.FunctionCall) (response otto.Value) {
	var passwd string
	if len(call.ArgumentList) == 0 {
		var err error
		passwd, err = Stdin.PasswordPrompt("Passphrase: ")
		if err != nil {
			return otto.FalseValue()
		}
		passwd2, err := Stdin.PasswordPrompt("Repeat passphrase: ")
		if err != nil {
			return otto.FalseValue()
		}

		if passwd != passwd2 {
			fmt.Println("Passphrases don't match")
			return otto.FalseValue()
		}
	} else if len(call.ArgumentList) == 1 && call.Argument(0).IsString() {
		passwd, _ = call.Argument(0).ToString()
	} else {
		fmt.Println("expected 0 or 1 string argument")
		return otto.FalseValue()
	}

	ret, err := call.Otto.Call("jeth.newAccount", nil, passwd)
	if err == nil {
		return ret
	}
	fmt.Println(err)
	return otto.FalseValue()
}
开发者ID:Xiaoyang-Zhu,项目名称:go-ethereum,代码行数:32,代码来源:jeth.go

示例2: plurk_AddResponse

// Add Response API
func plurk_AddResponse(call otto.FunctionCall) otto.Value {

	plurkID, _ := call.Argument(0).ToInteger()
	message, _ := call.Argument(1).ToString()
	qualifier, _ := call.Argument(2).ToString()

	if plurkID == 0 {
		logger.Error("Plurk ID not specify, add response failed!")
		return otto.FalseValue()
	}

	if len(message) <= 0 || message == "undefined" {
		logger.Error("No plurk content specify, add response failed!")
		return otto.FalseValue()
	}

	if qualifier == "undefined" {
		qualifier = ":"
	}

	responses := client.GetResponses()
	res, err := responses.ResponseAdd(int(plurkID), message, qualifier)

	if err != nil {
		logger.Error("Add response failed, because %s", err.Error())
	}

	logger.Info("Add response success, content is %s", res.RawContent)

	return otto.TrueValue()
}
开发者ID:elct9620,项目名称:go-plurk-robot,代码行数:32,代码来源:mod_plurk.go

示例3: InitUtilsJSBridge

func (pm *PluginManager) InitUtilsJSBridge() {
	bridge := &pmUtilsJSBridge{
		GetPage: func(call otto.FunctionCall) otto.Value {
			var err error
			switch {
			case len(call.ArgumentList) == 1 && call.ArgumentList[0].IsString():
				if page, err := utils.GetPage(call.Argument(0).String()); err == nil {
					if val, err := pm.js.ToValue(page); err == nil {
						return val
					}
				}
				pm.log.Printf("[UTILS] GetPage errored: %s\n", err)
			case len(call.ArgumentList) == 3 && call.ArgumentList[0].IsString() && call.ArgumentList[1].IsString() && call.ArgumentList[2].IsString():
				if page, err := utils.GetPageWithAuth(call.Argument(0).String(), call.Argument(1).String(), call.Argument(2).String()); err == nil {
					if val, err := pm.js.ToValue(page); err == nil {
						return val
					}
				}
				pm.log.Printf("[UTILS] GetPageWithAuth errored: %s\n", err)
			}
			return otto.FalseValue()
		},
		ExtractURL: func(call otto.FunctionCall) otto.Value {
			var err error
			if len(call.ArgumentList) == 1 && call.ArgumentList[0].IsString() {
				if url, err := utils.ExtractURL(call.Argument(0).String()); err == nil {
					if val, err := pm.js.ToValue(url); err == nil {
						return val
					}
				}
				pm.log.Printf("[UTILS] ExtractURL errored: %s\n", err)
			}
			return otto.FalseValue()
		},
		ExtractTitle: func(call otto.FunctionCall) otto.Value {
			var err error
			if len(call.ArgumentList) == 1 && call.ArgumentList[0].IsString() {
				if title, err := utils.ExtractTitle(call.Argument(0).String()); err == nil {
					if val, err := pm.js.ToValue(title); err == nil {
						return val
					}
				}
				pm.log.Printf("[UTILS] ExtractTitle errored: %s\n", err)
			}
			return otto.FalseValue()
		},
		Sleep: func(call otto.FunctionCall) otto.Value {
			var err error
			if len(call.ArgumentList) == 1 && call.ArgumentList[0].IsNumber() {
				if i, err := call.Argument(0).ToInteger(); err == nil {
					utils.Sleep(i)
					return otto.TrueValue()
				}
				pm.log.Printf("[UTILS] Sleep errored: %s\n", err)
			}
			return otto.FalseValue()
		},
	}
	pm.js.Set("UTILS", bridge)
}
开发者ID:Zenithar,项目名称:aktarus,代码行数:60,代码来源:utils_js_bridge.go

示例4: unlock

func (js *jsre) unlock(call otto.FunctionCall) otto.Value {
	addr, err := call.Argument(0).ToString()
	if err != nil {
		fmt.Println(err)
		return otto.FalseValue()
	}
	seconds, err := call.Argument(2).ToInteger()
	if err != nil {
		fmt.Println(err)
		return otto.FalseValue()
	}
	arg := call.Argument(1)
	var passphrase string
	if arg.IsUndefined() {
		fmt.Println("Please enter a passphrase now.")
		passphrase, err = readPassword("Passphrase: ", true)
		if err != nil {
			utils.Fatalf("%v", err)
		}
	} else {
		passphrase, err = arg.ToString()
		if err != nil {
			fmt.Println(err)
			return otto.FalseValue()
		}
	}
	am := js.ethereum.AccountManager()
	err = am.TimedUnlock(common.FromHex(addr), passphrase, time.Duration(seconds)*time.Second)
	if err != nil {
		fmt.Printf("Unlock account failed '%v'\n", err)
		return otto.FalseValue()
	}
	return otto.TrueValue()
}
开发者ID:CedarLogic,项目名称:go-ethereum,代码行数:34,代码来源:admin.go

示例5: NewAccount

// NewAccount asks the user for the password and than executes the jeth.newAccount callback in the jsre
func (self *Jeth) NewAccount(call otto.FunctionCall) (response otto.Value) {
	if len(call.ArgumentList) == 0 {
		passwd, err := PromptPassword("Passphrase: ", true)
		if err != nil {
			return otto.FalseValue()
		}
		passwd2, err := PromptPassword("Repeat passphrase: ", true)
		if err != nil {
			return otto.FalseValue()
		}

		if passwd != passwd2 {
			fmt.Println("Passphrases don't match")
			return otto.FalseValue()
		}

		cmd := fmt.Sprintf("jeth.newAccount('%s')", passwd)
		if val, err := call.Otto.Run(cmd); err == nil {
			return val
		}
	} else {
		fmt.Println("New account doesn't expect argument(s), you will be prompted for a password")
	}

	return otto.FalseValue()
}
开发者ID:karalabe,项目名称:etherapis,代码行数:27,代码来源:jeth.go

示例6: resend

func (js *jsre) resend(call otto.FunctionCall) otto.Value {
	if len(call.ArgumentList) == 0 {
		fmt.Println("first argument must be a transaction")
		return otto.FalseValue()
	}

	v, err := call.Argument(0).Export()
	if err != nil {
		fmt.Println(err)
		return otto.FalseValue()
	}

	if tx, ok := v.(*tx); ok {
		gl, gp := tx.GasLimit, tx.GasPrice
		if len(call.ArgumentList) > 1 {
			gp = call.Argument(1).String()
		}
		if len(call.ArgumentList) > 2 {
			gl = call.Argument(2).String()
		}

		ret, err := js.xeth.Transact(tx.From, tx.To, tx.Nonce, tx.Value, gl, gp, tx.Data)
		if err != nil {
			fmt.Println(err)
			return otto.FalseValue()
		}
		js.ethereum.TxPool().RemoveTransactions(types.Transactions{tx.tx})

		return js.re.ToVal(ret)
	}

	fmt.Println("first argument must be a transaction")
	return otto.FalseValue()
}
开发者ID:CedarLogic,项目名称:go-ethereum,代码行数:34,代码来源:admin.go

示例7: plurk_AddPlurk

// Add Plurk API
func plurk_AddPlurk(call otto.FunctionCall) otto.Value {
	message, _ := call.Argument(0).ToString()
	qualifier, _ := call.Argument(1).ToString()
	lang, _ := call.Argument(2).ToString()

	// No message specify, return error
	if len(message) <= 0 {
		return otto.FalseValue()
	}

	// Default qualifier
	if qualifier == "undefined" {
		qualifier = ":"
	}

	if lang == "undefined" {
		lang = "en"
	}

	timeline := client.GetTimeline()
	res, err := timeline.PlurkAdd(message, qualifier, make([]int, 0), false, lang, true)

	if err != nil {
		logger.Error("Add Plurk failed, because %s", err.Error())
		return otto.FalseValue()
	}

	logger.Info("New plurk added, content is %s", res.RawContent)

	return otto.TrueValue()
}
开发者ID:elct9620,项目名称:go-plurk-robot,代码行数:32,代码来源:mod_plurk.go

示例8: loadplugin

func (i *instance) loadplugin(name string) error {
	b, err := ioutil.ReadFile(name)
	_, filename := filepath.Split(name)

	if _, ok := i.Pluginfuncs[filename]; ok {
		delete(i.Pluginfuncs, filename)
		delete(i.Plugindocs, filename)
	}

	if err != nil {
		return err
	}

	m := make(map[string]otto.Value)
	i.js.Set("Subscribe", func(call otto.FunctionCall) otto.Value {
		if len(call.ArgumentList) >= 2 && call.ArgumentList[0].IsString() && call.ArgumentList[1].IsFunction() {
			name := call.ArgumentList[0].String()
			f := call.ArgumentList[1]
			if strings.HasPrefix(name, "regex:") {
				_, err := regexp.Compile(name[len("regex:"):])
				if err != nil {
					i.Irc.Privmsg(i.Irccfg.Channel, "Regex error: "+err.Error()+" - Regex subscribe was not successful")
					return otto.FalseValue()
				}
			}
			m[name] = f
			return otto.TrueValue()
		} else {
			return otto.FalseValue()
		}
	})

	md := make(map[string]string)
	i.js.Set("Doc", func(call otto.FunctionCall) otto.Value {
		if len(call.ArgumentList) >= 2 && call.ArgumentList[0].IsString() && call.ArgumentList[1].IsString() {
			name := call.ArgumentList[0].String()
			doc := call.ArgumentList[1].String()
			md[name] = doc
			return otto.TrueValue()
		} else {
			return otto.FalseValue()
		}
	})

	_, err = i.js.Run(string(b))
	i.js.Set("Subscribe", nil)
	i.js.Set("Doc", nil)

	if err != nil {
		fmt.Println(err.Error())
		return err
	} else {
		i.Pluginfuncs[filename] = m
		i.Plugindocs[filename] = md
		return nil
	}

}
开发者ID:ylmbtm,项目名称:nitori-go,代码行数:58,代码来源:plugin.go

示例9: NewExecutor

func NewExecutor(s stream.Stream) *Executor {
	e := &Executor{
		incomingScripts: make(chan string),
		outgoingMsgs:    make(chan string),
		incomingEvents:  make(chan IncomingEvent),
		eventHandlers:   make(map[string]map[string]otto.Value),
	}
	e.xmppStream = s
	e.vm = otto.New()

	send := func(call otto.FunctionCall) otto.Value {
		str, _ := call.Argument(0).ToString()
		e.outgoingMsgs <- str
		return otto.UndefinedValue()
	}

	addHandler := func(call otto.FunctionCall) otto.Value {
		evtName, err := call.Argument(0).ToString()
		handlerName, err := call.Argument(1).ToString()
		if err != nil {
			return otto.FalseValue()
		}
		val := call.Argument(2)
		if !val.IsFunction() {
			return otto.FalseValue()
		}
		handlers, ok := e.eventHandlers[evtName]
		if !ok {
			e.eventHandlers[evtName] = map[string]otto.Value{handlerName: val}
		} else {
			handlers[handlerName] = val
		}
		return otto.TrueValue()
	}

	listHandlers := func(call otto.FunctionCall) otto.Value {
		evtName, err := call.Argument(0).ToString()
		if err != nil {
			return otto.UndefinedValue()
		}
		list := []string{}
		for handlerName := range e.eventHandlers[evtName] {
			list = append(list, handlerName)
		}
		val, err := e.vm.ToValue(list)
		if err != nil {
			return otto.UndefinedValue()
		} else {
			return val
		}
	}

	chatLibrary, _ := e.vm.Object("Chat = {};")
	chatLibrary.Set("send", send)
	chatLibrary.Set("addEventHandler", addHandler)
	chatLibrary.Set("listEventHandlers", listHandlers)
	return e
}
开发者ID:postman0,项目名称:xep,代码行数:58,代码来源:executor.go

示例10: loadScript

/*
Executes a JS script from inside the currently executing JS code.
Should only be called from inside an RPC routine.
*/
func (self *JSRE) loadScript(call otto.FunctionCall) otto.Value {
	file, err := call.Argument(0).ToString()
	if err != nil {
		return otto.FalseValue()
	}
	if err := self.execWithoutEQ(file); err != nil { // loadScript is only called from inside js
		fmt.Println("err:", err)
		return otto.FalseValue()
	}

	return otto.TrueValue()
}
开发者ID:CedarLogic,项目名称:go-ethereum,代码行数:16,代码来源:jsre.go

示例11: addPeer

func (js *jsre) addPeer(call otto.FunctionCall) otto.Value {
	nodeURL, err := call.Argument(0).ToString()
	if err != nil {
		fmt.Println(err)
		return otto.FalseValue()
	}
	err = js.ethereum.AddPeer(nodeURL)
	if err != nil {
		fmt.Println(err)
		return otto.FalseValue()
	}
	return otto.TrueValue()
}
开发者ID:CedarLogic,项目名称:go-ethereum,代码行数:13,代码来源:admin.go

示例12: startMining

func (js *jsre) startMining(call otto.FunctionCall) otto.Value {
	_, err := call.Argument(0).ToInteger()
	if err != nil {
		fmt.Println(err)
		return otto.FalseValue()
	}
	// threads now ignored
	err = js.ethereum.StartMining()
	if err != nil {
		fmt.Println(err)
		return otto.FalseValue()
	}
	return otto.TrueValue()
}
开发者ID:CedarLogic,项目名称:go-ethereum,代码行数:14,代码来源:admin.go

示例13: newAccount

func (js *jsre) newAccount(call otto.FunctionCall) otto.Value {
	arg := call.Argument(0)
	var passphrase string
	if arg.IsUndefined() {
		fmt.Println("The new account will be encrypted with a passphrase.")
		fmt.Println("Please enter a passphrase now.")
		auth, err := readPassword("Passphrase: ", true)
		if err != nil {
			utils.Fatalf("%v", err)
		}
		confirm, err := readPassword("Repeat Passphrase: ", false)
		if err != nil {
			utils.Fatalf("%v", err)
		}
		if auth != confirm {
			utils.Fatalf("Passphrases did not match.")
		}
		passphrase = auth
	} else {
		var err error
		passphrase, err = arg.ToString()
		if err != nil {
			fmt.Println(err)
			return otto.FalseValue()
		}
	}
	acct, err := js.ethereum.AccountManager().NewAccount(passphrase)
	if err != nil {
		fmt.Printf("Could not create the account: %v", err)
		return otto.UndefinedValue()
	}
	return js.re.ToVal("0x" + common.Bytes2Hex(acct.Address))
}
开发者ID:CedarLogic,项目名称:go-ethereum,代码行数:33,代码来源:admin.go

示例14: importChain

func (js *jsre) importChain(call otto.FunctionCall) otto.Value {
	if len(call.ArgumentList) == 0 {
		fmt.Println("err: require file name")
		return otto.FalseValue()
	}
	fn, err := call.Argument(0).ToString()
	if err != nil {
		fmt.Println(err)
		return otto.FalseValue()
	}
	if err := utils.ImportChain(js.ethereum.ChainManager(), fn); err != nil {
		fmt.Println("Import error: ", err)
		return otto.FalseValue()
	}
	return otto.TrueValue()
}
开发者ID:CedarLogic,项目名称:go-ethereum,代码行数:16,代码来源:admin.go

示例15: UnlockAccount

// UnlockAccount asks the user for the password and than executes the jeth.UnlockAccount callback in the jsre.
// It will need the public address for the account to unlock as first argument.
// The second argument is an optional string with the password. If not given the user is prompted for the password.
// The third argument is an optional integer which specifies for how long the account will be unlocked (in seconds).
func (self *Jeth) UnlockAccount(call otto.FunctionCall) (response otto.Value) {
	var account, passwd otto.Value
	duration := otto.NullValue()

	if !call.Argument(0).IsString() {
		fmt.Println("first argument must be the account to unlock")
		return otto.FalseValue()
	}

	account = call.Argument(0)

	// if password is not given or as null value -> ask user for password
	if call.Argument(1).IsUndefined() || call.Argument(1).IsNull() {
		fmt.Printf("Unlock account %s\n", account)
		if input, err := Stdin.PasswordPrompt("Passphrase: "); err != nil {
			throwJSExeception(err.Error())
		} else {
			passwd, _ = otto.ToValue(input)
		}
	} else {
		if !call.Argument(1).IsString() {
			throwJSExeception("password must be a string")
		}
		passwd = call.Argument(1)
	}

	// third argument is the duration how long the account must be unlocked.
	// verify that its a number.
	if call.Argument(2).IsDefined() && !call.Argument(2).IsNull() {
		if !call.Argument(2).IsNumber() {
			throwJSExeception("unlock duration must be a number")
		}
		duration = call.Argument(2)
	}

	// jeth.unlockAccount will send the request to the backend.
	if val, err := call.Otto.Call("jeth.unlockAccount", nil, account, passwd, duration); err == nil {
		return val
	} else {
		throwJSExeception(err.Error())
	}

	return otto.FalseValue()
}
开发者ID:Xiaoyang-Zhu,项目名称:go-ethereum,代码行数:48,代码来源:jeth.go


注:本文中的github.com/robertkrimen/otto.FalseValue函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。