2020-04-07 13:28:09 +00:00
|
|
|
## BDLedger API
|
|
|
|
|
|
|
|
### Documentation
|
|
|
|
|
|
|
|
See [API documentation](..\docs\apis.md)
|
|
|
|
|
|
|
|
### Development
|
|
|
|
|
|
|
|
#### Generating gRPC code in languages
|
|
|
|
|
|
|
|
##### Installling tools
|
|
|
|
|
2021-07-14 09:33:28 +00:00
|
|
|
Download the [Protocol Buffers compiler](https://github.com/protocolbuffers/protobuf/releases) (protoc-3.17.3-*)+ for
|
|
|
|
your platform and add `protoc` to `PATH` environment variable
|
2020-04-07 13:28:09 +00:00
|
|
|
|
2021-07-14 09:33:28 +00:00
|
|
|
For generating Go code, install `protoc-gen-go` (v1.27.1+):
|
2021-07-15 07:30:07 +00:00
|
|
|
|
|
|
|
```shell
|
2021-07-14 09:33:28 +00:00
|
|
|
GIT_TAG="v1.27.1"
|
2020-09-22 08:21:24 +00:00
|
|
|
go get -d -u google.golang.org/protobuf/cmd/protoc-gen-go
|
|
|
|
git -C "$(go env GOPATH)"/src/google.golang.org/protobuf checkout $GIT_TAG
|
|
|
|
go install google.golang.org/protobuf/cmd/protoc-gen-go
|
2020-04-07 13:28:09 +00:00
|
|
|
```
|
2020-09-22 08:21:24 +00:00
|
|
|
|
2021-07-14 09:33:28 +00:00
|
|
|
Also install `protoc-gen-go-grpc` v1.1.0+:
|
2021-07-15 07:30:07 +00:00
|
|
|
|
|
|
|
```shell
|
2021-07-14 09:33:28 +00:00
|
|
|
go get -u google.golang.org/grpc/cmd/protoc-gen-go-grpc
|
2020-09-22 08:21:24 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Or install using [gobin](https://github.com/myitcv/gobin):
|
2021-07-15 07:30:07 +00:00
|
|
|
|
|
|
|
```shell
|
2020-09-22 08:21:24 +00:00
|
|
|
gobin google.golang.org/protobuf/cmd/protoc-gen-go
|
|
|
|
gobin google.golang.org/grpc/cmd/protoc-gen-go-grpc
|
|
|
|
```
|
|
|
|
|
2021-07-15 07:30:07 +00:00
|
|
|
For generating HTTP JSON APIs with [grpc-gateway](https://grpc-ecosystem.github.io/grpc-gateway/), follow
|
|
|
|
the [documentation](https://github.com/grpc-ecosystem/grpc-gateway/tree/v2#installation).
|
|
|
|
|
|
|
|
For generating validators
|
|
|
|
install [go-proto-validators](https://github.com/mwitkow/go-proto-validators/tree/master/protoc-gen-govalidators):
|
2020-04-07 13:28:09 +00:00
|
|
|
|
2021-07-15 07:30:07 +00:00
|
|
|
```shell
|
2021-02-12 13:12:20 +00:00
|
|
|
go get github.com/mwitkow/go-proto-validators/protoc-gen-govalidators
|
|
|
|
```
|
|
|
|
|
2020-04-07 13:28:09 +00:00
|
|
|
For generating Java code: From `bdledger-sdk-java` run `gradle generateProto`
|
|
|
|
|
2021-07-15 07:30:07 +00:00
|
|
|
For generating Node.js code and/or TypeScript definitions), install Node.js then run:
|
|
|
|
|
|
|
|
```shell
|
2020-12-07 08:32:36 +00:00
|
|
|
npm install
|
2020-04-07 13:28:09 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
For frontend JavaScript:
|
2021-07-15 07:30:07 +00:00
|
|
|
|
|
|
|
```shell
|
2020-04-07 13:28:09 +00:00
|
|
|
git clone https://github.com/grpc/grpc-web
|
|
|
|
cd grpc-web
|
|
|
|
sudo make install-plugin
|
|
|
|
```
|
|
|
|
|
|
|
|
References:
|
2021-07-15 07:30:07 +00:00
|
|
|
|
2020-04-07 13:28:09 +00:00
|
|
|
- [Go Quick Start](https://grpc.io/docs/quickstart/go.html#prerequisites)
|
|
|
|
- [gRPC Go FAQ](https://github.com/grpc/grpc-go#faq)
|
|
|
|
|
|
|
|
**TODO: Look into [protobuf.js](https://github.com/protobufjs/protobuf.js) for Nodes.js and frontend**
|
|
|
|
**TODO: Look into [Kroto+](https://github.com/marcoferrer/kroto-plus) for Kotlin**
|
|
|
|
|
|
|
|
##### Generating code
|
|
|
|
|
|
|
|
Run:
|
2021-07-15 07:30:07 +00:00
|
|
|
|
|
|
|
```shell
|
2021-02-12 13:12:20 +00:00
|
|
|
./scripts/gen [-a, --async] [go] [gohttp] [nodejs] [docs]
|
2020-04-07 13:28:09 +00:00
|
|
|
```
|
2021-07-15 07:30:07 +00:00
|
|
|
|
|
|
|
`nodejs`: For generating static Node.js code and TypeScript definitions
|
|
|
|
|
|
|
|
Use `-a` or `--async` to speed up generation by asynchronously and concurrently generating all code and documentation (
|
|
|
|
script will exit without waiting for completion)
|
|
|
|
|
|
|
|
For generating TypeScript definitions to be used with `@grpc/proto-loader`, run:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
invoke gen -t types
|
|
|
|
```
|
2020-04-07 13:28:09 +00:00
|
|
|
|
|
|
|
#### Generateing documentation
|
|
|
|
|
|
|
|
Install Go then run:
|
|
|
|
|
2021-07-15 07:30:07 +00:00
|
|
|
```shell
|
2020-04-07 13:28:09 +00:00
|
|
|
go get -u github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc
|
2020-04-07 16:49:17 +00:00
|
|
|
./scripts/gen [-a, --async] docs
|
2020-04-07 13:28:09 +00:00
|
|
|
```
|
2021-02-12 13:12:20 +00:00
|
|
|
|