The ConsenSource rest api is a Rust server that has endpoints for fetching data from Postgres, and posting transactions/batches to the Processor.
Batches submitted from a client (web app, cli, etc) are sent to the /batches
endpoint as a serialized payload. This endpoint deserializes the payload and
creates a protocol buffer. The
ConsenSource proto formats can be found in the
common
repo.
The protobuf is sent to the Transaction
Processor, and the REST API
responds with a url /batch_statuses?<batch_ids>
. This endpoint monitors
Sawtooth state and returns a JSON payload indicating the status of a batch, and
if has been committed to a block.
A SSE server is created along with the REST API in order to send new data to web ui. Details on SSE can be found on Mozilla's docs. The Rust library we are using for SSE can be found here.
The ConsenSource REST API is written using the Rocket web framework. It requires nightly, though is very close to being stabilized.
rustup toolchain install nightly rustup default nightly
rustup component add rustfmt --toolchain nightly
cargo +nightly fmt -- --check
Most of the Rest API tests are integration tests. To startup a Postgres and Rest API instance and run these tests with code coverage metrics:
cd test
docker-compose up
cargo build
You'll need to run ConsenSource from the compose repo. The compose repo is a git submodules repo that references all the components that make up ConsenSource.
NOTE: The consensource-compose repo is only for pulling changes and running the project as a whole, it is not for development.