Example #1
0
func (js *jsre) apiBindings() {

	ethApi := rpc.NewEthereumApi(js.xeth)
	//js.re.Bind("jeth", rpc.NewJeth(ethApi, js.re.ToVal))

	jeth := rpc.NewJeth(ethApi, js.re.ToVal, js.re)
	//js.re.Bind("jeth", jeth)
	js.re.Set("jeth", struct{}{})
	t, _ := js.re.Get("jeth")
	jethObj := t.Object()
	jethObj.Set("send", jeth.Send)
	jethObj.Set("sendAsync", jeth.Send)

	err := js.re.Compile("bignumber.js", re.BigNumber_JS)
	if err != nil {
		utils.Fatalf("Error loading bignumber.js: %v", err)
	}

	// we need to declare a dummy setTimeout. Otto does not support it
	_, err = js.re.Eval("setTimeout = function(cb, delay) {};")
	if err != nil {
		utils.Fatalf("Error defining setTimeout: %v", err)
	}

	err = js.re.Compile("ethereum.js", re.Ethereum_JS)
	if err != nil {
		utils.Fatalf("Error loading ethereum.js: %v", err)
	}

	_, err = js.re.Eval("var web3 = require('web3');")
	if err != nil {
		utils.Fatalf("Error requiring web3: %v", err)
	}

	_, err = js.re.Eval("web3.setProvider(jeth)")
	if err != nil {
		utils.Fatalf("Error setting web3 provider: %v", err)
	}
	_, err = js.re.Eval(`
var eth = web3.eth;
var shh = web3.shh;
var db  = web3.db;
var net = web3.net;
  `)
	if err != nil {
		utils.Fatalf("Error setting namespaces: %v", err)
	}

	js.re.Eval(globalRegistrar + "registrar = new GlobalRegistrar(\"" + globalRegistrarAddr + "\");")
}
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

}