Skip to content

Commit

Permalink
feat: enable listing API methods for Boost (#1442)
Browse files Browse the repository at this point in the history
* enable rpc.discover API

* Replace Lotus reference with Boost
  • Loading branch information
LexLuthr authored May 10, 2023
1 parent 8df5f44 commit 803878f
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 5 deletions.
5 changes: 3 additions & 2 deletions api/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/filecoin-project/go-jsonrpc/auth"
apitypes "github.com/filecoin-project/lotus/api/types"
)

// MODIFYING THE API INTERFACE
Expand Down Expand Up @@ -38,8 +39,8 @@ type Common interface {
//// Version provides information about API provider
//Version(context.Context) (APIVersion, error) //perm:read

//// Discover returns an OpenRPC document describing an RPC API.
//Discover(ctx context.Context) (apitypes.OpenRPCDocument, error) //perm:read
// Discover returns an OpenRPC document describing an RPC API.
Discover(ctx context.Context) (apitypes.OpenRPCDocument, error) //perm:read

//// trigger graceful shutdown
//Shutdown(context.Context) error //perm:admin
Expand Down
2 changes: 1 addition & 1 deletion api/docgen-openrpc/openrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func NewLotusOpenRPCDocument(Comments, GroupDocs map[string]string) *go_openrpc_
},
GetInfoFn: func() (info *meta_schema.InfoObject) {
info = &meta_schema.InfoObject{}
title := "Lotus RPC API"
title := "Boost RPC API"
info.Title = (*meta_schema.InfoObjectProperties)(&title)

version := build.BuildVersion
Expand Down
4 changes: 2 additions & 2 deletions api/docgen/docgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/filecoin-project/go-jsonrpc/auth"
"github.com/google/uuid"
"github.com/ipfs/go-cid"
graphsync "github.com/ipfs/go-graphsync"
"github.com/ipfs/go-graphsync"
textselector "github.com/ipld/go-ipld-selector-text-lite"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/libp2p/go-libp2p/core/metrics"
Expand Down Expand Up @@ -265,7 +265,7 @@ func init() {
addExample(apitypes.OpenRPCDocument{
"openrpc": "1.2.6",
"info": map[string]interface{}{
"title": "Lotus RPC API",
"title": "Boost RPC API",
"version": "1.2.1/generated=2020-11-22T08:22:42-06:00",
},
"methods": []interface{}{}},
Expand Down
14 changes: 14 additions & 0 deletions api/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions build/openrpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package build

import (
"bytes"
"compress/gzip"
"embed"
"encoding/json"
"log"

lotus_apitypes "github.com/filecoin-project/lotus/api/types"
)

//go:embed openrpc
var openrpcfs embed.FS

func mustReadGzippedOpenRPCDocument(data []byte) lotus_apitypes.OpenRPCDocument {
zr, err := gzip.NewReader(bytes.NewBuffer(data))
if err != nil {
log.Fatal(err)
}
m := lotus_apitypes.OpenRPCDocument{}
err = json.NewDecoder(zr).Decode(&m)
if err != nil {
log.Fatal(err)
}
err = zr.Close()
if err != nil {
log.Fatal(err)
}
return m
}

func OpenRPCDiscoverJSON_Boost() lotus_apitypes.OpenRPCDocument {
data, err := openrpcfs.ReadFile("openrpc/boost.json.gz")
if err != nil {
panic(err)
}
return mustReadGzippedOpenRPCDocument(data)
}
Binary file modified build/openrpc/boost.json.gz
Binary file not shown.
24 changes: 24 additions & 0 deletions documentation/en/api-v1-methods.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Groups
* [](#)
* [Discover](#discover)
* [Actor](#actor)
* [ActorSectorSize](#actorsectorsize)
* [Auth](#auth)
Expand Down Expand Up @@ -92,6 +94,28 @@
* [RuntimeSubsystems](#runtimesubsystems)
* [Sectors](#sectors)
* [SectorsRefs](#sectorsrefs)
##


### Discover


Perms: read

Inputs: `null`

Response:
```json
{
"info": {
"title": "Boost RPC API",
"version": "1.2.1/generated=2020-11-22T08:22:42-06:00"
},
"methods": [],
"openrpc": "1.2.6"
}
```

## Actor


Expand Down
5 changes: 5 additions & 0 deletions node/impl/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/filecoin-project/go-jsonrpc/auth"
apitypes "github.com/filecoin-project/lotus/api/types"
"github.com/gbrlsnchs/jwt/v3"
"github.com/google/uuid"
logging "github.com/ipfs/go-log/v2"
Expand Down Expand Up @@ -79,3 +80,7 @@ func (a *CommonAPI) Session(ctx context.Context) (uuid.UUID, error) {
func (a *CommonAPI) Closing(ctx context.Context) (<-chan struct{}, error) {
return make(chan struct{}), nil // relies on jsonrpc closing
}

func (a *CommonAPI) Discover(ctx context.Context) (apitypes.OpenRPCDocument, error) {
return build.OpenRPCDiscoverJSON_Boost(), nil
}
1 change: 1 addition & 0 deletions node/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func BoostHandler(a api.Boost, permissioned bool) (http.Handler, error) {
readerHandler, readerServerOpt := rpcenc.ReaderParamDecoder()
rpcServer := jsonrpc.NewServer(readerServerOpt)
rpcServer.Register("Filecoin", mapi)
rpcServer.AliasMethod("rpc.discover", "Filecoin.Discover")

m.Handle("/rpc/v0", rpcServer)
m.Handle("/rpc/streams/v0/push/{uuid}", readerHandler)
Expand Down

0 comments on commit 803878f

Please sign in to comment.