func testInit(t *testing.T) (self *testFrontend) { // initialise and start minimal expanse stack expanse, err := testEth(t) if err != nil { t.Errorf("error creating expanse: %v", err) return } err = expanse.Start() if err != nil { t.Errorf("error starting expanse: %v", err) return } // mock frontend self = &testFrontend{t: t, expanse: expanse} self.xeth = xe.New(expanse, self) self.wait = self.xeth.UpdateState() addr, _ := self.expanse.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 }
func StartRPC(exp *exp.Expanse, 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(exp, nil) codec := codec.JSON apis, err := api.ParseApiString(ctx.GlobalString(RpcApiFlag.Name), codec, xeth, exp) if err != nil { return err } return comms.StartHttp(config, codec, api.Merge(apis...)) }
func StartIPC(exp *exp.Expanse, ctx *cli.Context) error { config := comms.IpcConfig{ Endpoint: IpcSocketPath(ctx), } initializer := func(conn net.Conn) (comms.Stopper, shared.ExpanseApi, error) { fe := useragent.NewRemoteFrontend(conn, exp.AccountManager()) xeth := xeth.New(exp, fe) apis, err := api.ParseApiString(ctx.GlobalString(IPCApiFlag.Name), codec.JSON, xeth, exp) if err != nil { return nil, nil, err } return xeth, api.Merge(apis...), nil } return comms.StartIpc(config, codec.JSON, initializer) }
func newJSRE(expanse *exp.Expanse, docRoot, corsDomain string, client comms.ExpanseClient, interactive bool, f xeth.Frontend) *jsre { js := &jsre{expanse: expanse, ps1: "> "} // set default cors domain used by startRpc from CLI flag js.corsDomain = corsDomain if f == nil { f = js } js.xeth = xeth.New(expanse, 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, expanse); err == nil { clt.Initialize(api.Merge(offeredApis...)) } } // update state in separare forever blocks js.re = re.New(docRoot) 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(expanse.DataDir, 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(expanse.DataDir, func(hist *os.File) { hist.Truncate(0); lr.WriteHistory(hist) }) lr.Close() close(js.wait) } } return js }
func testInit(t *testing.T) (self *testFrontend) { // initialise and start minimal expanse stack expanse, err := testExp(t) if err != nil { t.Errorf("error creating expanse: %v", err) return } err = expanse.Start(nil) if err != nil { t.Errorf("error starting expanse: %v", err) return } // mock frontend self = &testFrontend{t: t, ethereum: ethereum} self.xeth = xe.New(nil, self) self.wait = self.xexp.UpdateState() addr, _ := self.expanse.Etherbase() // initialise the registry contracts reg := registrar.New(self.xeth) registrar.GlobalRegistrarAddr = "0x0" var txG, txH, txU string txG, err = reg.SetGlobalRegistrar("", addr) if err != nil { t.Fatalf("error creating GlobalRegistrar: %v", err) } if !processTxs(self, t, 1) { t.Fatalf("error mining txs") } recG := self.xexp.GetTxReceipt(common.HexToHash(txG)) if recG == nil { t.Fatalf("blockchain error creating GlobalRegistrar") } registrar.GlobalRegistrarAddr = recG.ContractAddress.Hex() txH, err = reg.SetHashReg("", addr) if err != nil { t.Errorf("error creating HashReg: %v", err) } if !processTxs(self, t, 1) { t.Errorf("error mining txs") } recH := self.xexp.GetTxReceipt(common.HexToHash(txH)) if recH == nil { t.Fatalf("blockchain error creating HashReg") } registrar.HashRegAddr = recH.ContractAddress.Hex() txU, err = reg.SetUrlHint("", addr) if err != nil { t.Errorf("error creating UrlHint: %v", err) } if !processTxs(self, t, 1) { t.Errorf("error mining txs") } recU := self.xexp.GetTxReceipt(common.HexToHash(txU)) if recU == nil { t.Fatalf("blockchain error creating UrlHint") } registrar.UrlHintAddr = recU.ContractAddress.Hex() return }