From f9cbd16f27e393d4937354ee31435e0a2f689484 Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Fri, 7 Aug 2015 09:56:49 +0200 Subject: support for user agents --- rpc/api/admin.go | 9 +++++++++ rpc/api/net.go | 3 +-- rpc/api/personal.go | 22 +++++++++++----------- rpc/api/personal_args.go | 22 +++++++++++++++------- rpc/api/shh_js.go | 34 ++++++++++++++++++++++++++++++++++ rpc/api/ssh_js.go | 34 ---------------------------------- 6 files changed, 70 insertions(+), 54 deletions(-) create mode 100644 rpc/api/shh_js.go delete mode 100644 rpc/api/ssh_js.go (limited to 'rpc/api') diff --git a/rpc/api/admin.go b/rpc/api/admin.go index 29f342ab6..5e392ae32 100644 --- a/rpc/api/admin.go +++ b/rpc/api/admin.go @@ -37,6 +37,7 @@ import ( "github.com/ethereum/go-ethereum/rpc/codec" "github.com/ethereum/go-ethereum/rpc/comms" "github.com/ethereum/go-ethereum/rpc/shared" + "github.com/ethereum/go-ethereum/rpc/useragent" "github.com/ethereum/go-ethereum/xeth" ) @@ -71,6 +72,7 @@ var ( "admin_httpGet": (*adminApi).HttpGet, "admin_sleepBlocks": (*adminApi).SleepBlocks, "admin_sleep": (*adminApi).Sleep, + "admin_enableUserAgent": (*adminApi).EnableUserAgent, } ) @@ -474,3 +476,10 @@ func (self *adminApi) HttpGet(req *shared.Request) (interface{}, error) { return string(resp), nil } + +func (self *adminApi) EnableUserAgent(req *shared.Request) (interface{}, error) { + if fe, ok := self.xeth.Frontend().(*useragent.RemoteFrontend); ok { + fe.Enable() + } + return true, nil +} diff --git a/rpc/api/net.go b/rpc/api/net.go index 39c230e14..9c6369615 100644 --- a/rpc/api/net.go +++ b/rpc/api/net.go @@ -32,7 +32,7 @@ var ( netMapping = map[string]nethandler{ "net_peerCount": (*netApi).PeerCount, "net_listening": (*netApi).IsListening, - "net_version": (*netApi).Version, + "net_version": (*netApi).Version, } ) @@ -97,4 +97,3 @@ func (self *netApi) IsListening(req *shared.Request) (interface{}, error) { func (self *netApi) Version(req *shared.Request) (interface{}, error) { return self.xeth.NetworkVersion(), nil } - diff --git a/rpc/api/personal.go b/rpc/api/personal.go index e9942c1e5..6c73ac83d 100644 --- a/rpc/api/personal.go +++ b/rpc/api/personal.go @@ -17,6 +17,7 @@ package api import ( + "fmt" "time" "github.com/ethereum/go-ethereum/common" @@ -125,18 +126,17 @@ func (self *personalApi) UnlockAccount(req *shared.Request) (interface{}, error) return nil, shared.NewDecodeParamError(err.Error()) } - var err error + if len(args.Passphrase) == 0 { + fe := self.xeth.Frontend() + if fe == nil { + return false, fmt.Errorf("No password provided") + } + return fe.UnlockAccount(common.HexToAddress(args.Address).Bytes()), nil + } + am := self.ethereum.AccountManager() addr := common.HexToAddress(args.Address) - if args.Duration == -1 { - err = am.Unlock(addr, args.Passphrase) - } else { - err = am.TimedUnlock(addr, args.Passphrase, time.Duration(args.Duration)*time.Second) - } - - if err == nil { - return true, nil - } - return false, err + err := am.TimedUnlock(addr, args.Passphrase, time.Duration(args.Duration)*time.Second) + return err == nil, err } diff --git a/rpc/api/personal_args.go b/rpc/api/personal_args.go index 7f00701e3..5a584fb0c 100644 --- a/rpc/api/personal_args.go +++ b/rpc/api/personal_args.go @@ -86,10 +86,10 @@ func (args *UnlockAccountArgs) UnmarshalJSON(b []byte) (err error) { return shared.NewDecodeParamError(err.Error()) } - args.Duration = -1 + args.Duration = 0 - if len(obj) < 2 { - return shared.NewInsufficientParamsError(len(obj), 2) + if len(obj) < 1 { + return shared.NewInsufficientParamsError(len(obj), 1) } if addrstr, ok := obj[0].(string); ok { @@ -98,10 +98,18 @@ func (args *UnlockAccountArgs) UnmarshalJSON(b []byte) (err error) { return shared.NewInvalidTypeError("address", "not a string") } - if passphrasestr, ok := obj[1].(string); ok { - args.Passphrase = passphrasestr - } else { - return shared.NewInvalidTypeError("passphrase", "not a string") + if len(obj) >= 2 && obj[1] != nil { + if passphrasestr, ok := obj[1].(string); ok { + args.Passphrase = passphrasestr + } else { + return shared.NewInvalidTypeError("passphrase", "not a string") + } + } + + if len(obj) >= 3 && obj[2] != nil { + if duration, ok := obj[2].(float64); ok { + args.Duration = int(duration) + } } return nil diff --git a/rpc/api/shh_js.go b/rpc/api/shh_js.go new file mode 100644 index 000000000..a92ad1644 --- /dev/null +++ b/rpc/api/shh_js.go @@ -0,0 +1,34 @@ +// Copyright 2015 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + +package api + +const Shh_JS = ` +web3._extend({ + property: 'shh', + methods: + [ + + ], + properties: + [ + new web3._extend.Property({ + name: 'version', + getter: 'shh_version' + }) + ] +}); +` diff --git a/rpc/api/ssh_js.go b/rpc/api/ssh_js.go deleted file mode 100644 index a92ad1644..000000000 --- a/rpc/api/ssh_js.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2015 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum 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 Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see . - -package api - -const Shh_JS = ` -web3._extend({ - property: 'shh', - methods: - [ - - ], - properties: - [ - new web3._extend.Property({ - name: 'version', - getter: 'shh_version' - }) - ] -}); -` -- cgit v1.2.3