From e46ab3bdcde7236c8fe54d6c83655e50bd19fe31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Tue, 27 Oct 2015 15:10:30 +0200 Subject: eth, p2p, rpc/api: polish protocol info gathering --- rpc/api/admin.go | 9 ++++++--- rpc/api/utils.go | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'rpc') diff --git a/rpc/api/admin.go b/rpc/api/admin.go index eb08fbc5d..b359d52a1 100644 --- a/rpc/api/admin.go +++ b/rpc/api/admin.go @@ -32,6 +32,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rpc/codec" "github.com/ethereum/go-ethereum/rpc/comms" @@ -80,15 +81,17 @@ type adminhandler func(*adminApi, *shared.Request) (interface{}, error) // admin api provider type adminApi struct { xeth *xeth.XEth + network *p2p.Server ethereum *eth.Ethereum codec codec.Codec coder codec.ApiCoder } // create a new admin api instance -func NewAdminApi(xeth *xeth.XEth, ethereum *eth.Ethereum, codec codec.Codec) *adminApi { +func NewAdminApi(xeth *xeth.XEth, network *p2p.Server, ethereum *eth.Ethereum, codec codec.Codec) *adminApi { return &adminApi{ xeth: xeth, + network: network, ethereum: ethereum, codec: codec, coder: codec.New(nil), @@ -137,11 +140,11 @@ func (self *adminApi) AddPeer(req *shared.Request) (interface{}, error) { } func (self *adminApi) Peers(req *shared.Request) (interface{}, error) { - return self.ethereum.PeersInfo(), nil + return self.network.PeersInfo(), nil } func (self *adminApi) NodeInfo(req *shared.Request) (interface{}, error) { - return self.ethereum.NodeInfo(), nil + return self.network.NodeInfo(), nil } func (self *adminApi) DataDir(req *shared.Request) (interface{}, error) { diff --git a/rpc/api/utils.go b/rpc/api/utils.go index 5a3ade46b..6dde4022b 100644 --- a/rpc/api/utils.go +++ b/rpc/api/utils.go @@ -165,7 +165,7 @@ func ParseApiString(apistr string, codec codec.Codec, xeth *xeth.XEth, eth *eth. for i, name := range names { switch strings.ToLower(strings.TrimSpace(name)) { case shared.AdminApiName: - apis[i] = NewAdminApi(xeth, eth, codec) + apis[i] = NewAdminApi(xeth, eth.Network(), eth, codec) case shared.DebugApiName: apis[i] = NewDebugApi(xeth, eth, codec) case shared.DbApiName: -- cgit v1.2.3 From 76410df6a21a10dec09ca955b1896ac083853ef7 Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Thu, 29 Oct 2015 16:58:23 +0100 Subject: rpc: return an unsupported error when "pending" was used to create a filter --- rpc/api/args_test.go | 12 +++++------- rpc/api/eth_args.go | 7 +++++++ 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'rpc') diff --git a/rpc/api/args_test.go b/rpc/api/args_test.go index 23ae2930d..130315bd9 100644 --- a/rpc/api/args_test.go +++ b/rpc/api/args_test.go @@ -1394,13 +1394,10 @@ func TestBlockFilterArgsDefaults(t *testing.T) { } func TestBlockFilterArgsWords(t *testing.T) { - input := `[{ - "fromBlock": "latest", - "toBlock": "pending" - }]` + input := `[{"fromBlock": "latest", "toBlock": "latest"}]` expected := new(BlockFilterArgs) expected.Earliest = -1 - expected.Latest = -2 + expected.Latest = -1 args := new(BlockFilterArgs) if err := json.Unmarshal([]byte(input), &args); err != nil { @@ -1411,8 +1408,9 @@ func TestBlockFilterArgsWords(t *testing.T) { t.Errorf("Earliest shoud be %#v but is %#v", expected.Earliest, args.Earliest) } - if expected.Latest != args.Latest { - t.Errorf("Latest shoud be %#v but is %#v", expected.Latest, args.Latest) + input = `[{"toBlock": "pending"}]` + if err := json.Unmarshal([]byte(input), &args); err == nil { + t.Errorf("Pending isn't currently supported and should raise an unsupported error") } } diff --git a/rpc/api/eth_args.go b/rpc/api/eth_args.go index 6aca6a663..a406d0817 100644 --- a/rpc/api/eth_args.go +++ b/rpc/api/eth_args.go @@ -714,6 +714,13 @@ func (args *BlockFilterArgs) UnmarshalJSON(b []byte) (err error) { return err } } + + if num == -2 { + return fmt.Errorf("\"pending\" is unsupported") + } else if num < -2 { + return fmt.Errorf("Invalid to block number") + } + args.Latest = num if obj[0].Limit == nil { -- cgit v1.2.3 From 6e5349880e79b8321ae311d824493e4581039d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Fri, 6 Nov 2015 11:47:57 +0200 Subject: rpc/api: fix #1972 api regression (nil eth panic) in attach --- rpc/api/admin.go | 9 +++------ rpc/api/utils.go | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) (limited to 'rpc') diff --git a/rpc/api/admin.go b/rpc/api/admin.go index b359d52a1..c11662577 100644 --- a/rpc/api/admin.go +++ b/rpc/api/admin.go @@ -32,7 +32,6 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/logger/glog" - "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rpc/codec" "github.com/ethereum/go-ethereum/rpc/comms" @@ -81,17 +80,15 @@ type adminhandler func(*adminApi, *shared.Request) (interface{}, error) // admin api provider type adminApi struct { xeth *xeth.XEth - network *p2p.Server ethereum *eth.Ethereum codec codec.Codec coder codec.ApiCoder } // create a new admin api instance -func NewAdminApi(xeth *xeth.XEth, network *p2p.Server, ethereum *eth.Ethereum, codec codec.Codec) *adminApi { +func NewAdminApi(xeth *xeth.XEth, ethereum *eth.Ethereum, codec codec.Codec) *adminApi { return &adminApi{ xeth: xeth, - network: network, ethereum: ethereum, codec: codec, coder: codec.New(nil), @@ -140,11 +137,11 @@ func (self *adminApi) AddPeer(req *shared.Request) (interface{}, error) { } func (self *adminApi) Peers(req *shared.Request) (interface{}, error) { - return self.network.PeersInfo(), nil + return self.ethereum.Network().PeersInfo(), nil } func (self *adminApi) NodeInfo(req *shared.Request) (interface{}, error) { - return self.network.NodeInfo(), nil + return self.ethereum.Network().NodeInfo(), nil } func (self *adminApi) DataDir(req *shared.Request) (interface{}, error) { diff --git a/rpc/api/utils.go b/rpc/api/utils.go index 6dde4022b..5a3ade46b 100644 --- a/rpc/api/utils.go +++ b/rpc/api/utils.go @@ -165,7 +165,7 @@ func ParseApiString(apistr string, codec codec.Codec, xeth *xeth.XEth, eth *eth. for i, name := range names { switch strings.ToLower(strings.TrimSpace(name)) { case shared.AdminApiName: - apis[i] = NewAdminApi(xeth, eth.Network(), eth, codec) + apis[i] = NewAdminApi(xeth, eth, codec) case shared.DebugApiName: apis[i] = NewDebugApi(xeth, eth, codec) case shared.DbApiName: -- cgit v1.2.3 From 6ea05f5a54c2db009e4379ce917590568b950f42 Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Sat, 15 Aug 2015 23:51:31 +0200 Subject: rpc/api, xeth: added signTransaction method SignTransaction creates a transaction but does submit it to the network. SignTransaction returns a structure which includes the transaction object details as well as the RLP encoded transaction that could possibly be submitted by the SendRawTransaction method. --- rpc/api/eth.go | 46 ++++++++++++++++++++++++++++++++++++++++++++-- rpc/api/eth_js.go | 22 +++++++++++++++++----- 2 files changed, 61 insertions(+), 7 deletions(-) (limited to 'rpc') diff --git a/rpc/api/eth.go b/rpc/api/eth.go index b84ae31da..db7a643d8 100644 --- a/rpc/api/eth.go +++ b/rpc/api/eth.go @@ -26,6 +26,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/natspec" "github.com/ethereum/go-ethereum/eth" + "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rpc/codec" "github.com/ethereum/go-ethereum/rpc/shared" "github.com/ethereum/go-ethereum/xeth" @@ -70,8 +71,10 @@ var ( "eth_getCode": (*ethApi).GetData, "eth_getNatSpec": (*ethApi).GetNatSpec, "eth_sign": (*ethApi).Sign, - "eth_sendRawTransaction": (*ethApi).SendRawTransaction, + "eth_sendRawTransaction": (*ethApi).SubmitTransaction, + "eth_submitTransaction": (*ethApi).SubmitTransaction, "eth_sendTransaction": (*ethApi).SendTransaction, + "eth_signTransaction": (*ethApi).SignTransaction, "eth_transact": (*ethApi).SendTransaction, "eth_estimateGas": (*ethApi).EstimateGas, "eth_call": (*ethApi).Call, @@ -285,7 +288,7 @@ func (self *ethApi) Sign(req *shared.Request) (interface{}, error) { return v, nil } -func (self *ethApi) SendRawTransaction(req *shared.Request) (interface{}, error) { +func (self *ethApi) SubmitTransaction(req *shared.Request) (interface{}, error) { args := new(NewDataArgs) if err := self.codec.Decode(req.Params, &args); err != nil { return nil, shared.NewDecodeParamError(err.Error()) @@ -298,6 +301,45 @@ func (self *ethApi) SendRawTransaction(req *shared.Request) (interface{}, error) return v, nil } +// JsonTransaction is returned as response by the JSON RPC. It contains the +// signed RLP encoded transaction as Raw and the signed transaction object as Tx. +type JsonTransaction struct { + Raw string `json:"raw"` + Tx *tx `json:"tx"` +} + +func (self *ethApi) SignTransaction(req *shared.Request) (interface{}, error) { + args := new(NewTxArgs) + if err := self.codec.Decode(req.Params, &args); err != nil { + return nil, shared.NewDecodeParamError(err.Error()) + } + + // nonce may be nil ("guess" mode) + var nonce string + if args.Nonce != nil { + nonce = args.Nonce.String() + } + + var gas, price string + if args.Gas != nil { + gas = args.Gas.String() + } + if args.GasPrice != nil { + price = args.GasPrice.String() + } + tx, err := self.xeth.SignTransaction(args.From, args.To, nonce, args.Value.String(), gas, price, args.Data) + if err != nil { + return nil, err + } + + data, err := rlp.EncodeToBytes(tx) + if err != nil { + return nil, err + } + + return JsonTransaction{"0x" + common.Bytes2Hex(data), newTx(tx)}, nil +} + func (self *ethApi) SendTransaction(req *shared.Request) (interface{}, error) { args := new(NewTxArgs) if err := self.codec.Decode(req.Params, &args); err != nil { diff --git a/rpc/api/eth_js.go b/rpc/api/eth_js.go index 75c103c9d..dfc104ad8 100644 --- a/rpc/api/eth_js.go +++ b/rpc/api/eth_js.go @@ -36,11 +36,23 @@ web3._extend({ params: 3, inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal] }), - new web3._extend.Method({ - name: 'getNatSpec', - call: 'eth_getNatSpec', - params: 1, - inputFormatter: [web3._extend.formatters.inputTransactionFormatter] + new web3._extend.Method({ + name: 'getNatSpec', + call: 'eth_getNatSpec', + params: 1, + inputFormatter: [web3._extend.formatters.inputTransactionFormatter] + }), + new web3._extend.Method({ + name: 'signTransaction', + call: 'eth_signTransaction', + params: 1, + inputFormatter: [web3._extend.formatters.inputTransactionFormatter] + }), + new web3._extend.Method({ + name: 'submitTransaction', + call: 'eth_submitTransaction', + params: 1, + inputFormatter: [web3._extend.formatters.inputTransactionFormatter] }) ], properties: -- cgit v1.2.3 From 53f28e71dc2ee41af3addc81a6a63be2f53bc0ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Wed, 18 Nov 2015 13:03:20 +0200 Subject: rpc/api: fix #1986, newIdentity autocomplete --- rpc/api/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rpc') diff --git a/rpc/api/utils.go b/rpc/api/utils.go index 5a3ade46b..8351e88d3 100644 --- a/rpc/api/utils.go +++ b/rpc/api/utils.go @@ -130,7 +130,7 @@ var ( }, "shh": []string{ "post", - "newIdentify", + "newIdentity", "hasIdentity", "newGroup", "addToGroup", -- cgit v1.2.3 From a1d9ef48c505ab4314ca8e3ee1fc272032da3034 Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Mon, 19 Oct 2015 16:08:17 +0200 Subject: core, eth, rpc: split out block validator and state processor This removes the burden on a single object to take care of all validation and state processing. Now instead the validation is done by the `core.BlockValidator` (`types.Validator`) that takes care of both header and uncle validation through the `ValidateBlock` method and state validation through the `ValidateState` method. The state processing is done by a new object `core.StateProcessor` (`types.Processor`) and accepts a new state as input and uses that to process the given block's transactions (and uncles for rewords) to calculate the state root for the next block (P_n + 1). --- rpc/api/debug.go | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'rpc') diff --git a/rpc/api/debug.go b/rpc/api/debug.go index d2cbc7f19..a6faa335e 100644 --- a/rpc/api/debug.go +++ b/rpc/api/debug.go @@ -22,6 +22,7 @@ import ( "time" "github.com/ethereum/ethash" + "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/eth" @@ -166,11 +167,30 @@ func (self *debugApi) ProcessBlock(req *shared.Request) (interface{}, error) { defer func() { vm.Debug = old }() vm.Debug = true - _, err := self.ethereum.BlockProcessor().RetryProcess(block) - if err == nil { - return true, nil + var ( + blockchain = self.ethereum.BlockChain() + validator = blockchain.Validator() + processor = blockchain.Processor() + ) + + err := core.ValidateHeader(blockchain.AuxValidator(), block.Header(), blockchain.GetHeader(block.ParentHash()), true, false) + if err != nil { + return false, err } - return false, err + statedb, err := state.New(blockchain.GetBlock(block.ParentHash()).Root(), self.ethereum.ChainDb()) + if err != nil { + return false, err + } + receipts, _, usedGas, err := processor.Process(block, statedb) + if err != nil { + return false, err + } + err = validator.ValidateState(block, blockchain.GetBlock(block.ParentHash()), statedb, receipts, usedGas) + if err != nil { + return false, err + } + + return true, nil } func (self *debugApi) SeedHash(req *shared.Request) (interface{}, error) { -- cgit v1.2.3