Skip to content

Commit

Permalink
Automatically generate RPC docs, bump version number for release
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash-L2L committed Jun 24, 2024
1 parent 557117b commit 6c7007f
Show file tree
Hide file tree
Showing 14 changed files with 590 additions and 37 deletions.
71 changes: 67 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ members = [
[workspace.package]
authors = [ "Ash Manning <[email protected]>" ]
edition = "2021"
version = "0.7.7"
version = "0.7.8"

[workspace.dependencies.bip300301]
git = "https://github.com/Ash-L2L/bip300301.git"
Expand Down
1 change: 1 addition & 0 deletions app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ tokio-util = { version = "0.7.10", features = ["rt"] }
tracing = "0.1.40"
tracing-appender = "0.2.3"
tracing-subscriber = "0.3.18"
utoipa = "4.2.3"

[dependencies.libes]
version = "0.9.1"
Expand Down
6 changes: 6 additions & 0 deletions app/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ impl RpcServer for RpcServerImpl {
Ok(utxos)
}

async fn openapi_schema(&self) -> RpcResult<utoipa::openapi::OpenApi> {
let res =
<plain_bitnames_app_rpc_api::RpcDoc as utoipa::OpenApi>::openapi();
Ok(res)
}

async fn reserve_bitname(&self, plain_name: String) -> RpcResult<Txid> {
let mut tx = Transaction::default();
let () = match self.app.wallet.reserve_bitname(&mut tx, &plain_name) {
Expand Down
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ plain_bitnames = { path = "../lib" }
plain_bitnames_app_rpc_api = { path = "../rpc-api" }
serde_json = "1.0.113"
tokio = "1.29.1"
utoipa = "4.2.3"

[lib]
name = "plain_bitnames_app_cli_lib"
Expand Down
8 changes: 8 additions & 0 deletions cli/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ pub enum Command {
},
/// List owned UTXOs
MyUtxos,
/// Show OpenAPI schema
#[command(name = "openapi-schema")]
OpenApiSchema,
/// Reserve a BitName
ReserveBitname { plaintext_name: String },
/// Set the wallet seed from a mnemonic seed phrase
Expand Down Expand Up @@ -144,6 +147,11 @@ impl Cli {
let utxos = rpc_client.my_utxos().await?;
serde_json::to_string_pretty(&utxos)?
}
Command::OpenApiSchema => {
let openapi =
<plain_bitnames_app_rpc_api::RpcDoc as utoipa::OpenApi>::openapi();
openapi.to_pretty_json()?
}
Command::ReserveBitname { plaintext_name } => {
let txid = rpc_client.reserve_bitname(plaintext_name).await?;
format!("{txid}")
Expand Down
1 change: 1 addition & 0 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ tokio = { version = "1.29.1", features = ["rt-multi-thread", "sync"] }
tokio-stream = { version = "0.1.15", features = ["sync"] }
tokio-util = { version = "0.7.10", features = ["rt"] }
tracing = "0.1.40"
utoipa = "4.2.3"
x25519-dalek = { version = "2.0.0", features = ["serde"] }

[target.'cfg(not(target_os = "windows"))'.dependencies.async_zmq]
Expand Down
12 changes: 11 additions & 1 deletion lib/authorization.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use borsh::BorshSerialize;
use rayon::iter::{IntoParallelRefIterator as _, ParallelIterator as _};
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

use crate::types::{
Address, AuthorizedTransaction, Body, GetAddress, Transaction, Verify,
Expand Down Expand Up @@ -49,12 +50,21 @@ where
}

#[derive(
BorshSerialize, Debug, Clone, Deserialize, Eq, PartialEq, Serialize,
BorshSerialize,
Debug,
Clone,
Deserialize,
Eq,
PartialEq,
Serialize,
ToSchema,
)]
pub struct Authorization {
#[borsh(serialize_with = "borsh_serialize_verifying_key")]
#[schema(schema_with = <String as utoipa::PartialSchema>::schema)]
pub verifying_key: VerifyingKey,
#[borsh(serialize_with = "borsh_serialize_signature")]
#[schema(schema_with = <String as utoipa::PartialSchema>::schema)]
pub signature: Signature,
}

Expand Down
18 changes: 18 additions & 0 deletions lib/types/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,21 @@ impl Serialize for Address {
}
}
}

impl utoipa::PartialSchema for Address {
fn schema() -> utoipa::openapi::RefOr<utoipa::openapi::schema::Schema> {
let obj = utoipa::openapi::Object::with_type(
utoipa::openapi::SchemaType::String,
);
utoipa::openapi::RefOr::T(utoipa::openapi::Schema::Object(obj))
}
}

impl utoipa::ToSchema<'static> for Address {
fn schema() -> (
&'static str,
utoipa::openapi::RefOr<utoipa::openapi::schema::Schema>,
) {
("Address", <Address as utoipa::PartialSchema>::schema())
}
}
72 changes: 72 additions & 0 deletions lib/types/hashes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,24 @@ impl FromStr for BlockHash {
}
}

impl utoipa::PartialSchema for BlockHash {
fn schema() -> utoipa::openapi::RefOr<utoipa::openapi::schema::Schema> {
let obj = utoipa::openapi::Object::with_type(
utoipa::openapi::SchemaType::String,
);
utoipa::openapi::RefOr::T(utoipa::openapi::Schema::Object(obj))
}
}

impl utoipa::ToSchema<'static> for BlockHash {
fn schema() -> (
&'static str,
utoipa::openapi::RefOr<utoipa::openapi::schema::Schema>,
) {
("BlockHash", <Self as utoipa::PartialSchema>::schema())
}
}

#[derive(
BorshSerialize,
Clone,
Expand Down Expand Up @@ -120,6 +138,24 @@ impl std::fmt::Debug for MerkleRoot {
}
}

impl utoipa::PartialSchema for MerkleRoot {
fn schema() -> utoipa::openapi::RefOr<utoipa::openapi::schema::Schema> {
let obj = utoipa::openapi::Object::with_type(
utoipa::openapi::SchemaType::String,
);
utoipa::openapi::RefOr::T(utoipa::openapi::Schema::Object(obj))
}
}

impl utoipa::ToSchema<'static> for MerkleRoot {
fn schema() -> (
&'static str,
utoipa::openapi::RefOr<utoipa::openapi::schema::Schema>,
) {
("MerkleRoot", <Self as utoipa::PartialSchema>::schema())
}
}

#[derive(
BorshSerialize,
Clone,
Expand Down Expand Up @@ -180,6 +216,24 @@ impl FromStr for Txid {
}
}

impl utoipa::PartialSchema for Txid {
fn schema() -> utoipa::openapi::RefOr<utoipa::openapi::schema::Schema> {
let obj = utoipa::openapi::Object::with_type(
utoipa::openapi::SchemaType::String,
);
utoipa::openapi::RefOr::T(utoipa::openapi::Schema::Object(obj))
}
}

impl utoipa::ToSchema<'static> for Txid {
fn schema() -> (
&'static str,
utoipa::openapi::RefOr<utoipa::openapi::schema::Schema>,
) {
("Txid", <Self as utoipa::PartialSchema>::schema())
}
}

/// Identifier for a BitName
#[derive(
BorshDeserialize,
Expand Down Expand Up @@ -213,6 +267,24 @@ impl FromHex for BitName {
}
}

impl utoipa::PartialSchema for BitName {
fn schema() -> utoipa::openapi::RefOr<utoipa::openapi::schema::Schema> {
let obj = utoipa::openapi::Object::with_type(
utoipa::openapi::SchemaType::String,
);
utoipa::openapi::RefOr::T(utoipa::openapi::Schema::Object(obj))
}
}

impl utoipa::ToSchema<'static> for BitName {
fn schema() -> (
&'static str,
utoipa::openapi::RefOr<utoipa::openapi::schema::Schema>,
) {
("BitName", <Self as utoipa::PartialSchema>::schema())
}
}

pub fn hash<T>(data: &T) -> Hash
where
T: BorshSerialize,
Expand Down
Loading

0 comments on commit 6c7007f

Please sign in to comment.