diff options
author | Ethan Buchman <ethan@coinculture.info> | 2015-02-18 08:25:18 +0800 |
---|---|---|
committer | Ethan Buchman <ethan@coinculture.info> | 2015-02-18 08:25:18 +0800 |
commit | 2ba65f4fbaea49c1e0d99959b0331e09b153f931 (patch) | |
tree | add8cabb05cd7fbf0ba4b4bbaf9460dacfc2082d /javascript | |
parent | 2da367a2bee84d74d1bb0ea1b42d4c22fae486dd (diff) | |
parent | 60318c96d03bcaaf731802b1080a3d87cb482124 (diff) | |
download | go-tangerine-2ba65f4fbaea49c1e0d99959b0331e09b153f931.tar.gz go-tangerine-2ba65f4fbaea49c1e0d99959b0331e09b153f931.tar.zst go-tangerine-2ba65f4fbaea49c1e0d99959b0331e09b153f931.zip |
Merge branch 'develop' of https://github.com/ethereum/go-ethereum into develop
Diffstat (limited to 'javascript')
-rw-r--r-- | javascript/javascript_runtime.go | 14 | ||||
-rw-r--r-- | javascript/types.go | 70 |
2 files changed, 32 insertions, 52 deletions
diff --git a/javascript/javascript_runtime.go b/javascript/javascript_runtime.go index adc9022b7..0aa0f73e2 100644 --- a/javascript/javascript_runtime.go +++ b/javascript/javascript_runtime.go @@ -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 @@ -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), } @@ -58,8 +58,7 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE { re.Vm.Run(jsLib) // Load extra javascript files - re.LoadIntFile("string.js") - re.LoadIntFile("big.js") + re.LoadIntFile("bignumber.min.js") // Subscribe to events mux := ethereum.EventMux() @@ -198,12 +197,13 @@ func (self *JSRE) watch(call otto.FunctionCall) otto.Value { } func (self *JSRE) addPeer(call otto.FunctionCall) otto.Value { - host, err := call.Argument(0).ToString() + nodeURL, err := call.Argument(0).ToString() if err != nil { return otto.FalseValue() } - self.ethereum.SuggestPeer(host) - + if err := self.ethereum.SuggestPeer(nodeURL); err != nil { + return otto.FalseValue() + } return otto.TrueValue() } diff --git a/javascript/types.go b/javascript/types.go index 61a57033b..17f1b739e 100644 --- a/javascript/types.go +++ b/javascript/types.go @@ -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))) } @@ -30,72 +30,52 @@ 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 { - To string `json:"to"` - From string `json:"from"` - Input string `json:"input"` - Output string `json:"output"` - Path int `json:"path"` - Origin string `json:"origin"` - Timestamp int32 `json:"timestamp"` - Coinbase string `json:"coinbase"` - Block string `json:"block"` - Number int32 `json:"number"` +type JSLog struct { + Address string `json:address` + Topics []string `json:topics` + Number int32 `json:number` + Data string `json:data` } -func NewJSMessage(message *state.Message) JSMessage { - return JSMessage{ - To: ethutil.Bytes2Hex(message.To), - From: ethutil.Bytes2Hex(message.From), - Input: ethutil.Bytes2Hex(message.Input), - Output: ethutil.Bytes2Hex(message.Output), - Path: message.Path, - Origin: ethutil.Bytes2Hex(message.Origin), - Timestamp: int32(message.Timestamp), - Coinbase: ethutil.Bytes2Hex(message.Origin), - Block: ethutil.Bytes2Hex(message.Block), - Number: int32(message.Number.Int64()), +func NewJSLog(log state.Log) JSLog { + return JSLog{ + Address: ethutil.Bytes2Hex(log.Address()), + Topics: nil, //ethutil.Bytes2Hex(log.Address()), + Number: 0, + Data: ethutil.Bytes2Hex(log.Data()), } } 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) Peers() otto.Value { - return self.toVal(self.JSXEth.Peers()) -} - -func (self *JSEthereum) Key() otto.Value { - return self.toVal(self.JSXEth.Key()) -} - func (self *JSEthereum) GetStateObject(addr string) otto.Value { - return self.toVal(&JSStateObject{xeth.NewJSObject(self.JSXEth.World().SafeGet(ethutil.Hex2Bytes(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(recipient, valueStr, gasStr, gasPriceStr, dataStr) if err != nil { fmt.Println(err) @@ -120,13 +100,13 @@ func (self *JSEthereum) toVal(v interface{}) otto.Value { func (self *JSEthereum) Messages(object map[string]interface{}) otto.Value { filter := ui.NewFilterFromMap(object, self.ethereum) - messages := filter.Find() - var msgs []JSMessage - for _, m := range messages { - msgs = append(msgs, NewJSMessage(m)) + logs := filter.Find() + var jslogs []JSLog + for _, m := range logs { + jslogs = append(jslogs, NewJSLog(m)) } - v, _ := self.vm.ToValue(msgs) + v, _ := self.vm.ToValue(jslogs) return v } |