|
1 | 1 | use std::sync::Arc; |
2 | | -use crate::model::RawTx; |
| 2 | +use crate::{ |
| 3 | + error::{ApiError, Error, NotFoundKind}, |
| 4 | + model::RawTx, |
| 5 | + repository::RepositoryOps, |
| 6 | + storage::SortOrder, |
| 7 | + Result, |
| 8 | +}; |
| 9 | +use super::{ |
| 10 | + query::PaginationQuery, |
| 11 | + response::{ApiPagedResponse, Response}, |
| 12 | + AppContext, |
| 13 | +}; |
3 | 14 | use axum::{ |
4 | | - routing::{get, post}, |
5 | | - Router, |
| 15 | + extract::{Path, Query}, |
| 16 | + routing::{get,post}, |
| 17 | + Extension, Router, |
6 | 18 | }; |
7 | 19 | use defichain_rpc::{Client, RpcApi}; |
8 | | -use super::path::Path; |
9 | 20 |
|
10 | | -async fn send_rawtx() -> String { |
11 | | - "Sending raw transaction".to_string() |
| 21 | +use ain_macros::ocean_endpoint; |
| 22 | + |
| 23 | +#[ocean_endpoint] |
| 24 | +async fn send_rawtx( |
| 25 | + Path(tx): Path<RawTx>, |
| 26 | + Extension(ctx): Extension<Arc<AppContext>>, |
| 27 | +) -> Result<Response<String>> { |
| 28 | + |
| 29 | + Ok(Response::new("Sending raw transaction".to_string())) |
12 | 30 | } |
13 | 31 |
|
14 | | -async fn test_rawtx() -> String { |
15 | | - "Testing raw transaction".to_string() |
| 32 | +#[ocean_endpoint] |
| 33 | +async fn test_rawtx( |
| 34 | + Path(tx): Path<RawTx>, |
| 35 | + Extension(ctx): Extension<Arc<AppContext>>, |
| 36 | +) -> Result<Response<String>> { |
| 37 | + |
| 38 | +Ok(Response::new("Testing raw transaction".to_string())) |
| 39 | +} |
| 40 | +#[ocean_endpoint] |
| 41 | +async fn get_rawtx( |
| 42 | + Path(txid): Path<String>, |
| 43 | + Extension(ctx): Extension<Arc<AppContext>>, |
| 44 | +) -> Result<Response<String>> { |
| 45 | + format!("Details of raw transaction with txid {}", txid); |
| 46 | + Ok(Response::new("Testing raw transaction".to_string())) |
16 | 47 | } |
17 | 48 |
|
18 | | -async fn get_rawtx(Path(txid): Path<String>) -> String { |
19 | | - format!("Details of raw transaction with txid {}", txid) |
| 49 | +async fn validate(hex:String) { |
| 50 | + if !hex.starts_with("040000000001") { |
| 51 | + return |
| 52 | + } |
| 53 | + |
20 | 54 | } |
21 | 55 |
|
22 | 56 | pub fn router(ctx: Arc<AppContext>) -> Router { |
23 | 57 | Router::new() |
24 | 58 | .route("/send", post(send_rawtx)) |
25 | 59 | .route("/test", get(test_rawtx)) |
26 | 60 | .route("/:txid", get(get_rawtx)) |
| 61 | + .layer(Extension(ctx)) |
27 | 62 | } |
0 commit comments