diff --git a/cmd/console/js.go b/cmd/console/js.go index 4229a95a253e5105959dcd5419ed650040871f2c..76695cabdceacfeac7ff49c703d8bcd1c3507341 100644 --- a/cmd/console/js.go +++ b/cmd/console/js.go @@ -32,12 +32,12 @@ import ( "github.com/ethereum/go-ethereum/common/docserver" re "github.com/ethereum/go-ethereum/jsre" "github.com/ethereum/go-ethereum/rpc" + "github.com/ethereum/go-ethereum/rpc/api" "github.com/ethereum/go-ethereum/rpc/codec" "github.com/ethereum/go-ethereum/rpc/comms" "github.com/ethereum/go-ethereum/rpc/shared" "github.com/peterh/liner" "github.com/robertkrimen/otto" - "github.com/ethereum/go-ethereum/rpc/api" ) type prompter interface { @@ -235,6 +235,7 @@ func (self *jsre) suportedApis(ipcpath string) ([]string, error) { // show summary of current geth instance func (self *jsre) welcome(ipcpath string) { self.re.Eval(`console.log('instance: ' + web3.version.client);`) + self.re.Eval(`console.log(' datadir: ' + admin.datadir);`) self.re.Eval(`console.log("coinbase: " + eth.coinbase);`) self.re.Eval(`var lastBlockTimestamp = 1000 * eth.getBlock(eth.blockNumber).timestamp`) self.re.Eval(`console.log("at block: " + eth.blockNumber + " (" + new Date(lastBlockTimestamp).toLocaleDateString() diff --git a/rpc/api/admin.go b/rpc/api/admin.go index c3746360495cd6f969865b3e4b28c485fd585e91..6b89942b2ace2ab12e3d02c24bdbc89eb5f96e65 100644 --- a/rpc/api/admin.go +++ b/rpc/api/admin.go @@ -25,14 +25,15 @@ var ( AdminMapping = map[string]adminhandler{ // "admin_startRPC": (*adminApi).StartRPC, // "admin_stopRPC": (*adminApi).StopRPC, - "admin_addPeer": (*adminApi).AddPeer, - "admin_peers": (*adminApi).Peers, - "admin_nodeInfo": (*adminApi).NodeInfo, - "admin_exportChain": (*adminApi).ExportChain, - "admin_importChain": (*adminApi).ImportChain, - "admin_verbosity": (*adminApi).Verbosity, - "admin_syncStatus": (*adminApi).SyncStatus, - "admin_setSolc": (*adminApi).SetSolc, + "admin_addPeer": (*adminApi).AddPeer, + "admin_peers": (*adminApi).Peers, + "admin_nodeInfo": (*adminApi).NodeInfo, + "admin_exportChain": (*adminApi).ExportChain, + "admin_importChain": (*adminApi).ImportChain, + "admin_verbosity": (*adminApi).Verbosity, + "admin_chainSyncStatus": (*adminApi).ChainSyncStatus, + "admin_setSolc": (*adminApi).SetSolc, + "admin_datadir": (*adminApi).DataDir, } ) @@ -129,6 +130,10 @@ func (self *adminApi) NodeInfo(req *shared.Request) (interface{}, error) { return self.ethereum.NodeInfo(), nil } +func (self *adminApi) DataDir(req *shared.Request) (interface{}, error) { + return self.ethereum.DataDir, nil +} + func hasAllBlocks(chain *core.ChainManager, bs []*types.Block) bool { for _, b := range bs { if !chain.HasBlock(b.Hash()) { @@ -209,9 +214,9 @@ func (self *adminApi) Verbosity(req *shared.Request) (interface{}, error) { return true, nil } -func (self *adminApi) SyncStatus(req *shared.Request) (interface{}, error) { +func (self *adminApi) ChainSyncStatus(req *shared.Request) (interface{}, error) { pending, cached := self.ethereum.Downloader().Stats() - return map[string]interface{}{"available": pending, "waitingForImport": cached}, nil + return map[string]interface{}{"blocksAvailable": pending, "blocksWaitingForImport": cached}, nil } func (self *adminApi) SetSolc(req *shared.Request) (interface{}, error) { diff --git a/rpc/api/admin_args.go b/rpc/api/admin_args.go index 9c0cbdcb6c974e53f12864aea17a66033b170b5a..56bb57e201393a0f684a0545b0dc81a21e80003a 100644 --- a/rpc/api/admin_args.go +++ b/rpc/api/admin_args.go @@ -3,8 +3,6 @@ package api import ( "encoding/json" - "math/big" - "github.com/ethereum/go-ethereum/rpc/shared" ) @@ -68,16 +66,8 @@ func (args *VerbosityArgs) UnmarshalJSON(b []byte) (err error) { return shared.NewDecodeParamError("Expected enode as argument") } - if levelint, ok := obj[0].(int); ok { - args.Level = levelint - } else if levelstr, ok := obj[0].(string); ok { - if !ok { - return shared.NewInvalidTypeError("level", "not a string") - } - level, success := new(big.Int).SetString(levelstr, 0) - if !success { - return shared.NewDecodeParamError("Unable to parse verbosity level") - } + level, err := numString(obj[0]) + if err == nil { args.Level = int(level.Int64()) } diff --git a/rpc/api/admin_js.go b/rpc/api/admin_js.go index 6255a6c7b99aaacf7328b84543dd75a9e54eae75..c3e713c67d5f25d34233c2f53cc702c6ce43e850 100644 --- a/rpc/api/admin_js.go +++ b/rpc/api/admin_js.go @@ -12,13 +12,6 @@ web3._extend({ inputFormatter: [web3._extend.utils.formatInputString], outputFormatter: web3._extend.formatters.formatOutputBool }), - new web3._extend.Method({ - name: 'peers', - call: 'admin_peers', - params: 0, - inputFormatter: [], - outputFormatter: function(obj) { return obj; } - }), new web3._extend.Method({ name: 'exportChain', call: 'admin_exportChain', @@ -40,13 +33,6 @@ web3._extend({ inputFormatter: [web3._extend.utils.formatInputInt], outputFormatter: web3._extend.formatters.formatOutputBool }), - new web3._extend.Method({ - name: 'syncStatus', - call: 'admin_syncStatus', - params: 1, - inputFormatter: [web3._extend.utils.formatInputInt], - outputFormatter: function(obj) { return obj; } - }), new web3._extend.Method({ name: 'setSolc', call: 'admin_setSolc', @@ -61,6 +47,21 @@ web3._extend({ name: 'nodeInfo', getter: 'admin_nodeInfo', outputFormatter: web3._extend.formatters.formatOutputString + }), + new web3._extend.Property({ + name: 'peers', + getter: 'admin_peers', + outputFormatter: function(obj) { return obj; } + }), + new web3._extend.Property({ + name: 'datadir', + getter: 'admin_datadir', + outputFormatter: web3._extend.formatters.formatOutputString + }), + new web3._extend.Property({ + name: 'chainSyncStatus', + getter: 'admin_chainSyncStatus', + outputFormatter: function(obj) { return obj; } }) ] }); diff --git a/rpc/api/miner_args.go b/rpc/api/miner_args.go index 6b3d16d4831d3e454ba47a2b574349b789a2cf75..7b0560c1637c131c4eec3f30ec3739aa2d1b8876 100644 --- a/rpc/api/miner_args.go +++ b/rpc/api/miner_args.go @@ -41,6 +41,10 @@ func (args *SetExtraArgs) UnmarshalJSON(b []byte) (err error) { return shared.NewDecodeParamError(err.Error()) } + if len(obj) < 1 { + return shared.NewInsufficientParamsError(len(obj), 1) + } + extrastr, ok := obj[0].(string) if !ok { return shared.NewInvalidTypeError("Price", "not a string") @@ -60,13 +64,16 @@ func (args *GasPriceArgs) UnmarshalJSON(b []byte) (err error) { return shared.NewDecodeParamError(err.Error()) } - pricestr, ok := obj[0].(string) - if !ok { - return shared.NewInvalidTypeError("Price", "not a string") + if len(obj) < 1 { + return shared.NewInsufficientParamsError(len(obj), 1) } - args.Price = pricestr - return nil + if pricestr, ok := obj[0].(string); ok { + args.Price = pricestr + return nil + } + + return shared.NewInvalidTypeError("Price", "not a string") } type MakeDAGArgs struct { diff --git a/rpc/api/miner_js.go b/rpc/api/miner_js.go index bcf92f6a7c9ce5ee534f595b72837f24bfed2873..6290368da3af75fabda3de4b52824621c4ee9f1d 100644 --- a/rpc/api/miner_js.go +++ b/rpc/api/miner_js.go @@ -19,13 +19,6 @@ web3._extend({ inputFormatter: [web3._extend.formatters.formatInputInt], outputFormatter: web3._extend.formatters.formatOutputBool }), - new web3._extend.Method({ - name: 'getHashrate', - call: 'miner_hashrate', - params: 0, - inputFormatter: [], - outputFormatter: web3._extend.utils.toDecimal - }), new web3._extend.Method({ name: 'setExtra', call: 'miner_setExtra', diff --git a/rpc/api/net.go b/rpc/api/net.go index efc4007850fb71156d5c9e37bb58da80adf4583a..6f5d55f12f16536ec74a1c5407b49d8cdbcb898f 100644 --- a/rpc/api/net.go +++ b/rpc/api/net.go @@ -10,7 +10,7 @@ import ( var ( // mapping between methods and handlers netMapping = map[string]nethandler{ - "net_id": (*netApi).NetworkVersion, + "net_version": (*netApi).Version, "net_peerCount": (*netApi).PeerCount, "net_listening": (*netApi).IsListening, "net_peers": (*netApi).Peers, @@ -63,7 +63,7 @@ func (self *netApi) Name() string { } // Network version -func (self *netApi) NetworkVersion(req *shared.Request) (interface{}, error) { +func (self *netApi) Version(req *shared.Request) (interface{}, error) { return self.xeth.NetworkVersion(), nil } diff --git a/rpc/api/net_js.go b/rpc/api/net_js.go index 75f6c89f311e5f3db7d27cab3b8c66fc0e7556a4..1677d9fa6454fd970c447c653eb98a6b126331b5 100644 --- a/rpc/api/net_js.go +++ b/rpc/api/net_js.go @@ -12,26 +12,12 @@ web3._extend({ inputFormatter: [web3._extend.utils.formatInputString], outputFormatter: web3._extend.formatters.formatOutputBool }), - new web3._extend.Method({ - name: 'id', - call: 'net_id', - params: 0, - inputFormatter: [], - outputFormatter: web3._extend.formatters.formatOutputString - }), new web3._extend.Method({ name: 'getPeerCount', call: 'net_peerCount', params: 0, inputFormatter: [], outputFormatter: web3._extend.formatters.formatOutputString - }), - new web3._extend.Method({ - name: 'peers', - call: 'net_peers', - params: 0, - inputFormatter: [], - outputFormatter: function(obj) { return obj; } }) ], properties: @@ -45,6 +31,16 @@ web3._extend({ name: 'peerCount', getter: 'net_peerCount', outputFormatter: web3._extend.utils.toDecimal + }), + new web3._extend.Property({ + name: 'peers', + getter: 'net_peers', + outputFormatter: function(obj) { return obj; } + }), + new web3._extend.Property({ + name: 'version', + getter: 'net_version', + outputFormatter: web3._extend.formatters.formatOutputString }) ] }); diff --git a/rpc/api/personal_args.go b/rpc/api/personal_args.go index b41fc06e79d2a12915834cc5de7d31bbbecdee59..b3e683638a062a98a85c50767ec28868c1046769 100644 --- a/rpc/api/personal_args.go +++ b/rpc/api/personal_args.go @@ -16,13 +16,16 @@ func (args *NewAccountArgs) UnmarshalJSON(b []byte) (err error) { return shared.NewDecodeParamError(err.Error()) } - passhrase, ok := obj[0].(string) - if !ok { - return shared.NewInvalidTypeError("passhrase", "not a string") + if len(obj) < 1 { + return shared.NewInsufficientParamsError(len(obj), 1) } - args.Passphrase = passhrase - return nil + if passhrase, ok := obj[0].(string); ok { + args.Passphrase = passhrase + return nil + } + + return shared.NewInvalidTypeError("passhrase", "not a string") } type DeleteAccountArgs struct { @@ -36,17 +39,21 @@ func (args *DeleteAccountArgs) UnmarshalJSON(b []byte) (err error) { return shared.NewDecodeParamError(err.Error()) } - addr, ok := obj[0].(string) - if !ok { + if len(obj) < 2 { + return shared.NewInsufficientParamsError(len(obj), 2) + } + + if addr, ok := obj[0].(string); ok { + args.Address = addr + } else { return shared.NewInvalidTypeError("address", "not a string") } - args.Address = addr - passhrase, ok := obj[1].(string) - if !ok { + if passhrase, ok := obj[1].(string); ok { + args.Passphrase = passhrase + } else { return shared.NewInvalidTypeError("passhrase", "not a string") } - args.Passphrase = passhrase return nil } @@ -65,17 +72,21 @@ func (args *UnlockAccountArgs) UnmarshalJSON(b []byte) (err error) { args.Duration = -1 - addrstr, ok := obj[0].(string) - if !ok { + if len(obj) < 2 { + return shared.NewInsufficientParamsError(len(obj), 2) + } + + if addrstr, ok := obj[0].(string); ok { + args.Address = addrstr + } else { return shared.NewInvalidTypeError("address", "not a string") } - args.Address = addrstr - passphrasestr, ok := obj[1].(string) - if !ok { + if passphrasestr, ok := obj[1].(string); ok { + args.Passphrase = passphrasestr + } else { return shared.NewInvalidTypeError("passphrase", "not a string") } - args.Passphrase = passphrasestr return nil } diff --git a/rpc/api/personal_js.go b/rpc/api/personal_js.go index f9fa60e78a7a1f9f9b8f8cd0933970cbfd691815..ddd47f6a4e68fb8d374b215c775bd3648af6e27f 100644 --- a/rpc/api/personal_js.go +++ b/rpc/api/personal_js.go @@ -5,13 +5,6 @@ web3._extend({ property: 'personal', methods: [ - new web3._extend.Method({ - name: 'listAccounts', - call: 'personal_listAccounts', - params: 0, - inputFormatter: [], - outputFormatter: function(obj) { return obj; } - }), new web3._extend.Method({ name: 'newAccount', call: 'personal_newAccount', @@ -29,6 +22,11 @@ web3._extend({ ], properties: [ + new web3._extend.Property({ + name: 'accounts', + getter: 'personal_listAccounts', + outputFormatter: function(obj) { return obj; } + }) ] }); `