-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kairos-server: add deposit mock handler
- Loading branch information
Showing
5 changed files
with
118 additions
and
97 deletions.
There are no files selected for viewing
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,51 @@ | ||
use anyhow::{anyhow, Context}; | ||
use axum::{extract::State, http::StatusCode, Json}; | ||
use axum_extra::routing::TypedPath; | ||
use tracing::*; | ||
|
||
use kairos_tx::asn::{SigningPayload, TransactionBody}; | ||
|
||
use crate::{ | ||
routes::PayloadBody, | ||
state::{ | ||
transactions::{Signed, Transaction}, | ||
ServerState, | ||
}, | ||
AppErr, | ||
}; | ||
|
||
#[derive(TypedPath, Debug, Clone, Copy)] | ||
#[typed_path("/api/v1/deposit-mock")] | ||
pub struct MockDepositPath; | ||
|
||
#[instrument(level = "trace", skip(state), ret)] | ||
pub async fn deposit_mock_handler( | ||
_: MockDepositPath, | ||
state: State<ServerState>, | ||
Json(body): Json<PayloadBody>, | ||
) -> Result<(), AppErr> { | ||
tracing::info!("parsing transaction data"); | ||
let signing_payload: SigningPayload = | ||
body.payload.as_slice().try_into().context("payload err")?; | ||
let deposit = match signing_payload.body { | ||
TransactionBody::Deposit(deposit) => deposit.try_into().context("decoding deposit")?, | ||
_ => { | ||
return Err(AppErr::set_status( | ||
anyhow!("invalid transaction type"), | ||
StatusCode::BAD_REQUEST, | ||
)) | ||
} | ||
}; | ||
|
||
let public_key = body.public_key; | ||
let nonce = signing_payload.nonce.try_into().context("decoding nonce")?; | ||
|
||
state | ||
.batch_state_manager | ||
.enqueue_transaction(Signed { | ||
public_key, | ||
nonce, | ||
transaction: Transaction::Deposit(deposit), | ||
}) | ||
.await | ||
} |
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