Esempio n. 1
0
func StartRPC(eth *eth.Ethereum, ctx *cli.Context) error {
	config := rpc.RpcConfig{
		ListenAddress: ctx.GlobalString(RPCListenAddrFlag.Name),
		ListenPort:    uint(ctx.GlobalInt(RPCPortFlag.Name)),
		CorsDomain:    ctx.GlobalString(RPCCORSDomainFlag.Name),
	}

	xeth := xeth.New(eth, nil)
	return rpc.Start(xeth, config)
}
Esempio n. 2
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

}
Esempio n. 3
0
func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath, libPath string) *UiLib {
	x := xeth.New(eth, nil)
	lib := &UiLib{
		XEth:            x,
		engine:          engine,
		eth:             eth,
		assetPath:       assetPath,
		filterCallbacks: make(map[int][]int),
	}
	lib.filterManager = filter.NewFilterManager(eth.EventMux())
	go lib.filterManager.Start()

	return lib
}
Esempio n. 4
0
func StartIPC(eth *eth.Ethereum, ctx *cli.Context) error {
	config := comms.IpcConfig{
		Endpoint: IpcSocketPath(ctx),
	}

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

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

	return comms.StartIpc(config, codec, api.Merge(apis...))
}
Esempio n. 5
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...))
}
Esempio n. 6
0
func StartIPC(eth *eth.Ethereum, ctx *cli.Context) error {
	config := comms.IpcConfig{
		Endpoint: IpcSocketPath(ctx),
	}

	initializer := func(conn net.Conn) (comms.Stopper, shared.EthereumApi, error) {
		fe := useragent.NewRemoteFrontend(conn, eth.AccountManager())
		xeth := xeth.New(eth, fe)
		apis, err := api.ParseApiString(ctx.GlobalString(IPCApiFlag.Name), codec.JSON, xeth, eth)
		if err != nil {
			return nil, nil, err
		}
		return xeth, api.Merge(apis...), nil
	}

	return comms.StartIpc(config, codec.JSON, initializer)
}
Esempio n. 7
0
// Create GUI, but doesn't start it
func NewWindow(ethereum *eth.Ethereum) *Gui {
	db, err := ethdb.NewLDBDatabase(path.Join(ethereum.DataDir, "tx_database"))
	if err != nil {
		panic(err)
	}

	xeth := xeth.New(ethereum, nil)
	gui := &Gui{eth: ethereum,
		txDb:          db,
		xeth:          xeth,
		open:          false,
		plugins:       make(map[string]plugin),
		serviceEvents: make(chan ServEv, 1),
	}
	data, _ := ioutil.ReadFile(path.Join(ethereum.DataDir, "plugins.json"))
	json.Unmarshal(data, &gui.plugins)

	return gui
}
Esempio n. 8
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
}
Esempio n. 9
0
func testInit(t *testing.T) (self *testFrontend) {

	core.GenesisData = []byte(`{
	"` + testAccount + `": {"balance": "` + testBalance + `"}
	}`)

	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
	}

	self = &testFrontend{t: t, ethereum: ethereum}
	self.xeth = xe.New(ethereum, self)
	self.api = rpc.NewEthereumApi(self.xeth)

	addr := self.xeth.Coinbase()
	self.coinbase = addr
	if addr != "0x"+testAccount {
		t.Errorf("CoinBase %v does not match TestAccount 0x%v", addr, testAccount)
	}
	t.Logf("CoinBase is %v", addr)

	balance := self.xeth.BalanceAt(testAccount)
	/*if balance != core.TestBalance {
		t.Errorf("Balance %v does not match TestBalance %v", balance, core.TestBalance)
	}*/
	t.Logf("Balance is %v", balance)

	self.stateDb = self.ethereum.ChainManager().State().Copy()

	return

}
Esempio n. 10
0
func (js *jsre) startRPC(call otto.FunctionCall) otto.Value {
	addr, err := call.Argument(0).ToString()
	if err != nil {
		fmt.Println(err)
		return otto.FalseValue()
	}

	port, err := call.Argument(1).ToInteger()
	if err != nil {
		fmt.Println(err)
		return otto.FalseValue()
	}

	corsDomain := js.corsDomain
	if len(call.ArgumentList) > 2 {
		corsDomain, err = call.Argument(2).ToString()
		if err != nil {
			fmt.Println(err)
			return otto.FalseValue()
		}
	}

	config := rpc.RpcConfig{
		ListenAddress: addr,
		ListenPort:    uint(port),
		CorsDomain:    corsDomain,
	}

	xeth := xeth.New(js.ethereum, nil)
	err = rpc.Start(xeth, config)

	if err != nil {
		fmt.Printf(err.Error())
		return otto.FalseValue()
	}

	return otto.TrueValue()
}
Esempio n. 11
0
func newJSRE(ethereum *eth.Ethereum, libPath string, interactive bool, corsDomain string) *jsre {
	js := &jsre{ethereum: ethereum, ps1: "> "}
	// set default cors domain used by startRpc from CLI flag
	js.corsDomain = corsDomain
	js.xeth = xeth.New(ethereum, js)
	js.re = re.New(libPath)
	js.apiBindings()
	js.adminBindings()

	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.prompter = lr
		js.atexit = func() {
			js.withHistory(func(hist *os.File) { hist.Truncate(0); lr.WriteHistory(hist) })
			lr.Close()
		}
	}
	return js
}
Esempio n. 12
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(nil)
	if err != nil {
		t.Errorf("error starting ethereum: %v", err)
		return
	}

	// mock frontend
	self = &testFrontend{t: t, ethereum: ethereum}
	self.xeth = xe.New(nil, self)
	self.wait = self.xeth.UpdateState()
	addr, _ := self.ethereum.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.xeth.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.xeth.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.xeth.GetTxReceipt(common.HexToHash(txU))
	if recU == nil {
		t.Fatalf("blockchain error creating UrlHint")
	}
	registrar.UrlHintAddr = recU.ContractAddress.Hex()

	return
}