Switched over to ethpipe
This commit is contained in:
@ -10,7 +10,7 @@ import (
|
||||
"github.com/ethereum/eth-go"
|
||||
"github.com/ethereum/eth-go/ethchain"
|
||||
"github.com/ethereum/eth-go/ethlog"
|
||||
"github.com/ethereum/eth-go/ethpub"
|
||||
"github.com/ethereum/eth-go/ethpipe"
|
||||
"github.com/ethereum/eth-go/ethreact"
|
||||
"github.com/ethereum/eth-go/ethstate"
|
||||
"github.com/ethereum/eth-go/ethutil"
|
||||
@ -23,7 +23,7 @@ var jsrelogger = ethlog.NewLogger("JSRE")
|
||||
type JSRE struct {
|
||||
ethereum *eth.Ethereum
|
||||
Vm *otto.Otto
|
||||
lib *ethpub.PEthereum
|
||||
pipe *ethpipe.JSPipe
|
||||
|
||||
blockChan chan ethreact.Event
|
||||
changeChan chan ethreact.Event
|
||||
@ -50,7 +50,7 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
|
||||
re := &JSRE{
|
||||
ethereum,
|
||||
otto.New(),
|
||||
ethpub.New(ethereum),
|
||||
ethpipe.NewJSPipe(ethereum),
|
||||
make(chan ethreact.Event, 10),
|
||||
make(chan ethreact.Event, 10),
|
||||
make(chan bool),
|
||||
@ -71,7 +71,7 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
|
||||
reactor := ethereum.Reactor()
|
||||
reactor.Subscribe("newBlock", re.blockChan)
|
||||
|
||||
re.Bind("eth", &JSEthereum{re.lib, re.Vm, ethereum})
|
||||
re.Bind("eth", &JSEthereum{re.pipe, re.Vm, ethereum})
|
||||
|
||||
re.initStdFuncs()
|
||||
|
||||
@ -123,18 +123,6 @@ out:
|
||||
case block := <-self.blockChan:
|
||||
if _, ok := block.Resource.(*ethchain.Block); ok {
|
||||
}
|
||||
case object := <-self.changeChan:
|
||||
if stateObject, ok := object.Resource.(*ethstate.StateObject); ok {
|
||||
for _, cb := range self.objectCb[ethutil.Bytes2Hex(stateObject.Address())] {
|
||||
val, _ := self.Vm.ToValue(ethpub.NewPStateObject(stateObject))
|
||||
cb.Call(cb, val)
|
||||
}
|
||||
} else if storageObject, ok := object.Resource.(*ethstate.StorageState); ok {
|
||||
for _, cb := range self.objectCb[ethutil.Bytes2Hex(storageObject.StateAddress)+ethutil.Bytes2Hex(storageObject.Address)] {
|
||||
val, _ := self.Vm.ToValue(ethpub.NewPStorageState(storageObject))
|
||||
cb.Call(cb, val)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,20 +5,20 @@ import (
|
||||
|
||||
"github.com/ethereum/eth-go"
|
||||
"github.com/ethereum/eth-go/ethchain"
|
||||
"github.com/ethereum/eth-go/ethpub"
|
||||
"github.com/ethereum/eth-go/ethpipe"
|
||||
"github.com/ethereum/eth-go/ethstate"
|
||||
"github.com/ethereum/eth-go/ethutil"
|
||||
"github.com/obscuren/otto"
|
||||
)
|
||||
|
||||
type JSStateObject struct {
|
||||
*ethpub.PStateObject
|
||||
*ethpipe.JSObject
|
||||
eth *JSEthereum
|
||||
}
|
||||
|
||||
func (self *JSStateObject) EachStorage(call otto.FunctionCall) otto.Value {
|
||||
cb := call.Argument(0)
|
||||
self.PStateObject.EachStorage(func(key string, value *ethutil.Value) {
|
||||
self.JSObject.EachStorage(func(key string, value *ethutil.Value) {
|
||||
value.Decode()
|
||||
|
||||
cb.Call(self.eth.toVal(self), self.eth.toVal(key), self.eth.toVal(ethutil.Bytes2Hex(value.Bytes())))
|
||||
@ -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 {
|
||||
*ethpub.PBlock
|
||||
*ethpipe.JSBlock
|
||||
eth *JSEthereum
|
||||
}
|
||||
|
||||
func (self *JSBlock) GetTransaction(hash string) otto.Value {
|
||||
return self.eth.toVal(self.PBlock.GetTransaction(hash))
|
||||
return self.eth.toVal(self.JSBlock.GetTransaction(hash))
|
||||
}
|
||||
|
||||
type JSMessage struct {
|
||||
@ -67,33 +67,29 @@ func NewJSMessage(message *ethstate.Message) JSMessage {
|
||||
}
|
||||
|
||||
type JSEthereum struct {
|
||||
*ethpub.PEthereum
|
||||
*ethpipe.JSPipe
|
||||
vm *otto.Otto
|
||||
ethereum *eth.Ethereum
|
||||
}
|
||||
|
||||
func (self *JSEthereum) GetBlock(hash string) otto.Value {
|
||||
return self.toVal(&JSBlock{self.PEthereum.GetBlock(hash), self})
|
||||
return self.toVal(&JSBlock{self.JSPipe.GetBlockByHash(hash), self})
|
||||
}
|
||||
|
||||
func (self *JSEthereum) GetPeers() otto.Value {
|
||||
return self.toVal(self.PEthereum.GetPeers())
|
||||
return self.toVal(self.JSPipe.GetPeers())
|
||||
}
|
||||
|
||||
func (self *JSEthereum) GetKey() otto.Value {
|
||||
return self.toVal(self.PEthereum.GetKey())
|
||||
return self.toVal(self.JSPipe.GetKey())
|
||||
}
|
||||
|
||||
func (self *JSEthereum) GetStateObject(addr string) otto.Value {
|
||||
return self.toVal(&JSStateObject{self.PEthereum.GetStateObject(addr), self})
|
||||
}
|
||||
|
||||
func (self *JSEthereum) GetStateKeyVals(addr string) otto.Value {
|
||||
return self.toVal(self.PEthereum.GetStateObject(addr).StateKeyVal(false))
|
||||
return self.toVal(&JSStateObject{ethpipe.NewJSObject(self.JSPipe.World().SafeGet(ethutil.Hex2Bytes(addr))), self})
|
||||
}
|
||||
|
||||
func (self *JSEthereum) Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr string) otto.Value {
|
||||
r, err := self.PEthereum.Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr)
|
||||
r, err := self.JSPipe.Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
||||
@ -104,7 +100,7 @@ func (self *JSEthereum) Transact(key, recipient, valueStr, gasStr, gasPriceStr,
|
||||
}
|
||||
|
||||
func (self *JSEthereum) Create(key, valueStr, gasStr, gasPriceStr, scriptStr string) otto.Value {
|
||||
r, err := self.PEthereum.Create(key, valueStr, gasStr, gasPriceStr, scriptStr)
|
||||
r, err := self.JSPipe.Transact(key, "", valueStr, gasStr, gasPriceStr, scriptStr)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
Reference in New Issue
Block a user