updated ethereum.js and moved to subfolder

* Previous subtree caused a lot of trouble
* Implemented sha3 in our shiny new http JSON RPC
This commit is contained in:
obscuren 2015-01-29 00:24:00 +01:00
parent 73dcbf7ba2
commit ec85458612
7 changed files with 140 additions and 3 deletions

View File

@ -550,6 +550,9 @@ var contract = function (address, desc) {
result[displayName][typeName] = impl;
});
console.log("call:")
console.log(result.call)
console.log(JSON.stringify(result));
return result;
};
@ -1195,4 +1198,4 @@ module.exports = web3;
},{"./lib/abi":1,"./lib/contract":2,"./lib/filter":3,"./lib/httpsync":4,"./lib/providermanager":5,"./lib/qtsync":6,"./lib/web3":7}]},{},["web3"])
//# sourceMappingURL=ethereum.js.map
//# sourceMappingURL=ethereum.js.map

View File

@ -0,0 +1,66 @@
// Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301 USA
var ethx = {
prototype: Object,
watch: function(options) {
return new Filter(options);
},
note: function() {
var args = Array.prototype.slice.call(arguments, 0);
var o = []
for(var i = 0; i < args.length; i++) {
o.push(args[i].toString())
}
eth.notef(o);
},
};
var Filter = function(options) {
this.callbacks = [];
this.options = options;
if(options === "chain") {
this.id = eth.newFilterString(options);
} else if(typeof options === "object") {
this.id = eth.newFilter(options);
}
};
Filter.prototype.changed = function(callback) {
this.callbacks.push(callback);
var self = this;
messages.connect(function(messages, id) {
if(id == self.id) {
for(var i = 0; i < self.callbacks.length; i++) {
self.callbacks[i].call(self, messages);
}
}
});
};
Filter.prototype.uninstall = function() {
eth.uninstallFilter(this.id)
}
Filter.prototype.messages = function() {
return eth.messages(this.id)
}

View File

@ -0,0 +1,30 @@
// Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301 USA
// this function is included locally, but you can also include separately via a header definition
function request(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = (function(req) {
return function() {
if(req.readyState === 4) {
callback(req);
}
}
})(xhr);
xhr.open('GET', url, true);
xhr.send('');
}

View File

@ -155,7 +155,7 @@ Rectangle {
onLoadingChanged: {
if (loadRequest.status == WebEngineView.LoadSucceededStatus) {
webview.runJavaScript(eth.readFile("bignumber.min.js"));
webview.runJavaScript(eth.readFile("dist/ethereum.js"));
webview.runJavaScript(eth.readFile("ethereum.js/dist/ethereum.js"));
}
}
onJavaScriptConsoleMessage: {

View File

@ -216,3 +216,14 @@ func (a *GetCodeAtArgs) requirements() error {
}
return nil
}
type Sha3Args struct {
Data string
}
func (obj *Sha3Args) UnmarshalJSON(b []byte) (err error) {
if err = json.Unmarshal(b, &obj.Data); err != nil {
return NewErrorResponse(ErrorDecodeArgs)
}
return
}

View File

@ -56,6 +56,20 @@ type RpcRequest struct {
Params []json.RawMessage `json:"params"`
}
func (req *RpcRequest) ToSha3Args() (*Sha3Args, error) {
if len(req.Params) < 1 {
return nil, NewErrorResponse(ErrorArguments)
}
args := new(Sha3Args)
r := bytes.NewReader(req.Params[0])
if err := json.NewDecoder(r).Decode(args); err != nil {
return nil, NewErrorResponse(ErrorDecodeArgs)
}
rpclogger.DebugDetailf("%T %v", args, args)
return args, nil
}
func (req *RpcRequest) ToGetBlockArgs() (*GetBlockArgs, error) {
if len(req.Params) < 1 {
return nil, NewErrorResponse(ErrorArguments)

View File

@ -26,9 +26,11 @@ For each request type, define the following:
package rpc
import (
"fmt"
"math/big"
"strings"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/xeth"
)
@ -161,6 +163,11 @@ func (p *EthereumApi) GetCodeAt(args *GetCodeAtArgs, reply *interface{}) error {
return nil
}
func (p *EthereumApi) Sha3(args *Sha3Args, reply *interface{}) error {
*reply = ethutil.Bytes2Hex(crypto.Sha3(ethutil.Hex2Bytes(args.Data)))
return nil
}
func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error {
// Spec at https://github.com/ethereum/wiki/wiki/Generic-ON-RPC
rpclogger.DebugDetailf("%T %s", req.Params, req.Params)
@ -203,8 +210,14 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
return err
}
return p.GetBlock(args, reply)
case "web3_sha3":
args, err := req.ToSha3Args()
if err != nil {
return err
}
return p.Sha3(args, reply)
default:
return NewErrorResponse(ErrorNotImplemented)
return NewErrorResponse(fmt.Sprintf("%v %s", ErrorNotImplemented, req.Method))
}
rpclogger.DebugDetailf("Reply: %T %s", reply, reply)