-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dummy endpoint to sign transaction
- Loading branch information
1 parent
4c5de94
commit 9894ea5
Showing
6 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use axum::Json; | ||
use firefly_server::error::{ApiError, ApiResult}; | ||
use schemars::JsonSchema; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Deserialize, JsonSchema)] | ||
pub struct SignTransactionRequest { | ||
/// The address of the key to sign the transaction with. | ||
address: String, | ||
/// The raw CBOR-encoded transaction to sign. | ||
transaction: String, | ||
} | ||
|
||
#[derive(Serialize, JsonSchema)] | ||
pub struct SignTransactionResponse { | ||
/// The CBOR-encoded signed transaction. | ||
transaction: String, | ||
} | ||
|
||
pub async fn sign_transaction( | ||
Json(req): Json<SignTransactionRequest>, | ||
) -> ApiResult<Json<SignTransactionResponse>> { | ||
if req.address.is_empty() { | ||
return Err(ApiError::not_found("No address provided")); | ||
} | ||
Ok(Json(SignTransactionResponse { | ||
transaction: req.transaction, | ||
})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use aide::OperationOutput; | ||
use axum::{ | ||
http::StatusCode, | ||
response::{IntoResponse, Response}, | ||
}; | ||
|
||
pub struct ApiError { | ||
status: StatusCode, | ||
message: String, | ||
} | ||
|
||
impl ApiError { | ||
pub fn new(status: impl Into<StatusCode>, message: impl Into<String>) -> Self { | ||
Self { | ||
status: status.into(), | ||
message: message.into(), | ||
} | ||
} | ||
pub fn not_found(message: impl Into<String>) -> Self { | ||
Self::new(StatusCode::NOT_FOUND, message) | ||
} | ||
} | ||
|
||
impl IntoResponse for ApiError { | ||
fn into_response(self) -> Response { | ||
(self.status, self.message).into_response() | ||
} | ||
} | ||
|
||
impl<E> From<E> for ApiError | ||
where | ||
E: Into<anyhow::Error>, | ||
{ | ||
fn from(value: E) -> Self { | ||
Self { | ||
status: StatusCode::INTERNAL_SERVER_ERROR, | ||
message: value.into().to_string(), | ||
} | ||
} | ||
} | ||
|
||
impl OperationOutput for ApiError { | ||
type Inner = Self; | ||
} | ||
|
||
pub type ApiResult<T, E = ApiError> = std::result::Result<T, E>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod config; | ||
pub mod error; | ||
pub mod server; |