diff options
author | obscuren <geffobscura@gmail.com> | 2015-01-29 07:24:00 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-01-29 07:24:18 +0800 |
commit | ec85458612e1d5374767f87005dd0ad5934f74d5 (patch) | |
tree | a7e11798765bd56eb088259f2ab4401ec87e4f24 /rpc | |
parent | 73dcbf7ba23ea4d4d87d4261ff7ebaecfe0ec810 (diff) | |
download | dexon-ec85458612e1d5374767f87005dd0ad5934f74d5.tar.gz dexon-ec85458612e1d5374767f87005dd0ad5934f74d5.tar.zst dexon-ec85458612e1d5374767f87005dd0ad5934f74d5.zip |
updated ethereum.js and moved to subfolder
* Previous subtree caused a lot of trouble
* Implemented sha3 in our shiny new http JSON RPC
Diffstat (limited to 'rpc')
-rw-r--r-- | rpc/args.go | 11 | ||||
-rw-r--r-- | rpc/message.go | 14 | ||||
-rw-r--r-- | rpc/packages.go | 15 |
3 files changed, 39 insertions, 1 deletions
diff --git a/rpc/args.go b/rpc/args.go index 8b01cc191..bebd79eb9 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -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 +} diff --git a/rpc/message.go b/rpc/message.go index caf50a6c0..5785fcc87 100644 --- a/rpc/message.go +++ b/rpc/message.go @@ -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) diff --git a/rpc/packages.go b/rpc/packages.go index 5d17a0f90..2c5fbf6be 100644 --- a/rpc/packages.go +++ b/rpc/packages.go @@ -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) |