-
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.
- Loading branch information
1 parent
838b64f
commit 196716e
Showing
8 changed files
with
87 additions
and
150 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use crate::model::AppState; | ||
|
||
use actix_web::{web::Data, HttpResponse}; | ||
use anyhow::Context; | ||
use k256::elliptic_curve::generic_array::sequence::Lengthen; | ||
use serde_json::json; | ||
use tiny_keccak::{Hasher, Keccak}; | ||
|
||
pub async fn bill_data(appstate: Data<AppState>) -> HttpResponse { | ||
let mut costs_gaurd = appstate.execution_costs.lock().unwrap(); | ||
let costs_map = costs_gaurd.clone(); | ||
|
||
let mut hash = [0u8; 32]; | ||
let mut hasher_gaurd = appstate.billing_hasher.lock().unwrap(); | ||
hasher_gaurd.clone().finalize(&mut hash); | ||
let sign = appstate | ||
.signer | ||
.sign_prehash_recoverable(&hash) | ||
.context("Failed to sign requests data"); | ||
if sign.is_err() { | ||
return HttpResponse::InternalServerError().body(format!("{:?}", sign.unwrap_err())); | ||
} | ||
let (rs, v) = sign.unwrap(); | ||
let signature = hex::encode(rs.to_bytes().append(27 + v.to_byte()).as_slice()); | ||
|
||
costs_gaurd.clear(); | ||
hasher_gaurd.clone_from(&Keccak::v256()); | ||
|
||
HttpResponse::Ok().json(json!({ | ||
"execution_costs": costs_map, | ||
"signature": signature, | ||
})) | ||
} |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
pub mod billing_job; | ||
pub mod bill_handler; | ||
pub mod cgroups; | ||
pub mod handler; | ||
pub mod model; | ||
|
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
Oops, something went wrong.