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
This commit is contained in:
@ -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
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
Reference in New Issue
Block a user