Skip to content

Commit

Permalink
feat: update schema for mainnet, simplify go-schemagen tool, improve …
Browse files Browse the repository at this point in the history
…README (filecoin-shipyard#4)

* Greatly simplify schemagen tool

Also detects API methods that return channels and
labels them as subscription methods.

* Rearrange source files

* Update schemas and improve README

* Fix imports

* Clean up files for publishing, delete lotus symlink

* Update README.md

* refactor: use official lotus release

* fix: no need to remove lotus now

Co-authored-by: Alan Shaw <[email protected]>
  • Loading branch information
jimpick and Alan Shaw authored Oct 19, 2020
1 parent de4b428 commit 878e732
Show file tree
Hide file tree
Showing 21 changed files with 493 additions and 5,419 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
node_modules
yarn.lock
package-lock.json
dual-publish-tmp
tmp*
lotus
go-schemagen/lotus
.vscode
3 changes: 1 addition & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
go-docgen
go-schemagen
go-schemagen/
lotus
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,59 @@ This package contains some .js files that describe methods exported by the
See [filecoin-shipyard/js-lotus-client](https://github.com/filecoin-shipyard/js-lotus-client)
for examples that show how to use these schemas.

## Usage

```js
const { LotusRPC } = require('@filecoin-shipyard/lotus-client-rpc')
const { NodejsProvider } = require('@filecoin-shipyard/lotus-client-provider-nodejs')
const { mainnet } = require('@filecoin-shipyard/lotus-client-schema')

const url = 'ws://127.0.0.1:7777/rpc/v0'
const provider = new NodejsProvider(url)
const client = new LotusRPC(provider, { schema: mainnet.fullNode })
```

## Schemas

The following schema objects are exported:

* `mainnet.fullNode` - used to talk to a Lotus "Full Node" (`lotus`)
* `mainnet.storageMiner` - used to talk to a Lotus storage miner (`lotus-miner`)
* `mainnet.gatewayApi` - used to talk to public Lotus API Gateway (`lotus-gateway`)
* `mainnet.walletApi` - a subset of methods for wallets
* `mainnet.workerApi` - used to talk to `lotus-worker` (for mining)
* `mainnet.common` - a subset of methods used by a number of different daemons

## Schema Format

Right now, the schema is extremely simple, as the JS library only needs to know if a method supports subscriptions or not. The JS library is very light, so all method parameters are just passed through to the JSON-RPC request.

In the future, the schema could be extended to provide more parameter and type information to make it easier to validate and marshal/unmarshal requests and responses.

For example, the entry for the `ChainHead` method is currently just:

```
ChainHead: {}
```

The `ChainNotify` entry supports JSON-RPC subscriptions, so it looks like this:

```
ChainNotify: {
subscription: true
}
```

Each API is represented by an Object with a single `methods` property which
is an Object with all the methods supported.

If you are trying to use a JSON-RPC API method that isn't in the schema yet,
don't be afraid to "monkey-patch" the schemas distributed via this package
to add any missing methods ... eg. `mainnet.fullNode.methods.MyMissingMethod = {}`

## Updating the schemas

Lotus is constantly being updated. There is a simple tool (written in go) in the `go-schemagen` directory that links against a Lotus source code tree (modify the replace directory in go.mod or make a symlink) and outputs the current set of method signatures as JSON.

## License

Expand Down
14 changes: 0 additions & 14 deletions go-schemagen/common/go.mod

This file was deleted.

1,882 changes: 0 additions & 1,882 deletions go-schemagen/common/go.sum

This file was deleted.

3 changes: 0 additions & 3 deletions go-schemagen/common/run.sh

This file was deleted.

276 changes: 0 additions & 276 deletions go-schemagen/common/schemagen.go

This file was deleted.

10 changes: 0 additions & 10 deletions go-schemagen/full-node/go.mod

This file was deleted.

Loading

0 comments on commit 878e732

Please sign in to comment.