From 83ee39448e0f23d42dff27bccde27f828afa3707 Mon Sep 17 00:00:00 2001 From: zelig Date: Tue, 23 Jun 2015 15:48:33 +0100 Subject: Registrar and contractInfo handling * resolver -> common/registrar * global registrar name registry interface * add Call to resolver backend interface * the hashReg and UrlHing contracts now initialised from global registry * initialization of contracts uniform * improve errors and more econsistent method names * common/registrar/ethreg: versioned registrar * integrate new naming and registrar in natspec * js console api: setGlobalRegistrar, setHashReg, setUrlHint * js test TestContract uses mining - tests fixed all pass * eth/backend: allow PoW test mode (small ethash DAG) * console jsre refers to resolver.abi/addr, * cmd/geth/contracts.go moved to common/registrar --- rpc/api/admin.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ rpc/api/admin_args.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) (limited to 'rpc/api') diff --git a/rpc/api/admin.go b/rpc/api/admin.go index b27482cfe..78c75a60b 100644 --- a/rpc/api/admin.go +++ b/rpc/api/admin.go @@ -3,7 +3,9 @@ package api import ( "fmt" "io" + "math/big" "os" + "time" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" @@ -244,3 +246,49 @@ func (self *adminApi) StopRPC(req *shared.Request) (interface{}, error) { comms.StopHttp() return true, nil } + +func (self *adminApi) SleepBlocks(req *shared.Request) (interface{}, error) { + args := new(SleepBlocksArgs) + if err := self.coder.Decode(req.Params, &args); err != nil { + return nil, shared.NewDecodeParamError(err.Error()) + } + var timer <-chan time.Time + var height *big.Int + var err error + if args.Timeout > 0 { + timer = time.NewTimer(time.Duration(args.Timeout) * time.Second).C + } + + height = new(big.Int).Add(self.xeth.CurrentBlock().Number(), big.NewInt(args.N)) + height, err = sleepBlocks(self.xeth.UpdateState(), height, timer) + if err != nil { + return nil, err + } + return height.Uint64(), nil +} + +func sleepBlocks(wait chan *big.Int, height *big.Int, timer <-chan time.Time) (newHeight *big.Int, err error) { + wait <- height + select { + case <-timer: + // if times out make sure the xeth loop does not block + go func() { + select { + case wait <- nil: + case <-wait: + } + }() + return nil, fmt.Errorf("timeout") + case newHeight = <-wait: + } + return +} + +// sec, err := call.Argument(0).ToInteger() +// if err != nil { +// fmt.Println(err) +// return otto.FalseValue() +// } +// time.Sleep(time.Duration(sec) * time.Second) +// return otto.UndefinedValue() +// } diff --git a/rpc/api/admin_args.go b/rpc/api/admin_args.go index 5437971ca..7aee5d678 100644 --- a/rpc/api/admin_args.go +++ b/rpc/api/admin_args.go @@ -147,3 +147,34 @@ func (args *StartRPCArgs) UnmarshalJSON(b []byte) (err error) { return nil } + +type SleepBlocksArgs struct { + N int64 + Timeout int64 +} + +func (args *SleepBlocksArgs) UnmarshalJSON(b []byte) (err error) { + var obj []interface{} + if err := json.Unmarshal(b, &obj); err != nil { + return shared.NewDecodeParamError(err.Error()) + } + + args.N = 1 + args.Timeout = 0 + if len(obj) >= 1 { + if n, ok := obj[0].(int64); ok { + args.N = n + } else { + return shared.NewInvalidTypeError("N", "not an integer") + } + } + + if len(obj) >= 2 { + if n, ok := obj[1].(int64); ok { + args.N = n + } else { + return shared.NewInvalidTypeError("Timeout", "not an integer") + } + } + return nil +} -- cgit v1.2.3 From 27392337198b9287e9f6fe615510a1f30099e3d7 Mon Sep 17 00:00:00 2001 From: zelig Date: Tue, 23 Jun 2015 15:48:33 +0100 Subject: Registrar and contractInfo handling * resolver -> common/registrar * global registrar name registry interface * add Call to resolver backend interface * the hashReg and UrlHing contracts now initialised from global registry * initialization of contracts uniform * improve errors and more econsistent method names * common/registrar/ethreg: versioned registrar * integrate new naming and registrar in natspec * js console api: setGlobalRegistrar, setHashReg, setUrlHint * js test TestContract uses mining - tests fixed all pass * eth/backend: allow PoW test mode (small ethash DAG) * console jsre refers to resolver.abi/addr, * cmd/geth/contracts.go moved to common/registrar --- rpc/api/admin.go | 185 ++++++++++++++++++++++++++++++++-- rpc/api/admin_args.go | 272 +++++++++++++++++++++++++++++++++++++++++++++++++- rpc/api/admin_js.go | 64 ++++++++++++ 3 files changed, 508 insertions(+), 13 deletions(-) (limited to 'rpc/api') diff --git a/rpc/api/admin.go b/rpc/api/admin.go index 78c75a60b..40199caa9 100644 --- a/rpc/api/admin.go +++ b/rpc/api/admin.go @@ -7,8 +7,14 @@ import ( "os" "time" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/compiler" + "github.com/ethereum/go-ethereum/common/docserver" + "github.com/ethereum/go-ethereum/common/natspec" + "github.com/ethereum/go-ethereum/common/registrar" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/rlp" @@ -26,17 +32,27 @@ const ( var ( // mapping between methods and handlers AdminMapping = map[string]adminhandler{ - "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, - "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_chainSyncStatus": (*adminApi).ChainSyncStatus, + "admin_setSolc": (*adminApi).SetSolc, + "admin_datadir": (*adminApi).DataDir, + "admin_startRPC": (*adminApi).StartRPC, + "admin_stopRPC": (*adminApi).StopRPC, + "admin_setGlobalRegistrar": (*adminApi).SetGlobalRegistrar, + "admin_setHashReg": (*adminApi).SetHashReg, + "admin_setUrlHint": (*adminApi).SetUrlHint, + "admin_saveInfo": (*adminApi).SaveInfo, + "admin_register": (*adminApi).Register, + "admin_registerUrl": (*adminApi).RegisterUrl, + "admin_startNatSpec": (*adminApi).StartNatSpec, + "admin_stopNatSpec": (*adminApi).StopNatSpec, + "admin_getContractInfo": (*adminApi).GetContractInfo, + "admin_httpGet": (*adminApi).HttpGet, } ) @@ -49,6 +65,7 @@ type adminApi struct { ethereum *eth.Ethereum codec codec.Codec coder codec.ApiCoder + ds *docserver.DocServer } // create a new admin api instance @@ -58,6 +75,7 @@ func NewAdminApi(xeth *xeth.XEth, ethereum *eth.Ethereum, codec codec.Codec) *ad ethereum: ethereum, codec: codec, coder: codec.New(nil), + ds: docserver.New("/"), } } @@ -292,3 +310,148 @@ func sleepBlocks(wait chan *big.Int, height *big.Int, timer <-chan time.Time) (n // time.Sleep(time.Duration(sec) * time.Second) // return otto.UndefinedValue() // } +func (self *adminApi) SetGlobalRegistrar(req *shared.Request) (interface{}, error) { + args := new(SetGlobalRegistrarArgs) + if err := self.coder.Decode(req.Params, &args); err != nil { + return nil, shared.NewDecodeParamError(err.Error()) + } + + sender := common.HexToAddress(args.ContractAddress) + + reg := registrar.New(self.xeth) + err := reg.SetGlobalRegistrar(args.NameReg, sender) + if err != nil { + return false, err + } + + return registrar.GlobalRegistrarAddr, nil +} + +func (self *adminApi) SetHashReg(req *shared.Request) (interface{}, error) { + args := new(SetHashRegArgs) + if err := self.coder.Decode(req.Params, &args); err != nil { + return nil, shared.NewDecodeParamError(err.Error()) + } + + reg := registrar.New(self.xeth) + sender := common.HexToAddress(args.Sender) + err := reg.SetHashReg(args.HashReg, sender) + if err != nil { + return false, err + } + + return registrar.HashRegAddr, nil +} + +func (self *adminApi) SetUrlHint(req *shared.Request) (interface{}, error) { + args := new(SetUrlHintArgs) + if err := self.coder.Decode(req.Params, &args); err != nil { + return nil, shared.NewDecodeParamError(err.Error()) + } + + urlHint := args.UrlHint + sender := common.HexToAddress(args.Sender) + + reg := registrar.New(self.xeth) + err := reg.SetUrlHint(urlHint, sender) + if err != nil { + return nil, err + } + + return registrar.UrlHintAddr, nil +} + +func (self *adminApi) SaveInfo(req *shared.Request) (interface{}, error) { + args := new(SaveInfoArgs) + if err := self.coder.Decode(req.Params, &args); err != nil { + return nil, shared.NewDecodeParamError(err.Error()) + } + + contenthash, err := compiler.SaveInfo(&args.ContractInfo, args.Filename) + if err != nil { + return nil, err + } + + return contenthash.Hex(), nil +} + +func (self *adminApi) Register(req *shared.Request) (interface{}, error) { + args := new(RegisterArgs) + if err := self.coder.Decode(req.Params, &args); err != nil { + return nil, shared.NewDecodeParamError(err.Error()) + } + + sender := common.HexToAddress(args.Sender) + // sender and contract address are passed as hex strings + codeb := self.xeth.CodeAtBytes(args.Address) + codeHash := common.BytesToHash(crypto.Sha3(codeb)) + contentHash := common.HexToHash(args.ContentHashHex) + registry := registrar.New(self.xeth) + + _, err := registry.SetHashToHash(sender, codeHash, contentHash) + if err != nil { + return false, err + } + + return true, nil +} + +func (self *adminApi) RegisterUrl(req *shared.Request) (interface{}, error) { + args := new(RegisterUrlArgs) + if err := self.coder.Decode(req.Params, &args); err != nil { + return nil, shared.NewDecodeParamError(err.Error()) + } + + sender := common.HexToAddress(args.Sender) + registry := registrar.New(self.xeth) + _, err := registry.SetUrlToHash(sender, common.HexToHash(args.ContentHash), args.Url) + if err != nil { + return false, err + } + + return true, nil +} + +func (self *adminApi) StartNatSpec(req *shared.Request) (interface{}, error) { + self.ethereum.NatSpec = true + return true, nil +} + +func (self *adminApi) StopNatSpec(req *shared.Request) (interface{}, error) { + self.ethereum.NatSpec = false + return true, nil +} + +func (self *adminApi) GetContractInfo(req *shared.Request) (interface{}, error) { + args := new(GetContractInfoArgs) + if err := self.coder.Decode(req.Params, &args); err != nil { + return nil, shared.NewDecodeParamError(err.Error()) + } + + infoDoc, err := natspec.FetchDocsForContract(args.Contract, self.xeth, self.ds) + if err != nil { + return nil, err + } + + var info interface{} + err = self.coder.Decode(infoDoc, &info) + if err != nil { + return nil, err + } + + return info, nil +} + +func (self *adminApi) HttpGet(req *shared.Request) (interface{}, error) { + args := new(HttpGetArgs) + if err := self.coder.Decode(req.Params, &args); err != nil { + return nil, shared.NewDecodeParamError(err.Error()) + } + + resp, err := self.ds.Get(args.Uri, args.Path) + if err != nil { + return nil, err + } + + return string(resp), nil +} diff --git a/rpc/api/admin_args.go b/rpc/api/admin_args.go index 7aee5d678..a4d692c0a 100644 --- a/rpc/api/admin_args.go +++ b/rpc/api/admin_args.go @@ -3,6 +3,7 @@ package api import ( "encoding/json" + "github.com/ethereum/go-ethereum/common/compiler" "github.com/ethereum/go-ethereum/rpc/shared" ) @@ -154,6 +155,7 @@ type SleepBlocksArgs struct { } func (args *SleepBlocksArgs) UnmarshalJSON(b []byte) (err error) { + var obj []interface{} if err := json.Unmarshal(b, &obj); err != nil { return shared.NewDecodeParamError(err.Error()) @@ -171,10 +173,276 @@ func (args *SleepBlocksArgs) UnmarshalJSON(b []byte) (err error) { if len(obj) >= 2 { if n, ok := obj[1].(int64); ok { - args.N = n + args.Timeout = n + } else { + return shared.NewInvalidTypeError("N", "not an integer") + } + } + + return nil +} + +type SetGlobalRegistrarArgs struct { + NameReg string + ContractAddress string +} + +func (args *SetGlobalRegistrarArgs) UnmarshalJSON(b []byte) (err error) { + var obj []interface{} + if err := json.Unmarshal(b, &obj); err != nil { + return shared.NewDecodeParamError(err.Error()) + } + + if len(obj) == 0 { + return shared.NewDecodeParamError("Expected namereg address") + } + + if len(obj) >= 1 { + if namereg, ok := obj[0].(string); ok { + args.NameReg = namereg + } else { + return shared.NewInvalidTypeError("NameReg", "not a string") + } + } + + if len(obj) >= 2 { + if addr, ok := obj[1].(string); ok { + args.ContractAddress = addr + } else { + return shared.NewInvalidTypeError("ContractAddress", "not a string") + } + } + + return nil +} + +type SetHashRegArgs struct { + HashReg string + Sender string +} + +func (args *SetHashRegArgs) UnmarshalJSON(b []byte) (err error) { + var obj []interface{} + if err := json.Unmarshal(b, &obj); err != nil { + return shared.NewDecodeParamError(err.Error()) + } + + if len(obj) >= 1 { + if hashreg, ok := obj[0].(string); ok { + args.HashReg = hashreg + } else { + return shared.NewInvalidTypeError("HashReg", "not a string") + } + } + + if len(obj) >= 2 { + if sender, ok := obj[1].(string); ok { + args.Sender = sender + } else { + return shared.NewInvalidTypeError("Sender", "not a string") + } + } + + return nil +} + +type SetUrlHintArgs struct { + UrlHint string + Sender string +} + +func (args *SetUrlHintArgs) UnmarshalJSON(b []byte) (err error) { + var obj []interface{} + if err := json.Unmarshal(b, &obj); err != nil { + return shared.NewDecodeParamError(err.Error()) + } + + if len(obj) >= 1 { + if urlhint, ok := obj[0].(string); ok { + args.UrlHint = urlhint + } else { + return shared.NewInvalidTypeError("UrlHint", "not a string") + } + } + + if len(obj) >= 2 { + if sender, ok := obj[1].(string); ok { + args.Sender = sender + } else { + return shared.NewInvalidTypeError("Sender", "not a string") + } + } + + return nil +} + +type SaveInfoArgs struct { + ContractInfo compiler.ContractInfo + Filename string +} + +func (args *SaveInfoArgs) UnmarshalJSON(b []byte) (err error) { + var obj []interface{} + if err := json.Unmarshal(b, &obj); err != nil { + return shared.NewDecodeParamError(err.Error()) + } + + if len(obj) < 2 { + return shared.NewInsufficientParamsError(len(obj), 2) + } + + if jsonraw, err := json.Marshal(obj[0]); err == nil { + if err = json.Unmarshal(jsonraw, &args.ContractInfo); err != nil { + return err + } + } else { + return err + } + + if filename, ok := obj[1].(string); ok { + args.Filename = filename + } else { + return shared.NewInvalidTypeError("Filename", "not a string") + } + + return nil +} + +type RegisterArgs struct { + Sender string + Address string + ContentHashHex string +} + +func (args *RegisterArgs) UnmarshalJSON(b []byte) (err error) { + var obj []interface{} + if err := json.Unmarshal(b, &obj); err != nil { + return shared.NewDecodeParamError(err.Error()) + } + + if len(obj) < 3 { + return shared.NewInsufficientParamsError(len(obj), 3) + } + + if len(obj) >= 1 { + if sender, ok := obj[0].(string); ok { + args.Sender = sender + } else { + return shared.NewInvalidTypeError("Sender", "not a string") + } + } + + if len(obj) >= 2 { + if address, ok := obj[1].(string); ok { + args.Address = address + } else { + return shared.NewInvalidTypeError("Address", "not a string") + } + } + + if len(obj) >= 3 { + if hex, ok := obj[2].(string); ok { + args.ContentHashHex = hex + } else { + return shared.NewInvalidTypeError("ContentHashHex", "not a string") + } + } + + return nil +} + +type RegisterUrlArgs struct { + Sender string + ContentHash string + Url string +} + +func (args *RegisterUrlArgs) UnmarshalJSON(b []byte) (err error) { + var obj []interface{} + if err := json.Unmarshal(b, &obj); err != nil { + return shared.NewDecodeParamError(err.Error()) + } + + if len(obj) >= 1 { + if sender, ok := obj[1].(string); ok { + args.Sender = sender + } else { + return shared.NewInvalidTypeError("Sender", "not a string") + } + } + + if sender, ok := obj[1].(string); ok { + args.ContentHash = sender + } else { + return shared.NewInvalidTypeError("ContentHash", "not a string") + } + + if len(obj) >= 3 { + if sender, ok := obj[2].(string); ok { + args.Url = sender + } else { + return shared.NewInvalidTypeError("Url", "not a string") + } + } + + return nil +} + +type GetContractInfoArgs struct { + Contract string +} + +func (args *GetContractInfoArgs) UnmarshalJSON(b []byte) (err error) { + var obj []interface{} + if err := json.Unmarshal(b, &obj); err != nil { + return shared.NewDecodeParamError(err.Error()) + } + + if len(obj) < 1 { + return shared.NewInsufficientParamsError(len(obj), 1) + } + + if len(obj) >= 1 { + if contract, ok := obj[0].(string); ok { + args.Contract = contract } else { - return shared.NewInvalidTypeError("Timeout", "not an integer") + return shared.NewInvalidTypeError("Contract", "not a string") } } + + return nil +} + +type HttpGetArgs struct { + Uri string + Path string +} + +func (args *HttpGetArgs) UnmarshalJSON(b []byte) (err error) { + var obj []interface{} + if err := json.Unmarshal(b, &obj); err != nil { + return shared.NewDecodeParamError(err.Error()) + } + + if len(obj) < 1 { + return shared.NewInsufficientParamsError(len(obj), 1) + } + + if len(obj) >= 1 { + if uri, ok := obj[0].(string); ok { + args.Uri = uri + } else { + return shared.NewInvalidTypeError("Uri", "not a string") + } + } + + if len(obj) >= 2 { + if path, ok := obj[1].(string); ok { + args.Path = path + } else { + return shared.NewInvalidTypeError("Path", "not a string") + } + } + return nil } diff --git a/rpc/api/admin_js.go b/rpc/api/admin_js.go index 97642ade7..1f822f2c7 100644 --- a/rpc/api/admin_js.go +++ b/rpc/api/admin_js.go @@ -53,7 +53,71 @@ web3._extend({ params: 0, inputFormatter: [], outputFormatter: web3._extend.formatters.formatOutputBool + }), + new web3._extend.Method({ + name: 'setGlobalRegistrar', + call: 'admin_setGlobalRegistrar', + params: 2, + inputFormatter: [web3._extend.utils.formatInputString,web3._extend.utils.formatInputString], + outputFormatter: web3._extend.formatters.formatOutputString + }), + new web3._extend.Method({ + name: 'setHashReg', + call: 'admin_setHashReg', + params: 2, + inputFormatter: [web3._extend.utils.formatInputString,web3._extend.utils.formatInputString], + outputFormatter: web3._extend.formatters.formatOutputString + }), + new web3._extend.Method({ + name: 'saveInfo', + call: 'admin_saveInfo', + params: 2, + inputFormatter: [function(obj) { return obj; },web3._extend.utils.formatInputString], + outputFormatter: web3._extend.formatters.formatOutputString + }), + new web3._extend.Method({ + name: 'register', + call: 'admin_register', + params: 2, + inputFormatter: [web3._extend.utils.formatInputString,web3._extend.utils.formatInputString], + outputFormatter: web3._extend.formatters.formatOutputBool + }), + new web3._extend.Method({ + name: 'registerUrl', + call: 'admin_registerUrl', + params: 3, + inputFormatter: [web3._extend.utils.formatInputString,web3._extend.utils.formatInputString,web3._extend.utils.formatInputString], + outputFormatter: web3._extend.formatters.formatOutputBool + }), + new web3._extend.Method({ + name: 'StartNatSpec', + call: 'admin_startNatSpec', + params: 0, + inputFormatter: [], + outputFormatter: web3._extend.formatters.formatOutputBool + }), + new web3._extend.Method({ + name: 'StopNatSpec', + call: 'admin_stopNatSpec', + params: 0, + inputFormatter: [], + outputFormatter: web3._extend.formatters.formatOutputBool + }), + new web3._extend.Method({ + name: 'getContractInfo', + call: 'admin_getContractInfo', + params: 1, + inputFormatter: [web3._extend.utils.formatInputString], + outputFormatter: function(obj) { return json.parse(obj); } + }), + new web3._extend.Method({ + name: 'httpGet', + call: 'admin_httpGet', + params: 2, + inputFormatter: [web3._extend.utils.formatInputString,web3._extend.utils.formatInputString], + outputFormatter: web3._extend.formatters.formatOutputString }) + ], properties: [ -- cgit v1.2.3 From 6391ec0c8f5ea645d772ede9f4c6fbda3d84105f Mon Sep 17 00:00:00 2001 From: zelig Date: Tue, 30 Jun 2015 16:39:31 +0100 Subject: add missing method to api/admin --- rpc/api/admin.go | 1 + rpc/api/admin_js.go | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'rpc/api') diff --git a/rpc/api/admin.go b/rpc/api/admin.go index 40199caa9..0230937fa 100644 --- a/rpc/api/admin.go +++ b/rpc/api/admin.go @@ -43,6 +43,7 @@ var ( "admin_datadir": (*adminApi).DataDir, "admin_startRPC": (*adminApi).StartRPC, "admin_stopRPC": (*adminApi).StopRPC, + "admin_sleepBlocks": (*adminApi).SleepBlocks, "admin_setGlobalRegistrar": (*adminApi).SetGlobalRegistrar, "admin_setHashReg": (*adminApi).SetHashReg, "admin_setUrlHint": (*adminApi).SetUrlHint, diff --git a/rpc/api/admin_js.go b/rpc/api/admin_js.go index 1f822f2c7..17be63575 100644 --- a/rpc/api/admin_js.go +++ b/rpc/api/admin_js.go @@ -26,6 +26,13 @@ web3._extend({ inputFormatter: [web3._extend.utils.formatInputString], outputFormatter: function(obj) { return obj; } }), + new web3._extend.Method({ + name: 'sleepBlocks', + call: 'admin_sleepBlocks', + params: 2, + inputFormatter: [web3._extend.utils.formatInputInt,web3._extend.utils.formatInputInt], + outputFormatter: web3._extend.formatters.formatOutputInt + }), new web3._extend.Method({ name: 'verbosity', call: 'admin_verbosity', @@ -68,6 +75,13 @@ web3._extend({ inputFormatter: [web3._extend.utils.formatInputString,web3._extend.utils.formatInputString], outputFormatter: web3._extend.formatters.formatOutputString }), + new web3._extend.Method({ + name: 'setUrlHint', + call: 'admin_setUrlHint', + params: 2, + inputFormatter: [web3._extend.utils.formatInputString,web3._extend.utils.formatInputString], + outputFormatter: web3._extend.formatters.formatOutputString + }), new web3._extend.Method({ name: 'saveInfo', call: 'admin_saveInfo', @@ -90,14 +104,14 @@ web3._extend({ outputFormatter: web3._extend.formatters.formatOutputBool }), new web3._extend.Method({ - name: 'StartNatSpec', + name: 'startNatSpec', call: 'admin_startNatSpec', params: 0, inputFormatter: [], outputFormatter: web3._extend.formatters.formatOutputBool }), new web3._extend.Method({ - name: 'StopNatSpec', + name: 'stopNatSpec', call: 'admin_stopNatSpec', params: 0, inputFormatter: [], -- cgit v1.2.3 From 518dc87db3dd09aed21f255f448f95dcc746dc12 Mon Sep 17 00:00:00 2001 From: zelig Date: Thu, 2 Jul 2015 16:38:48 +0100 Subject: fix sleepBlocks, implement sleep --- rpc/api/admin.go | 20 +++++++++++--------- rpc/api/admin_args.go | 40 ++++++++++++++++++++++++++++++++-------- rpc/api/admin_js.go | 2 +- 3 files changed, 44 insertions(+), 18 deletions(-) (limited to 'rpc/api') diff --git a/rpc/api/admin.go b/rpc/api/admin.go index 0230937fa..5d214e8d8 100644 --- a/rpc/api/admin.go +++ b/rpc/api/admin.go @@ -43,7 +43,6 @@ var ( "admin_datadir": (*adminApi).DataDir, "admin_startRPC": (*adminApi).StartRPC, "admin_stopRPC": (*adminApi).StopRPC, - "admin_sleepBlocks": (*adminApi).SleepBlocks, "admin_setGlobalRegistrar": (*adminApi).SetGlobalRegistrar, "admin_setHashReg": (*adminApi).SetHashReg, "admin_setUrlHint": (*adminApi).SetUrlHint, @@ -54,6 +53,8 @@ var ( "admin_stopNatSpec": (*adminApi).StopNatSpec, "admin_getContractInfo": (*adminApi).GetContractInfo, "admin_httpGet": (*adminApi).HttpGet, + "admin_sleepBlocks": (*adminApi).SleepBlocks, + "admin_sleep": (*adminApi).Sleep, } ) @@ -303,14 +304,15 @@ func sleepBlocks(wait chan *big.Int, height *big.Int, timer <-chan time.Time) (n return } -// sec, err := call.Argument(0).ToInteger() -// if err != nil { -// fmt.Println(err) -// return otto.FalseValue() -// } -// time.Sleep(time.Duration(sec) * time.Second) -// return otto.UndefinedValue() -// } +func (self *adminApi) Sleep(req *shared.Request) (interface{}, error) { + args := new(SleepArgs) + if err := self.coder.Decode(req.Params, &args); err != nil { + return nil, shared.NewDecodeParamError(err.Error()) + } + time.Sleep(time.Duration(args.S) * time.Second) + return nil, nil +} + func (self *adminApi) SetGlobalRegistrar(req *shared.Request) (interface{}, error) { args := new(SetGlobalRegistrarArgs) if err := self.coder.Decode(req.Params, &args); err != nil { diff --git a/rpc/api/admin_args.go b/rpc/api/admin_args.go index a4d692c0a..e7548c7be 100644 --- a/rpc/api/admin_args.go +++ b/rpc/api/admin_args.go @@ -149,6 +149,30 @@ func (args *StartRPCArgs) UnmarshalJSON(b []byte) (err error) { return nil } +type SleepArgs struct { + S int +} + +func (args *SleepArgs) UnmarshalJSON(b []byte) (err error) { + + var obj []interface{} + if err := json.Unmarshal(b, &obj); err != nil { + return shared.NewDecodeParamError(err.Error()) + } + if len(obj) >= 1 { + if obj[0] != nil { + if n, err := numString(obj[0]); err == nil { + args.S = int(n.Int64()) + } else { + return shared.NewInvalidTypeError("N", "not an integer: "+err.Error()) + } + } else { + return shared.NewInsufficientParamsError(0, 1) + } + } + return nil +} + type SleepBlocksArgs struct { N int64 Timeout int64 @@ -163,19 +187,19 @@ func (args *SleepBlocksArgs) UnmarshalJSON(b []byte) (err error) { args.N = 1 args.Timeout = 0 - if len(obj) >= 1 { - if n, ok := obj[0].(int64); ok { - args.N = n + if len(obj) >= 1 && obj[0] != nil { + if n, err := numString(obj[0]); err == nil { + args.N = n.Int64() } else { - return shared.NewInvalidTypeError("N", "not an integer") + return shared.NewInvalidTypeError("N", "not an integer: "+err.Error()) } } - if len(obj) >= 2 { - if n, ok := obj[1].(int64); ok { - args.Timeout = n + if len(obj) >= 2 && obj[1] != nil { + if n, err := numString(obj[1]); err == nil { + args.Timeout = n.Int64() } else { - return shared.NewInvalidTypeError("N", "not an integer") + return shared.NewInvalidTypeError("Timeout", "not an integer: "+err.Error()) } } diff --git a/rpc/api/admin_js.go b/rpc/api/admin_js.go index 17be63575..2a9197da7 100644 --- a/rpc/api/admin_js.go +++ b/rpc/api/admin_js.go @@ -57,7 +57,7 @@ web3._extend({ new web3._extend.Method({ name: 'stopRPC', call: 'admin_stopRPC', - params: 0, + params: 2, inputFormatter: [], outputFormatter: web3._extend.formatters.formatOutputBool }), -- cgit v1.2.3 From aa22cf323ef408f0562817352f68197f8b982f75 Mon Sep 17 00:00:00 2001 From: zelig Date: Sat, 4 Jul 2015 22:12:14 +0100 Subject: fix js arguments and TestContract passes --- rpc/api/admin_args.go | 32 +++++++++++++++++--------------- rpc/api/admin_js.go | 4 ++-- 2 files changed, 19 insertions(+), 17 deletions(-) (limited to 'rpc/api') diff --git a/rpc/api/admin_args.go b/rpc/api/admin_args.go index e7548c7be..532907905 100644 --- a/rpc/api/admin_args.go +++ b/rpc/api/admin_args.go @@ -114,7 +114,7 @@ func (args *StartRPCArgs) UnmarshalJSON(b []byte) (err error) { args.ListenPort = 8545 args.Apis = "net,eth,web3" - if len(obj) >= 1 { + if len(obj) >= 1 && obj[0] != nil { if addr, ok := obj[0].(string); ok { args.ListenAddress = addr } else { @@ -122,7 +122,7 @@ func (args *StartRPCArgs) UnmarshalJSON(b []byte) (err error) { } } - if len(obj) >= 2 { + if len(obj) >= 2 && obj[1] != nil { if port, ok := obj[1].(float64); ok && port >= 0 && port <= 64*1024 { args.ListenPort = uint(port) } else { @@ -130,7 +130,7 @@ func (args *StartRPCArgs) UnmarshalJSON(b []byte) (err error) { } } - if len(obj) >= 3 { + if len(obj) >= 3 && obj[2] != nil { if corsDomain, ok := obj[2].(string); ok { args.CorsDomain = corsDomain } else { @@ -138,7 +138,7 @@ func (args *StartRPCArgs) UnmarshalJSON(b []byte) (err error) { } } - if len(obj) >= 4 { + if len(obj) >= 4 && obj[3] != nil { if apis, ok := obj[3].(string); ok { args.Apis = apis } else { @@ -229,7 +229,7 @@ func (args *SetGlobalRegistrarArgs) UnmarshalJSON(b []byte) (err error) { } } - if len(obj) >= 2 { + if len(obj) >= 2 && obj[1] != nil { if addr, ok := obj[1].(string); ok { args.ContractAddress = addr } else { @@ -251,7 +251,7 @@ func (args *SetHashRegArgs) UnmarshalJSON(b []byte) (err error) { return shared.NewDecodeParamError(err.Error()) } - if len(obj) >= 1 { + if len(obj) >= 1 && obj[0] != nil { if hashreg, ok := obj[0].(string); ok { args.HashReg = hashreg } else { @@ -259,7 +259,7 @@ func (args *SetHashRegArgs) UnmarshalJSON(b []byte) (err error) { } } - if len(obj) >= 2 { + if len(obj) >= 2 && obj[1] != nil { if sender, ok := obj[1].(string); ok { args.Sender = sender } else { @@ -281,7 +281,7 @@ func (args *SetUrlHintArgs) UnmarshalJSON(b []byte) (err error) { return shared.NewDecodeParamError(err.Error()) } - if len(obj) >= 1 { + if len(obj) >= 1 && obj[0] != nil { if urlhint, ok := obj[0].(string); ok { args.UrlHint = urlhint } else { @@ -289,7 +289,7 @@ func (args *SetUrlHintArgs) UnmarshalJSON(b []byte) (err error) { } } - if len(obj) >= 2 { + if len(obj) >= 2 && obj[1] != nil { if sender, ok := obj[1].(string); ok { args.Sender = sender } else { @@ -388,17 +388,19 @@ func (args *RegisterUrlArgs) UnmarshalJSON(b []byte) (err error) { } if len(obj) >= 1 { - if sender, ok := obj[1].(string); ok { + if sender, ok := obj[0].(string); ok { args.Sender = sender } else { return shared.NewInvalidTypeError("Sender", "not a string") } } - if sender, ok := obj[1].(string); ok { - args.ContentHash = sender - } else { - return shared.NewInvalidTypeError("ContentHash", "not a string") + if len(obj) >= 2 { + if sender, ok := obj[1].(string); ok { + args.ContentHash = sender + } else { + return shared.NewInvalidTypeError("ContentHash", "not a string") + } } if len(obj) >= 3 { @@ -460,7 +462,7 @@ func (args *HttpGetArgs) UnmarshalJSON(b []byte) (err error) { } } - if len(obj) >= 2 { + if len(obj) >= 2 && obj[1] != nil { if path, ok := obj[1].(string); ok { args.Path = path } else { diff --git a/rpc/api/admin_js.go b/rpc/api/admin_js.go index 2a9197da7..40c029fd1 100644 --- a/rpc/api/admin_js.go +++ b/rpc/api/admin_js.go @@ -92,8 +92,8 @@ web3._extend({ new web3._extend.Method({ name: 'register', call: 'admin_register', - params: 2, - inputFormatter: [web3._extend.utils.formatInputString,web3._extend.utils.formatInputString], + params: 3, + inputFormatter: [web3._extend.utils.formatInputString,web3._extend.utils.formatInputString,web3._extend.utils.formatInputString], outputFormatter: web3._extend.formatters.formatOutputBool }), new web3._extend.Method({ -- cgit v1.2.3 From ceb0739ba111215d47cc2ff9d80d542fa26d764a Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Mon, 6 Jul 2015 13:08:08 +0200 Subject: fixed web3 formatters mismatch --- rpc/api/admin_js.go | 39 +++++++++------------------ rpc/api/db_js.go | 28 ------------------- rpc/api/debug_js.go | 23 ++++++---------- rpc/api/eth_js.go | 9 +++---- rpc/api/miner_js.go | 21 +++++---------- rpc/api/net_js.go | 28 +++---------------- rpc/api/personal_js.go | 10 +++---- rpc/api/ssh_js.go | 16 ++--------- rpc/api/utils.go | 73 ++++++++++++++++++++++---------------------------- 9 files changed, 73 insertions(+), 174 deletions(-) (limited to 'rpc/api') diff --git a/rpc/api/admin_js.go b/rpc/api/admin_js.go index 40c029fd1..e528b8863 100644 --- a/rpc/api/admin_js.go +++ b/rpc/api/admin_js.go @@ -9,22 +9,19 @@ web3._extend({ name: 'addPeer', call: 'admin_addPeer', params: 1, - inputFormatter: [web3._extend.utils.formatInputString], - outputFormatter: web3._extend.formatters.formatOutputBool + inputFormatter: [null] }), new web3._extend.Method({ name: 'exportChain', call: 'admin_exportChain', params: 1, - inputFormatter: [web3._extend.utils.formatInputString], - outputFormatter: function(obj) { return obj; } + inputFormatter: [null] }), new web3._extend.Method({ name: 'importChain', call: 'admin_importChain', params: 1, - inputFormatter: [web3._extend.utils.formatInputString], - outputFormatter: function(obj) { return obj; } + inputFormatter: [null] }), new web3._extend.Method({ name: 'sleepBlocks', @@ -37,22 +34,19 @@ web3._extend({ name: 'verbosity', call: 'admin_verbosity', params: 1, - inputFormatter: [web3._extend.utils.formatInputInt], - outputFormatter: web3._extend.formatters.formatOutputBool + inputFormatter: [web3._extend.utils.toDecimal] }), new web3._extend.Method({ name: 'setSolc', call: 'admin_setSolc', params: 1, - inputFormatter: [web3._extend.utils.formatInputString], - outputFormatter: web3._extend.formatters.formatOutputString + inputFormatter: [null] }), new web3._extend.Method({ name: 'startRPC', call: 'admin_startRPC', params: 4, - inputFormatter: [web3._extend.utils.formatInputString,web3._extend.utils.formatInputInteger,web3._extend.utils.formatInputString,web3._extend.utils.formatInputString], - outputFormatter: web3._extend.formatters.formatOutputBool + inputFormatter: [null, web3._extend.utils.toDecimal, null, null] }), new web3._extend.Method({ name: 'stopRPC', @@ -114,22 +108,19 @@ web3._extend({ name: 'stopNatSpec', call: 'admin_stopNatSpec', params: 0, - inputFormatter: [], - outputFormatter: web3._extend.formatters.formatOutputBool + inputFormatter: [] }), new web3._extend.Method({ name: 'getContractInfo', call: 'admin_getContractInfo', params: 1, - inputFormatter: [web3._extend.utils.formatInputString], - outputFormatter: function(obj) { return json.parse(obj); } + inputFormatter: [null], }), new web3._extend.Method({ name: 'httpGet', call: 'admin_httpGet', params: 2, - inputFormatter: [web3._extend.utils.formatInputString,web3._extend.utils.formatInputString], - outputFormatter: web3._extend.formatters.formatOutputString + inputFormatter: [null, null] }) ], @@ -137,23 +128,19 @@ web3._extend({ [ new web3._extend.Property({ name: 'nodeInfo', - getter: 'admin_nodeInfo', - outputFormatter: web3._extend.formatters.formatOutputString + getter: 'admin_nodeInfo' }), new web3._extend.Property({ name: 'peers', - getter: 'admin_peers', - outputFormatter: function(obj) { return obj; } + getter: 'admin_peers' }), new web3._extend.Property({ name: 'datadir', - getter: 'admin_datadir', - outputFormatter: web3._extend.formatters.formatOutputString + getter: 'admin_datadir' }), new web3._extend.Property({ name: 'chainSyncStatus', - getter: 'admin_chainSyncStatus', - outputFormatter: function(obj) { return obj; } + getter: 'admin_chainSyncStatus' }) ] }); diff --git a/rpc/api/db_js.go b/rpc/api/db_js.go index 62cdcd20e..91dc95e5b 100644 --- a/rpc/api/db_js.go +++ b/rpc/api/db_js.go @@ -5,34 +5,6 @@ web3._extend({ property: 'db', methods: [ - new web3._extend.Method({ - name: 'getString', - call: 'db_getString', - params: 2, - inputFormatter: [web3._extend.formatters.formatInputString, web3._extend.formatters.formatInputString], - outputFormatter: web3._extend.formatters.formatOutputString - }), - new web3._extend.Method({ - name: 'putString', - call: 'db_putString', - params: 3, - inputFormatter: [web3._extend.formatters.formatInputString, web3._extend.formatters.formatInputString, web3._extend.formatters.formatInputString], - outputFormatter: web3._extend.formatters.formatOutputBool - }), - new web3._extend.Method({ - name: 'getHex', - call: 'db_getHex', - params: 2, - inputFormatter: [web3._extend.formatters.formatInputString, web3._extend.formatters.formatInputString], - outputFormatter: web3._extend.formatters.formatOutputString - }), - new web3._extend.Method({ - name: 'putHex', - call: 'db_putHex', - params: 3, - inputFormatter: [web3._extend.formatters.formatInputString, web3._extend.formatters.formatInputString, web3._extend.formatters.formatInputString], - outputFormatter: web3._extend.formatters.formatOutputBool - }), ], properties: [ diff --git a/rpc/api/debug_js.go b/rpc/api/debug_js.go index bd3a6dfb2..93fba537e 100644 --- a/rpc/api/debug_js.go +++ b/rpc/api/debug_js.go @@ -9,50 +9,43 @@ web3._extend({ name: 'printBlock', call: 'debug_printBlock', params: 1, - inputFormatter: [web3._extend.formatters.formatInputInt], - outputFormatter: web3._extend.formatters.formatOutputString + inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter] }), new web3._extend.Method({ name: 'getBlockRlp', call: 'debug_getBlockRlp', params: 1, - inputFormatter: [web3._extend.formatters.formatInputInt], - outputFormatter: web3._extend.formatters.formatOutputString + inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter] }), new web3._extend.Method({ name: 'setHead', call: 'debug_setHead', params: 1, - inputFormatter: [web3._extend.formatters.formatInputInt], - outputFormatter: web3._extend.formatters.formatOutputBool + inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter] }), new web3._extend.Method({ name: 'processBlock', call: 'debug_processBlock', params: 1, - inputFormatter: [web3._extend.formatters.formatInputInt], - outputFormatter: function(obj) { return obj; } + inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter] }), new web3._extend.Method({ name: 'seedHash', call: 'debug_seedHash', params: 1, - inputFormatter: [web3._extend.formatters.formatInputInt], - outputFormatter: web3._extend.formatters.formatOutputString - }) , + inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter] + }), new web3._extend.Method({ name: 'dumpBlock', call: 'debug_dumpBlock', params: 1, - inputFormatter: [web3._extend.formatters.formatInputInt], - outputFormatter: function(obj) { return obj; } + inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter] }), new web3._extend.Method({ name: 'metrics', call: 'debug_metrics', params: 1, - inputFormatter: [web3._extend.formatters.formatInputBool], - outputFormatter: function(obj) { return obj; } + inputFormatter: [null] }) ], properties: diff --git a/rpc/api/eth_js.go b/rpc/api/eth_js.go index 4512cc147..4c3e9e4db 100644 --- a/rpc/api/eth_js.go +++ b/rpc/api/eth_js.go @@ -12,23 +12,20 @@ web3._extend({ name: 'sign', call: 'eth_sign', params: 2, - inputFormatter: [web3._extend.formatters.formatInputString,web3._extend.formatters.formatInputString], - outputFormatter: web3._extend.formatters.formatOutputString + inputFormatter: [web3._extend.utils.toAddress, null] }), new web3._extend.Method({ name: 'resend', call: 'eth_resend', params: 3, - inputFormatter: [function(obj) { return obj; },web3._extend.formatters.formatInputString,web3._extend.formatters.formatInputString], - outputFormatter: web3._extend.formatters.formatOutputString + inputFormatter: [null, null, null] }) ], properties: [ new web3._extend.Property({ name: 'pendingTransactions', - getter: 'eth_pendingTransactions', - outputFormatter: function(obj) { return obj; } + getter: 'eth_pendingTransactions' }) ] }); diff --git a/rpc/api/miner_js.go b/rpc/api/miner_js.go index 6290368da..6474166e7 100644 --- a/rpc/api/miner_js.go +++ b/rpc/api/miner_js.go @@ -9,50 +9,43 @@ web3._extend({ name: 'start', call: 'miner_start', params: 1, - inputFormatter: [web3._extend.formatters.formatInputInt], - outputFormatter: web3._extend.formatters.formatOutputBool + inputFormatter: [null] }), new web3._extend.Method({ name: 'stop', call: 'miner_stop', params: 1, - inputFormatter: [web3._extend.formatters.formatInputInt], - outputFormatter: web3._extend.formatters.formatOutputBool + inputFormatter: [null] }), new web3._extend.Method({ name: 'setExtra', call: 'miner_setExtra', params: 1, - inputFormatter: [web3._extend.utils.formatInputString], - outputFormatter: web3._extend.formatters.formatOutputBool + inputFormatter: [null] }), new web3._extend.Method({ name: 'setGasPrice', call: 'miner_setGasPrice', params: 1, - inputFormatter: [web3._extend.utils.formatInputString], - outputFormatter: web3._extend.formatters.formatOutputBool + inputFormatter: [null] }), new web3._extend.Method({ name: 'startAutoDAG', call: 'miner_startAutoDAG', params: 0, - inputFormatter: [], - outputFormatter: web3._extend.formatters.formatOutputBool + inputFormatter: [] }), new web3._extend.Method({ name: 'stopAutoDAG', call: 'miner_stopAutoDAG', params: 0, - inputFormatter: [], - outputFormatter: web3._extend.formatters.formatOutputBool + inputFormatter: [] }), new web3._extend.Method({ name: 'makeDAG', call: 'miner_makeDAG', params: 1, - inputFormatter: [web3._extend.formatters.inputDefaultBlockNumberFormatter], - outputFormatter: web3._extend.formatters.formatOutputBool + inputFormatter: [web3._extend.formatters.inputDefaultBlockNumberFormatter] }) ], properties: diff --git a/rpc/api/net_js.go b/rpc/api/net_js.go index 1677d9fa6..cc8d7f46e 100644 --- a/rpc/api/net_js.go +++ b/rpc/api/net_js.go @@ -2,45 +2,25 @@ package api const Net_JS = ` web3._extend({ - property: 'network', + property: 'net', methods: [ new web3._extend.Method({ name: 'addPeer', call: 'net_addPeer', params: 1, - inputFormatter: [web3._extend.utils.formatInputString], - outputFormatter: web3._extend.formatters.formatOutputBool - }), - new web3._extend.Method({ - name: 'getPeerCount', - call: 'net_peerCount', - params: 0, - inputFormatter: [], - outputFormatter: web3._extend.formatters.formatOutputString + inputFormatter: [null] }) ], properties: [ - new web3._extend.Property({ - name: 'listening', - getter: 'net_listening', - outputFormatter: web3._extend.formatters.formatOutputBool - }), - new web3._extend.Property({ - name: 'peerCount', - getter: 'net_peerCount', - outputFormatter: web3._extend.utils.toDecimal - }), new web3._extend.Property({ name: 'peers', - getter: 'net_peers', - outputFormatter: function(obj) { return obj; } + getter: 'net_peers' }), new web3._extend.Property({ name: 'version', - getter: 'net_version', - outputFormatter: web3._extend.formatters.formatOutputString + getter: 'net_version' }) ] }); diff --git a/rpc/api/personal_js.go b/rpc/api/personal_js.go index 463a2c7f5..66014cc02 100644 --- a/rpc/api/personal_js.go +++ b/rpc/api/personal_js.go @@ -9,23 +9,21 @@ web3._extend({ name: 'newAccount', call: 'personal_newAccount', params: 1, - inputFormatter: [web3._extend.formatters.formatInputString], - outputFormatter: web3._extend.formatters.formatOutputString + inputFormatter: [null], + outputFormatter: web3._extend.utils.toAddress }), new web3._extend.Method({ name: 'unlockAccount', call: 'personal_unlockAccount', params: 3, - inputFormatter: [web3._extend.formatters.formatInputString,web3._extend.formatters.formatInputString,web3._extend.formatters.formatInputInt], - outputFormatter: web3._extend.formatters.formatOutputBool + inputFormatter: [null, null, null] }) ], properties: [ new web3._extend.Property({ name: 'listAccounts', - getter: 'personal_listAccounts', - outputFormatter: function(obj) { return obj; } + getter: 'personal_listAccounts' }) ] }); diff --git a/rpc/api/ssh_js.go b/rpc/api/ssh_js.go index f401f70f1..c0591bd71 100644 --- a/rpc/api/ssh_js.go +++ b/rpc/api/ssh_js.go @@ -5,25 +5,13 @@ web3._extend({ property: 'shh', methods: [ - new web3._extend.Method({ - name: 'post', - call: 'shh_post', - params: 6, - inputFormatter: [web3._extend.formatters.formatInputString, - web3._extend.formatters.formatInputString, - web3._extend.formatters.formatInputString, - , - , web3._extend.formatters.formatInputInt - , web3._extend.formatters.formatInputInt], - outputFormatter: web3._extend.formatters.formatOutputBool - }), + ], properties: [ new web3._extend.Property({ name: 'version', - getter: 'shh_version', - outputFormatter: web3._extend.formatters.formatOutputInt + getter: 'shh_version' }) ] }); diff --git a/rpc/api/utils.go b/rpc/api/utils.go index 54ca28774..a96d105fb 100644 --- a/rpc/api/utils.go +++ b/rpc/api/utils.go @@ -36,6 +36,7 @@ var ( "debug": []string{ "dumpBlock", "getBlockRlp", + "metrics", "printBlock", "processBlock", "seedHash", @@ -44,49 +45,38 @@ var ( "eth": []string{ "accounts", "blockNumber", - "getBalance", - "protocolVersion", + "call", + "contract", "coinbase", - "mining", + "compile.lll", + "compile.serpent", + "compile.solidity", + "contract", + "defaultAccount", + "defaultBlock", + "estimateGas", + "filter", + "getBalance", + "getBlock", + "getBlockTransactionCount", + "getBlockUncleCount", + "getCode", + "getCompilers", "gasPrice", - "getStorage", - "storageAt", "getStorageAt", + "getTransaction", "getTransactionCount", - "getBlockTransactionCountByHash", - "getBlockTransactionCountByNumber", - "getUncleCountByBlockHash", - "getUncleCountByBlockNumber", - "getData", - "getCode", - "sign", - "sendRawTransaction", - "sendTransaction", - "transact", - "estimateGas", - "call", - "flush", - "getBlockByHash", - "getBlockByNumber", - "getTransactionByHash", - "getTransactionByBlockHashAndIndex", - "getUncleByBlockHashAndIndex", - "getUncleByBlockNumberAndIndex", - "getCompilers", - "compileSolidity", - "newFilter", - "newBlockFilter", - "newPendingTransactionFilter", - "uninstallFilter", - "getFilterChanges", - "getFilterLogs", - "getLogs", + "getTransactionFromBlock", + "getTransactionReceipt", + "getUncle", "hashrate", - "getWork", - "submitWork", + "mining", + "namereg", "pendingTransactions", "resend", - "getTransactionReceipt", + "sendRawTransaction", + "sendTransaction", + "sign", }, "miner": []string{ "hashrate", @@ -101,6 +91,8 @@ var ( "net": []string{ "peerCount", "listening", + "version", + "peers", }, "personal": []string{ "listAccounts", @@ -109,13 +101,12 @@ var ( "unlockAccount", }, "shh": []string{ - "version", "post", + "newIdentify", "hasIdentity", - "newIdentity", - "newFilter", - "uninstallFilter", - "getFilterChanges", + "newGroup", + "addToGroup", + "filter", }, "txpool": []string{ "status", -- cgit v1.2.3 From 7e6c1f8024d0cc0f381c615cab3c97b57fc9515e Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Mon, 6 Jul 2015 15:59:36 +0200 Subject: corrected input formatters as suggested during review --- rpc/api/admin_js.go | 4 ++-- rpc/api/eth_js.go | 2 +- rpc/api/miner_js.go | 2 +- rpc/api/net.go | 10 ---------- rpc/api/net_js.go | 8 -------- rpc/api/utils.go | 2 -- 6 files changed, 4 insertions(+), 24 deletions(-) (limited to 'rpc/api') diff --git a/rpc/api/admin_js.go b/rpc/api/admin_js.go index e528b8863..86a4f6a4c 100644 --- a/rpc/api/admin_js.go +++ b/rpc/api/admin_js.go @@ -34,7 +34,7 @@ web3._extend({ name: 'verbosity', call: 'admin_verbosity', params: 1, - inputFormatter: [web3._extend.utils.toDecimal] + inputFormatter: [web3._extend.utils.fromDecimal] }), new web3._extend.Method({ name: 'setSolc', @@ -46,7 +46,7 @@ web3._extend({ name: 'startRPC', call: 'admin_startRPC', params: 4, - inputFormatter: [null, web3._extend.utils.toDecimal, null, null] + inputFormatter: [null, null, null, null] }), new web3._extend.Method({ name: 'stopRPC', diff --git a/rpc/api/eth_js.go b/rpc/api/eth_js.go index 4c3e9e4db..400eb8e89 100644 --- a/rpc/api/eth_js.go +++ b/rpc/api/eth_js.go @@ -18,7 +18,7 @@ web3._extend({ name: 'resend', call: 'eth_resend', params: 3, - inputFormatter: [null, null, null] + inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal] }) ], properties: diff --git a/rpc/api/miner_js.go b/rpc/api/miner_js.go index 6474166e7..8861a177a 100644 --- a/rpc/api/miner_js.go +++ b/rpc/api/miner_js.go @@ -27,7 +27,7 @@ web3._extend({ name: 'setGasPrice', call: 'miner_setGasPrice', params: 1, - inputFormatter: [null] + inputFormatter: [web3._extend.utils.fromDecial] }), new web3._extend.Method({ name: 'startAutoDAG', diff --git a/rpc/api/net.go b/rpc/api/net.go index 761654661..b3931ba2d 100644 --- a/rpc/api/net.go +++ b/rpc/api/net.go @@ -14,10 +14,8 @@ const ( var ( // mapping between methods and handlers netMapping = map[string]nethandler{ - "net_version": (*netApi).Version, "net_peerCount": (*netApi).PeerCount, "net_listening": (*netApi).IsListening, - "net_peers": (*netApi).Peers, } ) @@ -70,11 +68,6 @@ func (self *netApi) ApiVersion() string { return NetApiVersion } -// Network version -func (self *netApi) Version(req *shared.Request) (interface{}, error) { - return self.xeth.NetworkVersion(), nil -} - // Number of connected peers func (self *netApi) PeerCount(req *shared.Request) (interface{}, error) { return newHexNum(self.xeth.PeerCount()), nil @@ -84,6 +77,3 @@ func (self *netApi) IsListening(req *shared.Request) (interface{}, error) { return self.xeth.IsListening(), nil } -func (self *netApi) Peers(req *shared.Request) (interface{}, error) { - return self.ethereum.PeersInfo(), nil -} diff --git a/rpc/api/net_js.go b/rpc/api/net_js.go index cc8d7f46e..2f872393c 100644 --- a/rpc/api/net_js.go +++ b/rpc/api/net_js.go @@ -14,14 +14,6 @@ web3._extend({ ], properties: [ - new web3._extend.Property({ - name: 'peers', - getter: 'net_peers' - }), - new web3._extend.Property({ - name: 'version', - getter: 'net_version' - }) ] }); ` diff --git a/rpc/api/utils.go b/rpc/api/utils.go index a96d105fb..d64cfc7cf 100644 --- a/rpc/api/utils.go +++ b/rpc/api/utils.go @@ -91,8 +91,6 @@ var ( "net": []string{ "peerCount", "listening", - "version", - "peers", }, "personal": []string{ "listAccounts", -- cgit v1.2.3 From 3791831081eb2d6e0dbfb3aa96f181dbb645c394 Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Mon, 6 Jul 2015 18:13:06 +0200 Subject: rebase with zelig/frontier/registrar --- rpc/api/admin_js.go | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'rpc/api') diff --git a/rpc/api/admin_js.go b/rpc/api/admin_js.go index 86a4f6a4c..ddfa2ea04 100644 --- a/rpc/api/admin_js.go +++ b/rpc/api/admin_js.go @@ -27,8 +27,7 @@ web3._extend({ name: 'sleepBlocks', call: 'admin_sleepBlocks', params: 2, - inputFormatter: [web3._extend.utils.formatInputInt,web3._extend.utils.formatInputInt], - outputFormatter: web3._extend.formatters.formatOutputInt + inputFormatter: [null, null] }), new web3._extend.Method({ name: 'verbosity', @@ -51,58 +50,50 @@ web3._extend({ new web3._extend.Method({ name: 'stopRPC', call: 'admin_stopRPC', - params: 2, - inputFormatter: [], - outputFormatter: web3._extend.formatters.formatOutputBool + params: 0, + inputFormatter: [] }), new web3._extend.Method({ name: 'setGlobalRegistrar', call: 'admin_setGlobalRegistrar', params: 2, - inputFormatter: [web3._extend.utils.formatInputString,web3._extend.utils.formatInputString], - outputFormatter: web3._extend.formatters.formatOutputString + inputFormatter: [null,null] }), new web3._extend.Method({ name: 'setHashReg', call: 'admin_setHashReg', params: 2, - inputFormatter: [web3._extend.utils.formatInputString,web3._extend.utils.formatInputString], - outputFormatter: web3._extend.formatters.formatOutputString + inputFormatter: [null,null] }), new web3._extend.Method({ name: 'setUrlHint', call: 'admin_setUrlHint', params: 2, - inputFormatter: [web3._extend.utils.formatInputString,web3._extend.utils.formatInputString], - outputFormatter: web3._extend.formatters.formatOutputString + inputFormatter: [null,null] }), new web3._extend.Method({ name: 'saveInfo', call: 'admin_saveInfo', params: 2, - inputFormatter: [function(obj) { return obj; },web3._extend.utils.formatInputString], - outputFormatter: web3._extend.formatters.formatOutputString + inputFormatter: [null,null] }), new web3._extend.Method({ name: 'register', call: 'admin_register', params: 3, - inputFormatter: [web3._extend.utils.formatInputString,web3._extend.utils.formatInputString,web3._extend.utils.formatInputString], - outputFormatter: web3._extend.formatters.formatOutputBool + inputFormatter: [null,null,null] }), new web3._extend.Method({ name: 'registerUrl', call: 'admin_registerUrl', params: 3, - inputFormatter: [web3._extend.utils.formatInputString,web3._extend.utils.formatInputString,web3._extend.utils.formatInputString], - outputFormatter: web3._extend.formatters.formatOutputBool + inputFormatter: [null,null,null] }), new web3._extend.Method({ name: 'startNatSpec', call: 'admin_startNatSpec', params: 0, - inputFormatter: [], - outputFormatter: web3._extend.formatters.formatOutputBool + inputFormatter: [] }), new web3._extend.Method({ name: 'stopNatSpec', @@ -122,7 +113,6 @@ web3._extend({ params: 2, inputFormatter: [null, null] }) - ], properties: [ -- cgit v1.2.3 From c5cb6e8e70339b6641b7ce46cda04b83936213b3 Mon Sep 17 00:00:00 2001 From: zelig Date: Tue, 7 Jul 2015 06:00:58 +0100 Subject: fix/skip tests, adapt registrar to no contract address registry initialisers now return the txhash which caller can use to retrieve receipt --- rpc/api/admin.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'rpc/api') diff --git a/rpc/api/admin.go b/rpc/api/admin.go index 5d214e8d8..c5f026090 100644 --- a/rpc/api/admin.go +++ b/rpc/api/admin.go @@ -322,12 +322,12 @@ func (self *adminApi) SetGlobalRegistrar(req *shared.Request) (interface{}, erro sender := common.HexToAddress(args.ContractAddress) reg := registrar.New(self.xeth) - err := reg.SetGlobalRegistrar(args.NameReg, sender) + txhash, err := reg.SetGlobalRegistrar(args.NameReg, sender) if err != nil { return false, err } - return registrar.GlobalRegistrarAddr, nil + return txhash, nil } func (self *adminApi) SetHashReg(req *shared.Request) (interface{}, error) { @@ -338,12 +338,12 @@ func (self *adminApi) SetHashReg(req *shared.Request) (interface{}, error) { reg := registrar.New(self.xeth) sender := common.HexToAddress(args.Sender) - err := reg.SetHashReg(args.HashReg, sender) + txhash, err := reg.SetHashReg(args.HashReg, sender) if err != nil { return false, err } - return registrar.HashRegAddr, nil + return txhash, nil } func (self *adminApi) SetUrlHint(req *shared.Request) (interface{}, error) { @@ -356,12 +356,12 @@ func (self *adminApi) SetUrlHint(req *shared.Request) (interface{}, error) { sender := common.HexToAddress(args.Sender) reg := registrar.New(self.xeth) - err := reg.SetUrlHint(urlHint, sender) + txhash, err := reg.SetUrlHint(urlHint, sender) if err != nil { return nil, err } - return registrar.UrlHintAddr, nil + return txhash, nil } func (self *adminApi) SaveInfo(req *shared.Request) (interface{}, error) { -- cgit v1.2.3