Skip to content

Commit

Permalink
Add script to generate client. Unify some names.
Browse files Browse the repository at this point in the history
  • Loading branch information
piohei committed Sep 19, 2024
1 parent ce591b5 commit 1835e19
Show file tree
Hide file tree
Showing 40 changed files with 448 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ target/
README.md
TODO.md
manual_test.nu
config.toml
config.toml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
target/
.env
schema.yaml
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,22 @@ RUN rustup component add cargo

# TODO: Hacky but it works
RUN mkdir -p ./src
RUN mkdir -p ./crates/base-api-types/src
RUN mkdir -p ./crates/postgres-docker-utils/src
RUN mkdir -p ./crates/tx-sitter-client/src

# Copy only Cargo.toml for better caching
COPY .cargo/config.toml .cargo/config.toml
COPY ./Cargo.toml ./Cargo.toml
COPY ./Cargo.lock ./Cargo.lock
COPY ./crates/base-api-types/Cargo.toml ./crates/base-api-types/Cargo.toml
COPY ./crates/postgres-docker-utils/Cargo.toml ./crates/postgres-docker-utils/Cargo.toml
COPY ./crates/tx-sitter-client/Cargo.toml ./crates/tx-sitter-client/Cargo.toml

RUN echo "fn main() {}" > ./src/main.rs
RUN echo "fn main() {}" > ./crates/base-api-types/src/main.rs
RUN echo "fn main() {}" > ./crates/postgres-docker-utils/src/main.rs
RUN echo "fn main() {}" > ./crates/tx-sitter-client/src/main.rs

# Prebuild dependencies
RUN cargo fetch
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,16 @@ can be used instead.
Client crate is located in `creates/tx-sitter-client`. It is generated using official OpenAPI generator with modified template files. Modified template files are located in `client-template/` directory. Possible files to overwrite could be fined here https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources/rust.
To generate client OpenAPI spec schema is required. To get one just run tx-sitter and then call `/schema.yaml` endpoint. To download schema you can use curl for example:
### Runnin script
Just run `./generate_api_client.sh`.
### Manual generation
To generate client OpenAPI spec schema is required. To get one just run api spec generator command:
```shell
curl http://localhost:3000/schema.yml > schema.yaml
cargo run --bin api_spec_generator > schema.yaml
```

Client generation is done by using default OpenAPI tools. You can install generator or use docker image as shown below:
Expand Down
20 changes: 10 additions & 10 deletions crates/tx-sitter-client/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ Cargo.toml
README.md
docs/AdminV1Api.md
docs/CreateApiKeyResponse.md
docs/CreateNetworkRequest.md
docs/CreateRelayerRequest.md
docs/CreateRelayerResponse.md
docs/GetTxResponse.md
docs/JsonRpcVersion.md
docs/NetworkInfo.md
docs/NewNetworkInfo.md
docs/RelayerGasPriceLimit.md
docs/RelayerInfo.md
docs/RelayerUpdate.md
docs/NetworkResponse.md
docs/RelayerGasPriceLimitResponse.md
docs/RelayerResponse.md
docs/RelayerUpdateRequest.md
docs/RelayerV1Api.md
docs/RpcRequest.md
docs/SendTxRequest.md
Expand All @@ -28,16 +28,16 @@ src/apis/relayer_v1_api.rs
src/apis/service_api.rs
src/lib.rs
src/models/create_api_key_response.rs
src/models/create_network_request.rs
src/models/create_relayer_request.rs
src/models/create_relayer_response.rs
src/models/get_tx_response.rs
src/models/json_rpc_version.rs
src/models/mod.rs
src/models/network_info.rs
src/models/new_network_info.rs
src/models/relayer_gas_price_limit.rs
src/models/relayer_info.rs
src/models/relayer_update.rs
src/models/network_response.rs
src/models/relayer_gas_price_limit_response.rs
src/models/relayer_response.rs
src/models/relayer_update_request.rs
src/models/rpc_request.rs
src/models/send_tx_request.rs
src/models/send_tx_response.rs
Expand Down
2 changes: 1 addition & 1 deletion crates/tx-sitter-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "tx-sitter-client"
version = "0.1.0"
authors = ["OpenAPI Generator team and contributors"]
description = "A transaction relayer service! ## Operating a relayer Below is a guide on using this service. Note that septs 1 through 4 require authentication using HTTP Basic auth. Using swagger explorer make sure to click the authorize button and use the correct credentials. Default dev creds are `admin:admin`. ### 1. Setup a network tx-sitter keeps track of supported networks in its internal database. In order to be able to create any relayers at least one network must be present. To add a network use the `POST /1/admin/networks/:chain_id` endpoint. To see the list of currently added networks use the `GET /1/admin/networks` endpoint. ### 2. Create a relayer A relayer is an abstraction layer on top of a private key stored locally (for testing purposes only!) or using a secrets manager (currently only AWS KMS is supported). To create a relayer use the `POST /1/admin/relayer` endpoint. The data returned will contain a relayer id, make sure to copy it to the clipboard. ### 3. Create an API key By itself a relayer is not very useful. In order to send transactions one must create an API key. To do that use the `POST /1/admin/relayer/:relayer_id/key` endpoint. **Make sure to copy the API key from the response. It's not possible to recover it!** But it's always possible to create a new one. ### 4. Use the API key Once an API keys has been created it's possible to use the relayer api to, among other things, send transactions. You can use the `POST /1/api/:api_token/tx` endpoint to create a transaction. "
description = "A transaction relayer service! ## Operating a relayer Below is a guide on using this service. Note that steps 1 through 4 require authentication using HTTP Basic auth. Using swagger explorer make sure to click the authorize button and use the correct credentials. Default dev creds are `admin:admin`. ### 1. Setup a network tx-sitter keeps track of supported networks in its internal database. In order to be able to create any relayers at least one network must be present. To add a network use the `POST /1/admin/networks/:chain_id` endpoint. To see the list of currently added networks use the `GET /1/admin/networks` endpoint. ### 2. Create a relayer A relayer is an abstraction layer on top of a private key stored locally (for testing purposes only!) or using a secrets manager (currently only AWS KMS is supported). To create a relayer use the `POST /1/admin/relayer` endpoint. The data returned will contain a relayer id, make sure to copy it to the clipboard. ### 3. Create an API key By itself a relayer is not very useful. In order to send transactions one must create an API key. To do that use the `POST /1/admin/relayer/:relayer_id/key` endpoint. **Make sure to copy the API key from the response. It's not possible to recover it!** But it's always possible to create a new one. ### 4. Use the API key Once an API keys has been created it's possible to use the relayer api to, among other things, send transactions. You can use the `POST /1/api/:api_token/tx` endpoint to create a transaction. "
# Override this license by providing a License Object in the OpenAPI.
license = "Unlicense"
edition = "2021"
Expand Down
14 changes: 7 additions & 7 deletions crates/tx-sitter-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
A transaction relayer service!

## Operating a relayer
Below is a guide on using this service. Note that septs 1 through 4 require authentication using HTTP Basic auth. Using swagger explorer make sure to click the authorize button and use the correct credentials. Default dev creds are `admin:admin`.
Below is a guide on using this service. Note that steps 1 through 4 require authentication using HTTP Basic auth. Using swagger explorer make sure to click the authorize button and use the correct credentials. Default dev creds are `admin:admin`.

### 1. Setup a network
tx-sitter keeps track of supported networks in its internal database. In order to be able to create any relayers at least one network must be present. To add a network use the `POST /1/admin/networks/:chain_id` endpoint.
Expand Down Expand Up @@ -47,7 +47,7 @@ tx-sitter-client = { path = "./tx-sitter-client" }

## Documentation for API Endpoints

All URIs are relative to *http://localhost:3000*
All URIs are relative to *http://localhost:8000*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
Expand All @@ -69,15 +69,15 @@ Class | Method | HTTP request | Description
## Documentation For Models

- [CreateApiKeyResponse](docs/CreateApiKeyResponse.md)
- [CreateNetworkRequest](docs/CreateNetworkRequest.md)
- [CreateRelayerRequest](docs/CreateRelayerRequest.md)
- [CreateRelayerResponse](docs/CreateRelayerResponse.md)
- [GetTxResponse](docs/GetTxResponse.md)
- [JsonRpcVersion](docs/JsonRpcVersion.md)
- [NetworkInfo](docs/NetworkInfo.md)
- [NewNetworkInfo](docs/NewNetworkInfo.md)
- [RelayerGasPriceLimit](docs/RelayerGasPriceLimit.md)
- [RelayerInfo](docs/RelayerInfo.md)
- [RelayerUpdate](docs/RelayerUpdate.md)
- [NetworkResponse](docs/NetworkResponse.md)
- [RelayerGasPriceLimitResponse](docs/RelayerGasPriceLimitResponse.md)
- [RelayerResponse](docs/RelayerResponse.md)
- [RelayerUpdateRequest](docs/RelayerUpdateRequest.md)
- [RpcRequest](docs/RpcRequest.md)
- [SendTxRequest](docs/SendTxRequest.md)
- [SendTxResponse](docs/SendTxResponse.md)
Expand Down
22 changes: 11 additions & 11 deletions crates/tx-sitter-client/docs/AdminV1Api.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# \AdminV1Api

All URIs are relative to *http://localhost:3000*
All URIs are relative to *http://localhost:8000*

Method | HTTP request | Description
------------- | ------------- | -------------
Expand All @@ -17,7 +17,7 @@ Method | HTTP request | Description

## create_network

> create_network(chain_id, new_network_info)
> create_network(chain_id, create_network_request)
Create Network

### Parameters
Expand All @@ -26,7 +26,7 @@ Create Network
Name | Type | Description | Required | Notes
------------- | ------------- | ------------- | ------------- | -------------
**chain_id** | **i32** | | [required] |
**new_network_info** | [**NewNetworkInfo**](NewNetworkInfo.md) | | [required] |
**create_network_request** | [**CreateNetworkRequest**](CreateNetworkRequest.md) | | [required] |

### Return type

Expand Down Expand Up @@ -74,7 +74,7 @@ Name | Type | Description | Required | Notes

## get_networks

> Vec<models::NetworkInfo> get_networks()
> Vec<models::NetworkResponse> get_networks()
Get Networks

### Parameters
Expand All @@ -83,7 +83,7 @@ This endpoint does not need any parameter.

### Return type

[**Vec<models::NetworkInfo>**](NetworkInfo.md)
[**Vec<models::NetworkResponse>**](NetworkResponse.md)

### Authorization

Expand All @@ -99,7 +99,7 @@ This endpoint does not need any parameter.

## get_relayer

> models::RelayerInfo get_relayer(relayer_id)
> models::RelayerResponse get_relayer(relayer_id)
Get Relayer

### Parameters
Expand All @@ -111,7 +111,7 @@ Name | Type | Description | Required | Notes

### Return type

[**models::RelayerInfo**](RelayerInfo.md)
[**models::RelayerResponse**](RelayerResponse.md)

### Authorization

Expand All @@ -127,7 +127,7 @@ Name | Type | Description | Required | Notes

## get_relayers

> Vec<models::RelayerInfo> get_relayers()
> Vec<models::RelayerResponse> get_relayers()
Get Relayers

### Parameters
Expand All @@ -136,7 +136,7 @@ This endpoint does not need any parameter.

### Return type

[**Vec<models::RelayerInfo>**](RelayerInfo.md)
[**Vec<models::RelayerResponse>**](RelayerResponse.md)

### Authorization

Expand Down Expand Up @@ -210,7 +210,7 @@ Name | Type | Description | Required | Notes

## update_relayer

> update_relayer(relayer_id, relayer_update)
> update_relayer(relayer_id, relayer_update_request)
Update Relayer

### Parameters
Expand All @@ -219,7 +219,7 @@ Update Relayer
Name | Type | Description | Required | Notes
------------- | ------------- | ------------- | ------------- | -------------
**relayer_id** | **String** | | [required] |
**relayer_update** | [**RelayerUpdate**](RelayerUpdate.md) | | [required] |
**relayer_update_request** | [**RelayerUpdateRequest**](RelayerUpdateRequest.md) | | [required] |

### Return type

Expand Down
13 changes: 13 additions & 0 deletions crates/tx-sitter-client/docs/CreateNetworkRequest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# CreateNetworkRequest

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**name** | **String** | |
**http_rpc** | **String** | |
**ws_rpc** | **String** | |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


14 changes: 14 additions & 0 deletions crates/tx-sitter-client/docs/NetworkResponse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# NetworkResponse

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**chain_id** | **i32** | |
**name** | **String** | |
**http_rpc** | **String** | |
**ws_rpc** | **String** | |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


12 changes: 12 additions & 0 deletions crates/tx-sitter-client/docs/RelayerGasPriceLimitResponse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# RelayerGasPriceLimitResponse

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**value** | [**base_api_types::DecimalU256**](base_api_types::DecimalU256.md) | A decimal 256-bit unsigned integer | [default to 0]
**chain_id** | **i64** | |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


21 changes: 21 additions & 0 deletions crates/tx-sitter-client/docs/RelayerResponse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# RelayerResponse

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | **String** | |
**name** | **String** | |
**chain_id** | **i32** | |
**key_id** | **String** | |
**address** | [**base_api_types::Address**](base_api_types::Address.md) | Hex encoded ethereum address |
**nonce** | **i32** | |
**current_nonce** | **i32** | |
**max_inflight_txs** | **i32** | |
**max_queued_txs** | **i32** | |
**gas_price_limits** | [**Vec<models::RelayerGasPriceLimitResponse>**](RelayerGasPriceLimitResponse.md) | |
**enabled** | **bool** | |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


15 changes: 15 additions & 0 deletions crates/tx-sitter-client/docs/RelayerUpdateRequest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# RelayerUpdateRequest

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**relayer_name** | Option<**String**> | | [optional]
**max_inflight_txs** | Option<**i32**> | | [optional]
**max_queued_txs** | Option<**i32**> | | [optional]
**gas_price_limits** | Option<[**Vec<models::RelayerGasPriceLimitResponse>**](RelayerGasPriceLimitResponse.md)> | | [optional]
**enabled** | Option<**bool**> | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


2 changes: 1 addition & 1 deletion crates/tx-sitter-client/docs/RelayerV1Api.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# \RelayerV1Api

All URIs are relative to *http://localhost:3000*
All URIs are relative to *http://localhost:8000*

Method | HTTP request | Description
------------- | ------------- | -------------
Expand Down
2 changes: 1 addition & 1 deletion crates/tx-sitter-client/docs/ServiceApi.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# \ServiceApi

All URIs are relative to *http://localhost:3000*
All URIs are relative to *http://localhost:8000*

Method | HTTP request | Description
------------- | ------------- | -------------
Expand Down
Loading

0 comments on commit 1835e19

Please sign in to comment.