Ejemplo n.º 1
0
func testInit(t *testing.T) (self *testFrontend) {
	// initialise and start minimal ethereum stack
	ethereum, err := testEth(t)
	if err != nil {
		t.Errorf("error creating ethereum: %v", err)
		return
	}
	err = ethereum.Start()
	if err != nil {
		t.Errorf("error starting ethereum: %v", err)
		return
	}

	// mock frontend
	self = &testFrontend{t: t, ethereum: ethereum}
	self.xeth = xe.New(ethereum, self)
	self.wait = self.xeth.UpdateState()
	addr, _ := self.ethereum.Etherbase()

	// initialise the registry contracts
	reg := registrar.New(self.xeth)
	var registrarTxhash, hashRegTxhash, urlHintTxhash string
	registrarTxhash, err = reg.SetGlobalRegistrar("", addr)
	if err != nil {
		t.Errorf("error creating GlobalRegistrar: %v", err)
	}

	hashRegTxhash, err = reg.SetHashReg("", addr)
	if err != nil {
		t.Errorf("error creating HashReg: %v", err)
	}
	urlHintTxhash, err = reg.SetUrlHint("", addr)
	if err != nil {
		t.Errorf("error creating UrlHint: %v", err)
	}
	if !processTxs(self, t, 3) {
		t.Errorf("error mining txs")
	}
	_ = registrarTxhash
	_ = hashRegTxhash
	_ = urlHintTxhash

	/* TODO:
	* lookup receipt and contract addresses by tx hash
	* name registration for HashReg and UrlHint addresses
	* mine those transactions
	* then set once more SetHashReg SetUrlHint
	 */

	return

}
Ejemplo n.º 2
0
func StartRPC(eth *eth.Ethereum, ctx *cli.Context) error {
	config := comms.HttpConfig{
		ListenAddress: ctx.GlobalString(RPCListenAddrFlag.Name),
		ListenPort:    uint(ctx.GlobalInt(RPCPortFlag.Name)),
		CorsDomain:    ctx.GlobalString(RPCCORSDomainFlag.Name),
	}

	xeth := xeth.New(eth, nil)
	codec := codec.JSON

	apis, err := api.ParseApiString(ctx.GlobalString(RpcApiFlag.Name), codec, xeth, eth)
	if err != nil {
		return err
	}

	return comms.StartHttp(config, codec, api.Merge(apis...))
}
Ejemplo n.º 3
0
func StartIPC(eth *eth.Ethereum, ctx *cli.Context) error {
	config := comms.IpcConfig{
		Endpoint: IpcSocketPath(ctx),
	}

	initializer := func(conn net.Conn) (shared.EthereumApi, error) {
		fe := useragent.NewRemoteFrontend(conn, eth.AccountManager())
		xeth := xeth.New(eth, fe)
		codec := codec.JSON

		apis, err := api.ParseApiString(ctx.GlobalString(IPCApiFlag.Name), codec, xeth, eth)
		if err != nil {
			return nil, err
		}

		return api.Merge(apis...), nil
	}

	return comms.StartIpc(config, codec.JSON, initializer)
}
Ejemplo n.º 4
0
func newJSRE(ethereum *eth.Ethereum, libPath, corsDomain string, client comms.EthereumClient, interactive bool, f xeth.Frontend) *jsre {
	js := &jsre{ethereum: ethereum, ps1: "> "}
	// set default cors domain used by startRpc from CLI flag
	js.corsDomain = corsDomain
	if f == nil {
		f = js
	}
	js.ds = docserver.New("/")
	js.xeth = xeth.New(ethereum, f)
	js.wait = js.xeth.UpdateState()
	js.client = client
	if clt, ok := js.client.(*comms.InProcClient); ok {
		if offeredApis, err := api.ParseApiString(shared.AllApis, codec.JSON, js.xeth, ethereum); err == nil {
			clt.Initialize(api.Merge(offeredApis...))
		}
	}

	// update state in separare forever blocks
	js.re = re.New(libPath)
	if err := js.apiBindings(f); err != nil {
		utils.Fatalf("Unable to connect - %v", err)
	}

	if !liner.TerminalSupported() || !interactive {
		js.prompter = dumbterm{bufio.NewReader(os.Stdin)}
	} else {
		lr := liner.NewLiner()
		js.withHistory(func(hist *os.File) { lr.ReadHistory(hist) })
		lr.SetCtrlCAborts(true)
		js.loadAutoCompletion()
		lr.SetWordCompleter(apiWordCompleter)
		lr.SetTabCompletionStyle(liner.TabPrints)
		js.prompter = lr
		js.atexit = func() {
			js.withHistory(func(hist *os.File) { hist.Truncate(0); lr.WriteHistory(hist) })
			lr.Close()
			close(js.wait)
		}
	}
	return js
}