aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-10-27 05:24:09 +0800
committerzelig <viktor.tron@gmail.com>2015-10-27 05:24:09 +0800
commit4d005a2c1d2929dc770acd3a2bfed59495c70557 (patch)
tree0442ccefd85cc8b692c2c58a5916bc997909657a /rpc
parent3b4ffacd0c63952ceda96b3fafb050c91e72b420 (diff)
downloadgo-tangerine-4d005a2c1d2929dc770acd3a2bfed59495c70557.tar.gz
go-tangerine-4d005a2c1d2929dc770acd3a2bfed59495c70557.tar.zst
go-tangerine-4d005a2c1d2929dc770acd3a2bfed59495c70557.zip
rpc api: eth_getNatSpec
* xeth, rpc: implement eth_getNatSpec for tx confirmations * rename silly docserver -> httpclient * eth/backend: httpclient now accessible via eth.Ethereum init-d via config.DocRoot * cmd: introduce separate CLI flag for DocRoot (defaults to homedir) * common/path: delete unused assetpath func, separate HomeDir func
Diffstat (limited to 'rpc')
-rw-r--r--rpc/api/admin.go13
-rw-r--r--rpc/api/api_test.go8
-rw-r--r--rpc/api/eth.go14
-rw-r--r--rpc/api/eth_js.go6
-rw-r--r--rpc/api/utils.go5
5 files changed, 31 insertions, 15 deletions
diff --git a/rpc/api/admin.go b/rpc/api/admin.go
index eed8d8366..eb08fbc5d 100644
--- a/rpc/api/admin.go
+++ b/rpc/api/admin.go
@@ -25,7 +25,6 @@ import (
"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"
@@ -84,19 +83,15 @@ type adminApi struct {
ethereum *eth.Ethereum
codec codec.Codec
coder codec.ApiCoder
- docRoot string
- ds *docserver.DocServer
}
// create a new admin api instance
-func NewAdminApi(xeth *xeth.XEth, ethereum *eth.Ethereum, codec codec.Codec, docRoot string) *adminApi {
+func NewAdminApi(xeth *xeth.XEth, ethereum *eth.Ethereum, codec codec.Codec) *adminApi {
return &adminApi{
xeth: xeth,
ethereum: ethereum,
codec: codec,
coder: codec.New(nil),
- docRoot: docRoot,
- ds: docserver.New(docRoot),
}
}
@@ -258,7 +253,7 @@ func (self *adminApi) StartRPC(req *shared.Request) (interface{}, error) {
CorsDomain: args.CorsDomain,
}
- apis, err := ParseApiString(args.Apis, self.codec, self.xeth, self.ethereum, self.docRoot)
+ apis, err := ParseApiString(args.Apis, self.codec, self.xeth, self.ethereum)
if err != nil {
return false, err
}
@@ -439,7 +434,7 @@ func (self *adminApi) GetContractInfo(req *shared.Request) (interface{}, error)
return nil, shared.NewDecodeParamError(err.Error())
}
- infoDoc, err := natspec.FetchDocsForContract(args.Contract, self.xeth, self.ds)
+ infoDoc, err := natspec.FetchDocsForContract(args.Contract, self.xeth, self.ethereum.HTTPClient())
if err != nil {
return nil, err
}
@@ -459,7 +454,7 @@ func (self *adminApi) HttpGet(req *shared.Request) (interface{}, error) {
return nil, shared.NewDecodeParamError(err.Error())
}
- resp, err := self.ds.Get(args.Uri, args.Path)
+ resp, err := self.ethereum.HTTPClient().Get(args.Uri, args.Path)
if err != nil {
return nil, err
}
diff --git a/rpc/api/api_test.go b/rpc/api/api_test.go
index a4efb09c1..131ef68f8 100644
--- a/rpc/api/api_test.go
+++ b/rpc/api/api_test.go
@@ -30,7 +30,7 @@ import (
)
func TestParseApiString(t *testing.T) {
- apis, err := ParseApiString("", codec.JSON, nil, nil, "")
+ apis, err := ParseApiString("", codec.JSON, nil, nil)
if err == nil {
t.Errorf("Expected an err from parsing empty API string but got nil")
}
@@ -39,7 +39,7 @@ func TestParseApiString(t *testing.T) {
t.Errorf("Expected 0 apis from empty API string")
}
- apis, err = ParseApiString("eth", codec.JSON, nil, nil, "")
+ apis, err = ParseApiString("eth", codec.JSON, nil, nil)
if err != nil {
t.Errorf("Expected nil err from parsing empty API string but got %v", err)
}
@@ -48,7 +48,7 @@ func TestParseApiString(t *testing.T) {
t.Errorf("Expected 1 apis but got %d - %v", apis, apis)
}
- apis, err = ParseApiString("eth,eth", codec.JSON, nil, nil, "")
+ apis, err = ParseApiString("eth,eth", codec.JSON, nil, nil)
if err != nil {
t.Errorf("Expected nil err from parsing empty API string but got \"%v\"", err)
}
@@ -57,7 +57,7 @@ func TestParseApiString(t *testing.T) {
t.Errorf("Expected 2 apis but got %d - %v", apis, apis)
}
- apis, err = ParseApiString("eth,invalid", codec.JSON, nil, nil, "")
+ apis, err = ParseApiString("eth,invalid", codec.JSON, nil, nil)
if err == nil {
t.Errorf("Expected an err but got no err")
}
diff --git a/rpc/api/eth.go b/rpc/api/eth.go
index 4722682ff..b84ae31da 100644
--- a/rpc/api/eth.go
+++ b/rpc/api/eth.go
@@ -24,6 +24,7 @@ import (
"fmt"
"github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/common/natspec"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/shared"
@@ -67,6 +68,7 @@ var (
"eth_getUncleCountByBlockNumber": (*ethApi).GetUncleCountByBlockNumber,
"eth_getData": (*ethApi).GetData,
"eth_getCode": (*ethApi).GetData,
+ "eth_getNatSpec": (*ethApi).GetNatSpec,
"eth_sign": (*ethApi).Sign,
"eth_sendRawTransaction": (*ethApi).SendRawTransaction,
"eth_sendTransaction": (*ethApi).SendTransaction,
@@ -322,6 +324,18 @@ func (self *ethApi) SendTransaction(req *shared.Request) (interface{}, error) {
return v, nil
}
+func (self *ethApi) GetNatSpec(req *shared.Request) (interface{}, error) {
+ args := new(NewTxArgs)
+ if err := self.codec.Decode(req.Params, &args); err != nil {
+ return nil, shared.NewDecodeParamError(err.Error())
+ }
+
+ var jsontx = fmt.Sprintf(`{"params":[{"to":"%s","data": "%s"}]}`, args.To, args.Data)
+ notice := natspec.GetNotice(self.xeth, jsontx, self.ethereum.HTTPClient())
+
+ return notice, nil
+}
+
func (self *ethApi) EstimateGas(req *shared.Request) (interface{}, error) {
_, gas, err := self.doCall(req.Params)
if err != nil {
diff --git a/rpc/api/eth_js.go b/rpc/api/eth_js.go
index 393dac22f..75c103c9d 100644
--- a/rpc/api/eth_js.go
+++ b/rpc/api/eth_js.go
@@ -35,6 +35,12 @@ web3._extend({
call: 'eth_resend',
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]
})
],
properties:
diff --git a/rpc/api/utils.go b/rpc/api/utils.go
index 719cb8074..5a3ade46b 100644
--- a/rpc/api/utils.go
+++ b/rpc/api/utils.go
@@ -89,6 +89,7 @@ var (
"getBlockTransactionCount",
"getBlockUncleCount",
"getCode",
+ "getNatSpec",
"getCompilers",
"gasPrice",
"getStorageAt",
@@ -153,7 +154,7 @@ var (
)
// Parse a comma separated API string to individual api's
-func ParseApiString(apistr string, codec codec.Codec, xeth *xeth.XEth, eth *eth.Ethereum, docRoot string) ([]shared.EthereumApi, error) {
+func ParseApiString(apistr string, codec codec.Codec, xeth *xeth.XEth, eth *eth.Ethereum) ([]shared.EthereumApi, error) {
if len(strings.TrimSpace(apistr)) == 0 {
return nil, fmt.Errorf("Empty apistr provided")
}
@@ -164,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, docRoot)
+ apis[i] = NewAdminApi(xeth, eth, codec)
case shared.DebugApiName:
apis[i] = NewDebugApi(xeth, eth, codec)
case shared.DbApiName: