Skip to content

Commit

Permalink
further cleaned up xeth interface
Browse files Browse the repository at this point in the history
  • Loading branch information
obscuren committed Jan 28, 2015
1 parent 1146f25 commit 872b249
Show file tree
Hide file tree
Showing 15 changed files with 123 additions and 133 deletions.
4 changes: 2 additions & 2 deletions cmd/mist/ext_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type AppContainer interface {
}

type ExtApplication struct {
*xeth.JSXEth
*xeth.XEth
eth core.EthManager

events event.Subscription
Expand All @@ -61,7 +61,7 @@ type ExtApplication struct {

func NewExtApplication(container AppContainer, lib *UiLib) *ExtApplication {
return &ExtApplication{
JSXEth: xeth.NewJSXEth(lib.eth),
XEth: xeth.New(lib.eth),
eth: lib.eth,
watcherQuitChan: make(chan bool),
filters: make(map[string]*core.Filter),
Expand Down
12 changes: 6 additions & 6 deletions cmd/mist/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type Gui struct {
logLevel logger.LogLevel
open bool

xeth *xeth.JSXEth
xeth *xeth.XEth

Session string
clientIdentity *p2p.SimpleClientIdentity
Expand All @@ -93,7 +93,7 @@ func NewWindow(ethereum *eth.Ethereum, config *ethutil.ConfigManager, clientIden
panic(err)
}

xeth := xeth.NewJSXEth(ethereum)
xeth := xeth.New(ethereum)
gui := &Gui{eth: ethereum,
txDb: db,
xeth: xeth,
Expand All @@ -120,9 +120,9 @@ func (gui *Gui) Start(assetPath string) {

// Register ethereum functions
qml.RegisterTypes("Ethereum", 1, 0, []qml.TypeSpec{{
Init: func(p *xeth.JSBlock, obj qml.Object) { p.Number = 0; p.Hash = "" },
Init: func(p *xeth.Block, obj qml.Object) { p.Number = 0; p.Hash = "" },
}, {
Init: func(p *xeth.JSTransaction, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" },
Init: func(p *xeth.Transaction, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" },
}, {
Init: func(p *xeth.KeyVal, obj qml.Object) { p.Key = ""; p.Value = "" },
}})
Expand Down Expand Up @@ -276,7 +276,7 @@ func (gui *Gui) insertTransaction(window string, tx *types.Transaction) {
}

var (
ptx = xeth.NewJSTx(tx)
ptx = xeth.NewTx(tx)
send = ethutil.Bytes2Hex(tx.From())
rec = ethutil.Bytes2Hex(tx.To())
)
Expand All @@ -303,7 +303,7 @@ func (gui *Gui) readPreviousTransactions() {

func (gui *Gui) processBlock(block *types.Block, initial bool) {
name := ethutil.Bytes2Hex(block.Coinbase())
b := xeth.NewJSBlock(block)
b := xeth.NewBlock(block)
b.Name = name

gui.getObjectByName("chainView").Call("addBlock", b, initial)
Expand Down
2 changes: 1 addition & 1 deletion cmd/mist/html_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (app *HtmlApplication) Window() *qml.Window {
}

func (app *HtmlApplication) NewBlock(block *types.Block) {
b := &xeth.JSBlock{Number: int(block.NumberU64()), Hash: ethutil.Bytes2Hex(block.Hash())}
b := &xeth.Block{Number: int(block.NumberU64()), Hash: ethutil.Bytes2Hex(block.Hash())}
app.webView.Call("onNewBlockCb", b)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/mist/qml_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (app *QmlApplication) NewWatcher(quitChan chan bool) {

// Events
func (app *QmlApplication) NewBlock(block *types.Block) {
pblock := &xeth.JSBlock{Number: int(block.NumberU64()), Hash: ethutil.Bytes2Hex(block.Hash())}
pblock := &xeth.Block{Number: int(block.NumberU64()), Hash: ethutil.Bytes2Hex(block.Hash())}
app.win.Call("onNewBlockCb", pblock)
}

Expand Down
12 changes: 6 additions & 6 deletions cmd/mist/ui_lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type memAddr struct {

// UI Library that has some basic functionality exposed
type UiLib struct {
*xeth.JSXEth
*xeth.XEth
engine *qml.Engine
eth *eth.Ethereum
connected bool
Expand All @@ -63,7 +63,7 @@ type UiLib struct {
}

func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib {
lib := &UiLib{JSXEth: xeth.NewJSXEth(eth), engine: engine, eth: eth, assetPath: assetPath, jsEngine: javascript.NewJSRE(eth), filterCallbacks: make(map[int][]int)} //, filters: make(map[int]*xeth.JSFilter)}
lib := &UiLib{XEth: xeth.New(eth), engine: engine, eth: eth, assetPath: assetPath, jsEngine: javascript.NewJSRE(eth), filterCallbacks: make(map[int][]int)} //, filters: make(map[int]*xeth.JSFilter)}
lib.miner = miner.New(eth.KeyManager().Address(), eth)
lib.filterManager = filter.NewFilterManager(eth.EventMux())
go lib.filterManager.Start()
Expand Down Expand Up @@ -180,7 +180,7 @@ func (self *UiLib) StartDebugger() {
func (self *UiLib) Transact(params map[string]interface{}) (string, error) {
object := mapToTxParams(params)

return self.JSXEth.Transact(
return self.XEth.Transact(
object["from"],
object["to"],
object["value"],
Expand All @@ -202,7 +202,7 @@ func (self *UiLib) Compile(code string) (string, error) {
func (self *UiLib) Call(params map[string]interface{}) (string, error) {
object := mapToTxParams(params)

return self.JSXEth.Execute(
return self.XEth.Execute(
object["to"],
object["value"],
object["gas"],
Expand Down Expand Up @@ -261,7 +261,7 @@ func (self *UiLib) ToAscii(data string) string {
func (self *UiLib) NewFilter(object map[string]interface{}, view *qml.Common) (id int) {
filter := qt.NewFilterFromMap(object, self.eth)
filter.MessageCallback = func(messages state.Messages) {
view.Call("messages", xeth.ToJSMessages(messages), id)
view.Call("messages", xeth.ToMessages(messages), id)
}
id = self.filterManager.InstallFilter(filter)
return id
Expand All @@ -279,7 +279,7 @@ func (self *UiLib) NewFilterString(typ string, view *qml.Common) (id int) {
func (self *UiLib) Messages(id int) *ethutil.List {
filter := self.filterManager.GetFilter(id)
if filter != nil {
messages := xeth.ToJSMessages(filter.Find())
messages := xeth.ToMessages(filter.Find())

return messages
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/utils/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func KeyTasks(keyManager *crypto.KeyManager, KeyRing string, GenAddr bool, Secre

func StartRpc(ethereum *eth.Ethereum, RpcPort int) {
var err error
ethereum.RpcServer, err = rpchttp.NewRpcHttpServer(xeth.NewJSXEth(ethereum), RpcPort)
ethereum.RpcServer, err = rpchttp.NewRpcHttpServer(xeth.New(ethereum), RpcPort)
if err != nil {
clilogger.Errorf("Could not start RPC interface (port %v): %v", RpcPort, err)
} else {
Expand Down
4 changes: 2 additions & 2 deletions javascript/javascript_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var jsrelogger = logger.NewLogger("JSRE")
type JSRE struct {
ethereum *eth.Ethereum
Vm *otto.Otto
pipe *xeth.JSXEth
pipe *xeth.XEth

events event.Subscription

Expand All @@ -49,7 +49,7 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
re := &JSRE{
ethereum,
otto.New(),
xeth.NewJSXEth(ethereum),
xeth.New(ethereum),
nil,
make(map[string][]otto.Value),
}
Expand Down
18 changes: 9 additions & 9 deletions javascript/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import (
)

type JSStateObject struct {
*xeth.JSObject
*xeth.Object
eth *JSEthereum
}

func (self *JSStateObject) EachStorage(call otto.FunctionCall) otto.Value {
cb := call.Argument(0)

it := self.JSObject.Trie().Iterator()
it := self.Object.Trie().Iterator()
for it.Next() {
cb.Call(self.eth.toVal(self), self.eth.toVal(ethutil.Bytes2Hex(it.Key)), self.eth.toVal(ethutil.Bytes2Hex(it.Value)))
}
Expand All @@ -30,12 +30,12 @@ func (self *JSStateObject) EachStorage(call otto.FunctionCall) otto.Value {
// The JSEthereum object attempts to wrap the PEthereum object and returns
// meaningful javascript objects
type JSBlock struct {
*xeth.JSBlock
*xeth.Block
eth *JSEthereum
}

func (self *JSBlock) GetTransaction(hash string) otto.Value {
return self.eth.toVal(self.JSBlock.GetTransaction(hash))
return self.eth.toVal(self.Block.GetTransaction(hash))
}

type JSMessage struct {
Expand Down Expand Up @@ -67,27 +67,27 @@ func NewJSMessage(message *state.Message) JSMessage {
}

type JSEthereum struct {
*xeth.JSXEth
*xeth.XEth
vm *otto.Otto
ethereum *eth.Ethereum
}

func (self *JSEthereum) Block(v interface{}) otto.Value {
if number, ok := v.(int64); ok {
return self.toVal(&JSBlock{self.JSXEth.BlockByNumber(int32(number)), self})
return self.toVal(&JSBlock{self.XEth.BlockByNumber(int32(number)), self})
} else if hash, ok := v.(string); ok {
return self.toVal(&JSBlock{self.JSXEth.BlockByHash(hash), self})
return self.toVal(&JSBlock{self.XEth.BlockByHash(hash), self})
}

return otto.UndefinedValue()
}

func (self *JSEthereum) GetStateObject(addr string) otto.Value {
return self.toVal(&JSStateObject{xeth.NewJSObject(self.JSXEth.State().SafeGet(addr)), self})
return self.toVal(&JSStateObject{self.XEth.State().SafeGet(addr), self})
}

func (self *JSEthereum) Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr string) otto.Value {
r, err := self.JSXEth.Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr)
r, err := self.XEth.Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr)
if err != nil {
fmt.Println(err)

Expand Down
4 changes: 2 additions & 2 deletions rpc/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
var rpchttplogger = logger.NewLogger("RPC-HTTP")
var JSON rpc.JsonWrapper

func NewRpcHttpServer(pipe *xeth.JSXEth, port int) (*RpcHttpServer, error) {
func NewRpcHttpServer(pipe *xeth.XEth, port int) (*RpcHttpServer, error) {
sport := fmt.Sprintf(":%d", port)
l, err := net.Listen("tcp", sport)
if err != nil {
Expand All @@ -47,7 +47,7 @@ func NewRpcHttpServer(pipe *xeth.JSXEth, port int) (*RpcHttpServer, error) {
type RpcHttpServer struct {
quit chan bool
listener net.Listener
pipe *xeth.JSXEth
pipe *xeth.XEth
port int
}

Expand Down
10 changes: 5 additions & 5 deletions rpc/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
For each request type, define the following:
1. RpcRequest "To" method [message.go], which does basic validation and conversion to "Args" type via json.Decoder()
2. json.Decoder() calls "UnmarshalJSON" defined on each "Args" struct
3. EthereumApi method, taking the "Args" type and replying with an interface to be marshalled to JSON
2. json.Decoder() calls "UnmarshalON" defined on each "Args" struct
3. EthereumApi method, taking the "Args" type and replying with an interface to be marshalled to ON
*/
package rpc
Expand All @@ -38,12 +38,12 @@ type RpcServer interface {
Stop()
}

func NewEthereumApi(xeth *xeth.JSXEth) *EthereumApi {
func NewEthereumApi(xeth *xeth.XEth) *EthereumApi {
return &EthereumApi{xeth: xeth}
}

type EthereumApi struct {
xeth *xeth.JSXEth
xeth *xeth.XEth
}

func (p *EthereumApi) GetBlock(args *GetBlockArgs, reply *interface{}) error {
Expand Down Expand Up @@ -162,7 +162,7 @@ func (p *EthereumApi) GetCodeAt(args *GetCodeAtArgs, reply *interface{}) error {
}

func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error {
// Spec at https://github.com/ethereum/wiki/wiki/Generic-JSON-RPC
// Spec at https://github.com/ethereum/wiki/wiki/Generic-ON-RPC
rpclogger.DebugDetailf("%T %s", req.Params, req.Params)
switch req.Method {
case "eth_coinbase":
Expand Down
2 changes: 1 addition & 1 deletion rpc/ws/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (self *WebSocketServer) Start() {
wslogger.Infof("Starting RPC-WS server on port %d", self.port)
go self.handlerLoop()

api := rpc.NewEthereumApi(xeth.NewJSXEth(self.eth))
api := rpc.NewEthereumApi(xeth.New(self.eth))
h := self.apiHandler(api)
http.Handle("/ws", h)

Expand Down
26 changes: 0 additions & 26 deletions xeth/object.go

This file was deleted.

Loading

0 comments on commit 872b249

Please sign in to comment.