Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
piohei committed Sep 6, 2024
1 parent e67fa99 commit f0768f7
Show file tree
Hide file tree
Showing 53 changed files with 2,959 additions and 70 deletions.
494 changes: 438 additions & 56 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ aws-types = "1.2.1"

# Internal
postgres-docker-utils = { path = "crates/postgres-docker-utils" }
tx-sitter-client = { path = "crates/tx-sitter-client" }

# Company
telemetry-batteries = { git = "https://github.com/worldcoin/telemetry-batteries", rev = "e0891328b29d9f85df037633feccca2f74a291a6" }
Expand Down
134 changes: 134 additions & 0 deletions client-template/reqwest/configuration.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{{>partial_header}}

{{#withAWSV4Signature}}
use std::time::SystemTime;
use aws_sigv4::http_request::{sign, SigningSettings, SigningParams, SignableRequest};
use http;
use secrecy::{SecretString, ExposeSecret};
{{/withAWSV4Signature}}

#[derive(Debug, Clone)]
pub struct Configuration {
pub base_path: String,
pub user_agent: Option<String>,
pub client: {{#supportMiddleware}}reqwest_middleware::ClientWithMiddleware{{/supportMiddleware}}{{^supportMiddleware}}reqwest{{^supportAsync}}::blocking{{/supportAsync}}::Client{{/supportMiddleware}},
pub basic_auth: Option<BasicAuth>,
pub oauth_access_token: Option<String>,
pub bearer_access_token: Option<String>,
pub api_key: Option<ApiKey>,
{{#withAWSV4Signature}}
pub aws_v4_key: Option<AWSv4Key>,
{{/withAWSV4Signature}}
// TODO: take an oauth2 token source, similar to the go one
}

pub type BasicAuth = (String, Option<String>);

#[derive(Debug, Clone)]
pub struct ApiKey {
pub prefix: Option<String>,
pub key: String,
}

{{#withAWSV4Signature}}
#[derive(Debug, Clone)]
pub struct AWSv4Key {
pub access_key: String,
pub secret_key: SecretString,
pub region: String,
pub service: String,
}

impl AWSv4Key {
pub fn sign(&self, uri: &str, method: &str, body: &str) -> Result<Vec::<(String, String)>, aws_sigv4::http_request::Error> {
let request = http::Request::builder()
.uri(uri)
.method(method)
.body(body).unwrap();
let signing_settings = SigningSettings::default();
let signing_params = SigningParams::builder()
.access_key(self.access_key.as_str())
.secret_key(self.secret_key.expose_secret().as_str())
.region(self.region.as_str())
.service_name(self.service.as_str())
.time(SystemTime::now())
.settings(signing_settings)
.build()
.unwrap();
let signable_request = SignableRequest::from(&request);
let (mut signing_instructions, _signature) = sign(signable_request, &signing_params)?.into_parts();
let mut additional_headers = Vec::<(String, String)>::new();
if let Some(new_headers) = signing_instructions.take_headers() {
for (name, value) in new_headers.into_iter() {
additional_headers.push((name.expect("header should have name").to_string(),
value.to_str().expect("header value should be a string").to_string()));
}
}
Ok(additional_headers)
}
}
{{/withAWSV4Signature}}

impl Default for Configuration {
fn default() -> Self {
Configuration {
base_path: "{{{basePath}}}".to_owned(),
user_agent: {{#httpUserAgent}}Some("{{{.}}}".to_owned()){{/httpUserAgent}}{{^httpUserAgent}}Some("OpenAPI-Generator/{{{version}}}/rust".to_owned()){{/httpUserAgent}},
client: {{#supportMiddleware}}reqwest_middleware::ClientBuilder::new(reqwest{{^supportAsync}}::blocking{{/supportAsync}}::Client::new()).build(){{/supportMiddleware}}{{^supportMiddleware}}reqwest{{^supportAsync}}::blocking{{/supportAsync}}::Client::new(){{/supportMiddleware}},
basic_auth: None,
oauth_access_token: None,
bearer_access_token: None,
api_key: None,
{{#withAWSV4Signature}} aws_v4_key: None,{{/withAWSV4Signature}}
}
}
}

pub struct ConfigurationBuilder {
pub base_path: Option<String>,
pub user_agent: Option<String>,
pub basic_auth: Option<BasicAuth>,
}

impl ConfigurationBuilder {
pub fn new() -> ConfigurationBuilder {
ConfigurationBuilder {
base_path: None,
user_agent: None,
basic_auth: None,
}
}

pub fn base_path(mut self, base_path: String) -> Self {
self.base_path = Some(base_path);
self
}

pub fn user_agent(mut self, user_agent: String) -> Self {
self.user_agent = Some(user_agent);
self
}

pub fn basic_auth(mut self, user: String, pass: Option<String>) -> Self {
self.basic_auth = Some((user, pass));
self
}

pub fn build(self) -> Configuration {
let mut conf: Configuration = Default::default();
if let Some(base_path) = self.base_path {
conf.base_path = base_path;
}

if let Some(user_agent) = self.user_agent {
conf.user_agent = Some(user_agent);
}

if let Some(basic_auth) = self.basic_auth {
conf.basic_auth = Some(basic_auth);
}

conf
}
}
3 changes: 3 additions & 0 deletions crates/tx-sitter-client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/target/
**/*.rs.bk
Cargo.lock
23 changes: 23 additions & 0 deletions crates/tx-sitter-client/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
45 changes: 45 additions & 0 deletions crates/tx-sitter-client/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.gitignore
.travis.yml
Cargo.toml
README.md
docs/AdminV1Api.md
docs/CreateApiKeyResponse.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/RelayerV1Api.md
docs/RpcRequest.md
docs/SendTxRequest.md
docs/SendTxResponse.md
docs/ServiceApi.md
docs/TransactionPriority.md
docs/TxStatus.md
git_push.sh
src/apis/admin_v1_api.rs
src/apis/configuration.rs
src/apis/mod.rs
src/apis/relayer_v1_api.rs
src/apis/service_api.rs
src/lib.rs
src/models/create_api_key_response.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/rpc_request.rs
src/models/send_tx_request.rs
src/models/send_tx_response.rs
src/models/transaction_priority.rs
src/models/tx_status.rs
1 change: 1 addition & 0 deletions crates/tx-sitter-client/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.9.0-SNAPSHOT
1 change: 1 addition & 0 deletions crates/tx-sitter-client/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: rust
18 changes: 18 additions & 0 deletions crates/tx-sitter-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
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. "
# Override this license by providing a License Object in the OpenAPI.
license = "Unlicense"
edition = "2021"

[dependencies]
serde = { version = "^1.0", features = ["derive"] }
serde_with = { version = "^3.8", default-features = false, features = ["base64", "std", "macros"] }
serde_json = "^1.0"
serde_repr = "^0.1"
url = "^2.5"
uuid = { version = "^1.8", features = ["serde", "v4"] }
reqwest = { version = "^0.12", features = ["json", "multipart"] }
reqwest-middleware = { version = "^0.3", features = ["json", "multipart"] }
94 changes: 94 additions & 0 deletions crates/tx-sitter-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Rust API client for tx-sitter-client

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.



## Overview

This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://openapis.org) from a remote server, you can easily generate an API client.

- API version: 0.1.0
- Package version: 0.1.0
- Generator version: 7.9.0-SNAPSHOT
- Build package: `org.openapitools.codegen.languages.RustClientCodegen`

## Installation

Put the package under your project folder in a directory named `tx-sitter-client` and add the following to `Cargo.toml` under `[dependencies]`:

```
tx-sitter-client = { path = "./tx-sitter-client" }
```

## Documentation for API Endpoints

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

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*AdminV1Api* | [**create_network**](docs/AdminV1Api.md#create_network) | **POST** /1/admin/network/{chain_id} | Create Network
*AdminV1Api* | [**create_relayer**](docs/AdminV1Api.md#create_relayer) | **POST** /1/admin/relayer | Create Relayer
*AdminV1Api* | [**get_networks**](docs/AdminV1Api.md#get_networks) | **GET** /1/admin/networks | Get Networks
*AdminV1Api* | [**get_relayer**](docs/AdminV1Api.md#get_relayer) | **GET** /1/admin/relayer/{relayer_id} | Get Relayer
*AdminV1Api* | [**get_relayers**](docs/AdminV1Api.md#get_relayers) | **GET** /1/admin/relayers | Get Relayers
*AdminV1Api* | [**relayer_create_api_key**](docs/AdminV1Api.md#relayer_create_api_key) | **POST** /1/admin/relayer/{relayer_id}/key | Create Relayer API Key
*AdminV1Api* | [**reset_relayer**](docs/AdminV1Api.md#reset_relayer) | **POST** /1/admin/relayer/{relayer_id}/reset | Reset Relayer transactions
*AdminV1Api* | [**update_relayer**](docs/AdminV1Api.md#update_relayer) | **POST** /1/admin/relayer/{relayer_id} | Update Relayer
*RelayerV1Api* | [**call_rpc**](docs/RelayerV1Api.md#call_rpc) | **POST** /1/api/{api_token}/rpc | Relayer RPC
*RelayerV1Api* | [**create_transaction**](docs/RelayerV1Api.md#create_transaction) | **POST** /1/api/{api_token}/tx | Send Transaction
*RelayerV1Api* | [**get_transaction**](docs/RelayerV1Api.md#get_transaction) | **GET** /1/api/{api_token}/tx/{tx_id} | Get Transaction
*RelayerV1Api* | [**get_transactions**](docs/RelayerV1Api.md#get_transactions) | **GET** /1/api/{api_token}/txs | Get Transactions
*ServiceApi* | [**health**](docs/ServiceApi.md#health) | **GET** /health | Health


## Documentation For Models

- [CreateApiKeyResponse](docs/CreateApiKeyResponse.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)
- [RpcRequest](docs/RpcRequest.md)
- [SendTxRequest](docs/SendTxRequest.md)
- [SendTxResponse](docs/SendTxResponse.md)
- [TransactionPriority](docs/TransactionPriority.md)
- [TxStatus](docs/TxStatus.md)


To get access to the crate's generated documentation, use:

```
cargo doc --open
```

## Author



Loading

0 comments on commit f0768f7

Please sign in to comment.