-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathtransaction.rs
86 lines (77 loc) · 2.26 KB
/
transaction.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use {
super::super::HANDLER_TASK_METRICS,
crate::{error::RpcError, state::AppState},
axum::{
extract::State,
response::{IntoResponse, Response},
Json,
},
serde::{Deserialize, Serialize},
std::sync::Arc,
tap::TapFallible,
tracing::log::error,
wc::future::FutureExt,
};
#[derive(Debug, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ConvertTransactionQueryParams {
pub project_id: String,
pub amount: String,
pub from: String,
pub to: String,
pub user_address: String,
pub eip155: Option<ConvertTransactionQueryEip155>,
pub disable_estimate: Option<bool>,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ConvertTransactionQueryEip155 {
pub slippage: usize,
pub permit: Option<String>,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ConvertTransactionResponseBody {
pub tx: ConvertTx,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ConvertTx {
pub from: String,
pub to: String,
pub data: String,
pub amount: String,
pub eip155: Option<ConvertTxEip155>,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ConvertTxEip155 {
pub gas: String,
pub gas_price: String,
}
pub async fn handler(
state: State<Arc<AppState>>,
Json(request_payload): Json<ConvertTransactionQueryParams>,
) -> Result<Response, RpcError> {
handler_internal(state, request_payload)
.with_metrics(HANDLER_TASK_METRICS.with_name("convert_build_transaction"))
.await
}
#[tracing::instrument(skip_all, level = "debug")]
async fn handler_internal(
state: State<Arc<AppState>>,
request_payload: ConvertTransactionQueryParams,
) -> Result<Response, RpcError> {
state
.validate_project_access_and_quota(&request_payload.project_id)
.await?;
let response = state
.providers
.conversion_provider
.build_convert_tx(request_payload, state.metrics.clone())
.await
.tap_err(|e| {
error!("Failed to call build conversion transaction with {}", e);
})?;
Ok(Json(response).into_response())
}