feat: gateway: OpenRPC support
This commit is contained in:
parent
48aa0131bf
commit
032e598962
4
Makefile
4
Makefile
@ -330,7 +330,7 @@ docsgen-md-storage: docsgen-md-bin
|
|||||||
docsgen-md-worker: docsgen-md-bin
|
docsgen-md-worker: docsgen-md-bin
|
||||||
./docgen-md "api/api_worker.go" "Worker" "api" "./api" > documentation/en/api-v0-methods-worker.md
|
./docgen-md "api/api_worker.go" "Worker" "api" "./api" > documentation/en/api-v0-methods-worker.md
|
||||||
|
|
||||||
docsgen-openrpc: docsgen-openrpc-full docsgen-openrpc-storage docsgen-openrpc-worker
|
docsgen-openrpc: docsgen-openrpc-full docsgen-openrpc-storage docsgen-openrpc-worker docsgen-openrpc-gateway
|
||||||
|
|
||||||
docsgen-openrpc-full: docsgen-openrpc-bin
|
docsgen-openrpc-full: docsgen-openrpc-bin
|
||||||
./docgen-openrpc "api/api_full.go" "FullNode" "api" "./api" -gzip > build/openrpc/full.json.gz
|
./docgen-openrpc "api/api_full.go" "FullNode" "api" "./api" -gzip > build/openrpc/full.json.gz
|
||||||
@ -338,6 +338,8 @@ docsgen-openrpc-storage: docsgen-openrpc-bin
|
|||||||
./docgen-openrpc "api/api_storage.go" "StorageMiner" "api" "./api" -gzip > build/openrpc/miner.json.gz
|
./docgen-openrpc "api/api_storage.go" "StorageMiner" "api" "./api" -gzip > build/openrpc/miner.json.gz
|
||||||
docsgen-openrpc-worker: docsgen-openrpc-bin
|
docsgen-openrpc-worker: docsgen-openrpc-bin
|
||||||
./docgen-openrpc "api/api_worker.go" "Worker" "api" "./api" -gzip > build/openrpc/worker.json.gz
|
./docgen-openrpc "api/api_worker.go" "Worker" "api" "./api" -gzip > build/openrpc/worker.json.gz
|
||||||
|
docsgen-openrpc-gateway: docsgen-openrpc-bin
|
||||||
|
./docgen-openrpc "api/api_gateway.go" "Gateway" "api" "./api" -gzip > build/openrpc/gateway.json.gz
|
||||||
|
|
||||||
.PHONY: docsgen docsgen-md-bin docsgen-openrpc-bin
|
.PHONY: docsgen docsgen-md-bin docsgen-openrpc-bin
|
||||||
|
|
||||||
|
@ -66,4 +66,5 @@ type Gateway interface {
|
|||||||
StateWaitMsg(ctx context.Context, cid cid.Cid, confidence uint64, limit abi.ChainEpoch, allowReplaced bool) (*MsgLookup, error)
|
StateWaitMsg(ctx context.Context, cid cid.Cid, confidence uint64, limit abi.ChainEpoch, allowReplaced bool) (*MsgLookup, error)
|
||||||
WalletBalance(context.Context, address.Address) (types.BigInt, error)
|
WalletBalance(context.Context, address.Address) (types.BigInt, error)
|
||||||
Version(context.Context) (APIVersion, error)
|
Version(context.Context) (APIVersion, error)
|
||||||
|
Discover(context.Context) (apitypes.OpenRPCDocument, error)
|
||||||
}
|
}
|
||||||
|
@ -350,6 +350,10 @@ func GetAPIType(name, pkg string) (i interface{}, t reflect.Type, permStruct []r
|
|||||||
i = &api.WorkerStruct{}
|
i = &api.WorkerStruct{}
|
||||||
t = reflect.TypeOf(new(struct{ api.Worker })).Elem()
|
t = reflect.TypeOf(new(struct{ api.Worker })).Elem()
|
||||||
permStruct = append(permStruct, reflect.TypeOf(api.WorkerStruct{}.Internal))
|
permStruct = append(permStruct, reflect.TypeOf(api.WorkerStruct{}.Internal))
|
||||||
|
case "Gateway":
|
||||||
|
i = &api.GatewayStruct{}
|
||||||
|
t = reflect.TypeOf(new(struct{ api.Gateway })).Elem()
|
||||||
|
permStruct = append(permStruct, reflect.TypeOf(api.GatewayStruct{}.Internal))
|
||||||
default:
|
default:
|
||||||
panic("unknown type")
|
panic("unknown type")
|
||||||
}
|
}
|
||||||
|
@ -512,6 +512,8 @@ type GatewayStruct struct {
|
|||||||
|
|
||||||
ChainReadObj func(p0 context.Context, p1 cid.Cid) ([]byte, error) ``
|
ChainReadObj func(p0 context.Context, p1 cid.Cid) ([]byte, error) ``
|
||||||
|
|
||||||
|
Discover func(p0 context.Context) (apitypes.OpenRPCDocument, error) ``
|
||||||
|
|
||||||
GasEstimateMessageGas func(p0 context.Context, p1 *types.Message, p2 *MessageSendSpec, p3 types.TipSetKey) (*types.Message, error) ``
|
GasEstimateMessageGas func(p0 context.Context, p1 *types.Message, p2 *MessageSendSpec, p3 types.TipSetKey) (*types.Message, error) ``
|
||||||
|
|
||||||
MpoolPush func(p0 context.Context, p1 *types.SignedMessage) (cid.Cid, error) ``
|
MpoolPush func(p0 context.Context, p1 *types.SignedMessage) (cid.Cid, error) ``
|
||||||
@ -3299,6 +3301,17 @@ func (s *GatewayStub) ChainReadObj(p0 context.Context, p1 cid.Cid) ([]byte, erro
|
|||||||
return *new([]byte), ErrNotSupported
|
return *new([]byte), ErrNotSupported
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *GatewayStruct) Discover(p0 context.Context) (apitypes.OpenRPCDocument, error) {
|
||||||
|
if s.Internal.Discover == nil {
|
||||||
|
return *new(apitypes.OpenRPCDocument), ErrNotSupported
|
||||||
|
}
|
||||||
|
return s.Internal.Discover(p0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GatewayStub) Discover(p0 context.Context) (apitypes.OpenRPCDocument, error) {
|
||||||
|
return *new(apitypes.OpenRPCDocument), ErrNotSupported
|
||||||
|
}
|
||||||
|
|
||||||
func (s *GatewayStruct) GasEstimateMessageGas(p0 context.Context, p1 *types.Message, p2 *MessageSendSpec, p3 types.TipSetKey) (*types.Message, error) {
|
func (s *GatewayStruct) GasEstimateMessageGas(p0 context.Context, p1 *types.Message, p2 *MessageSendSpec, p3 types.TipSetKey) (*types.Message, error) {
|
||||||
if s.Internal.GasEstimateMessageGas == nil {
|
if s.Internal.GasEstimateMessageGas == nil {
|
||||||
return nil, ErrNotSupported
|
return nil, ErrNotSupported
|
||||||
|
@ -52,3 +52,11 @@ func OpenRPCDiscoverJSON_Worker() apitypes.OpenRPCDocument {
|
|||||||
}
|
}
|
||||||
return mustReadGzippedOpenRPCDocument(data)
|
return mustReadGzippedOpenRPCDocument(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func OpenRPCDiscoverJSON_Gateway() apitypes.OpenRPCDocument {
|
||||||
|
data, err := openrpcfs.ReadFile("openrpc/gateway.json.gz")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return mustReadGzippedOpenRPCDocument(data)
|
||||||
|
}
|
||||||
|
Binary file not shown.
BIN
build/openrpc/gateway.json.gz
Normal file
BIN
build/openrpc/gateway.json.gz
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -16,6 +16,7 @@ func TestOpenRPCDiscoverJSON_Version(t *testing.T) {
|
|||||||
OpenRPCDiscoverJSON_Full,
|
OpenRPCDiscoverJSON_Full,
|
||||||
OpenRPCDiscoverJSON_Miner,
|
OpenRPCDiscoverJSON_Miner,
|
||||||
OpenRPCDiscoverJSON_Worker,
|
OpenRPCDiscoverJSON_Worker,
|
||||||
|
OpenRPCDiscoverJSON_Gateway,
|
||||||
} {
|
} {
|
||||||
doc := docFn()
|
doc := docFn()
|
||||||
if got, ok := doc["openrpc"]; !ok || got != openRPCDocVersion {
|
if got, ok := doc["openrpc"]; !ok || got != openRPCDocVersion {
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/filecoin-project/go-state-types/dline"
|
"github.com/filecoin-project/go-state-types/dline"
|
||||||
"github.com/filecoin-project/go-state-types/network"
|
"github.com/filecoin-project/go-state-types/network"
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
|
apitypes "github.com/filecoin-project/lotus/api/types"
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
@ -144,6 +145,10 @@ func (gw *Node) checkTimestamp(at time.Time) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gw *Node) Discover(ctx context.Context) (apitypes.OpenRPCDocument, error) {
|
||||||
|
return build.OpenRPCDiscoverJSON_Gateway(), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (gw *Node) Version(ctx context.Context) (api.APIVersion, error) {
|
func (gw *Node) Version(ctx context.Context) (api.APIVersion, error) {
|
||||||
return gw.target.Version(ctx)
|
return gw.target.Version(ctx)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user