This is a CLI application for the Stacks Signer API. It provides an API server for interacting with a Signer. It can run an API server with or without simulated data, generate API documentation, and run a Swagger UI server.
- Rust
- SQLite
To get started, first, make sure you have Rust installed. You can follow the Rust installation instructions here.
Next, clone this project and navigate to its root directory in your command prompt or terminal.
- Clone the repository:
git clone https://github.com/Trust-Machines/stacks-sbtc.git
- Navigate to the project folder:
cd stacks-sbtc/stacks-signer-api
- Build the CLI:
cargo build --release
- Navigate to the output folder:
cd target/release
To run the API server, run the following command
./stacks-signer-api run
--address
- Address to run the API server on (Default:0.0.0.0
)--port
- Port to run the API server on (Default:3030
)
To run the API server with simulated data, run the following command
./stacks-signer-api simulator
--address
- Address to run the API server on (Default:0.0.0.0
)--port
- Port to run the API server on (Default:3030
)
To run a local instance of Swagger UI for this API, execute the following command:
./stacks-signer-api swagger
--address
- Address to run the API server on (Default:0.0.0.0
)--port
- Port to run the API server on (Default:3030
)
By default, the Swagger UI server will be accessible at http://0.0.0.0:3030/swagger-ui/
.
To generate OpenAPI json documentation for the API, run the following command:
./stacks-signer-api docs
--output
- Output file to save the API documentation to. If not provided, it prints to stdout.
Run the Swagger CLI option to obtain a detailed breakdown of the API endpoints, requests, and responses.
The Signer API uses a custom error type Error
, which wraps SQLx and parse errors. The error type is defined in the root of the project and implements the warp::reject::Reject
trait to enable proper handling in Warp filters.
The Signer API uses SQLite as the backend database, and the sqlx
crate is utilized for handling database connections and queries.
Database operations are organized in separate modules according to their purpose (e.g., keys
, signers
, transaction
, vote
). Each module contains functions for interacting with the database, such as retrieving records, inserting records, and deleting records.
To use a file-based SQLite database, set the DATABASE_URL
environment variable with the file path:
export DATABASE_URL="sqlite://path/to/your/database.sqlite3"
If the DATABASE_URL
environment variable is not set, the API will use an in-memory SQLite database by default. Note that using an in-memory database is suitable for testing purposes but not recommended for production use, as the data will not be persisted after terminating the application.
To run the server with the database specified in the DATABASE_URL
environment variable (or an in-memory database if the variable is not set), use the following command:
./stacks-signer-api run
Alternatively, run the following command:
DATABASE_URL="sqlite://path/to/your/database.sqlite3" ./stacks-signer-api run
To make use of sqlx
and verify the sql queries on your own, you should follow the following steps:
- remove
sqlx-data.json
- install
sqlx-cli
version0.5.13
. Socargo install sqlx-cli --version=0.5.13
- make sure you have sqlite installed
- create a
.env
file in thestacks-signer-api
root folder with the env variableDATABASE_URL
- The url for sqlite is in the format
DATABASE_URL=sqlite://$(pwd)/stacks-signer-api/dev-signer-api.sqlite
- generate the test db using
sqlx database create
- run the
init
migrationsqlx migrate run
- prepare the
offline
static check cachecargo sqlx prepare -- --lib
This project is licensed under GPLv3.