Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update key for pallet name. #9

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .env.example
100644 → 100755
Empty file.
Empty file modified .github/workflows/release.yml
100644 → 100755
Empty file.
Empty file modified .github/workflows/rust.yml
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
29 changes: 20 additions & 9 deletions Cargo.lock
100644 → 100755

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ tracing-subscriber = { version = "0.3.18", features = ["env-filter", "json"] }
sp-io = "32.0.0"
sp-core = "30.0.0"
chrono = "0.4.34"
avail-core = { version = "0.5", git = "https://github.com/availproject/avail-core", branch = "main" }

avail-core = { git = "https://github.com/availproject/avail-core", branch = "main" }


[target.'cfg(not(target_env = "msvc"))'.dependencies]
Expand Down
Empty file modified Dockerfile
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
50 changes: 29 additions & 21 deletions src/main.rs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloy_primitives::{hex, B256, U256};
use avail_core::data_proof_v2::Message;
use avail_core::data_proof::AddressedMessage;
use axum::{
extract::{Json, Path, Query, State},
http::StatusCode,
Expand Down Expand Up @@ -49,25 +49,31 @@ struct IndexStruct {
index: u32,
}

#[derive(Deserialize)]
#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")]
struct KateQueryDataProofV2Response {
struct KateQueryDataProofResponse {
data_proof: DataProof,
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
message: Option<Message>,
message: Option<AddressedMessage>,
}

#[derive(Deserialize)]
#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")]
struct DataProof {
data_root: B256,
blob_root: B256,
bridge_root: B256,
roots: Roots,
proof: Vec<B256>,
leaf_index: u32,
leaf: B256,
}

#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")]
struct Roots {
data_root: B256,
blob_root: B256,
bridge_root: B256,
}

#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct AccountStorageProofResponse {
Expand Down Expand Up @@ -133,7 +139,7 @@ struct AggregatedResponse {
bridge_root: B256,
data_root_commitment: B256,
block_hash: B256,
message: Option<Message>,
message: Option<AddressedMessage>,
}

#[derive(Serialize)]
Expand Down Expand Up @@ -179,7 +185,7 @@ async fn get_eth_proof(
cloned_state
.avail_client
.request(
"kate_queryDataProofV2",
"kate_queryDataProof",
rpc_params![index_struct.index, &block_hash],
)
.await
Expand All @@ -201,11 +207,11 @@ async fn get_eth_proof(
}
});
let (data_proof, succinct_response) = join!(data_proof_response_fut, succinct_response_fut);
let data_proof_res: KateQueryDataProofV2Response = match data_proof {
let data_proof_res: KateQueryDataProofResponse = match data_proof {
Ok(resp) => match resp {
Ok(data) => data,
Err(err) => {
tracing::error!("❌ Cannot query data proof {:?}", err);
tracing::error!("❌ Cannot get kate data proof response: {:?}", err);
return (
StatusCode::BAD_REQUEST,
[("Cache-Control", "max-age=300, must-revalidate")],
Expand Down Expand Up @@ -276,9 +282,9 @@ async fn get_eth_proof(
data_root_index: succinct_data.index,
leaf: data_proof_res.data_proof.leaf,
leaf_index: data_proof_res.data_proof.leaf_index,
data_root: data_proof_res.data_proof.data_root,
blob_root: data_proof_res.data_proof.blob_root,
bridge_root: data_proof_res.data_proof.bridge_root,
data_root: data_proof_res.data_proof.roots.data_root,
blob_root: data_proof_res.data_proof.roots.blob_root,
bridge_root: data_proof_res.data_proof.roots.bridge_root,
data_root_commitment: succinct_data.data_commitment,
block_hash,
message: data_proof_res.message
Expand Down Expand Up @@ -322,7 +328,7 @@ async fn get_avl_proof(
})),
),
Err(err) => {
tracing::error!("❌ {:?}", err);
tracing::error!("❌ Cannot get account and storage proofs: {:?}", err);
(
StatusCode::INTERNAL_SERVER_ERROR,
[("Cache-Control", "max-age=300, must-revalidate")],
Expand Down Expand Up @@ -359,7 +365,10 @@ async fn get_beacon_slot(
})),
)
} else {
tracing::error!("❌ {:?}", rsp_data.status);
tracing::error!(
"❌ Beacon API returned unsuccessfully: {:?}",
rsp_data.status
);
(
StatusCode::INTERNAL_SERVER_ERROR,
[("Cache-Control", "max-age=300, must-revalidate")],
Expand All @@ -368,7 +377,7 @@ async fn get_beacon_slot(
}
}
Err(err) => {
tracing::error!("❌ {:?}", err);
tracing::error!("❌ Cannot get beacon API response data: {:?}", err);
(
StatusCode::INTERNAL_SERVER_ERROR,
[("Cache-Control", "max-age=300, must-revalidate")],
Expand All @@ -378,7 +387,7 @@ async fn get_beacon_slot(
}
}
Err(err) => {
tracing::error!("❌ {:?}", err);
tracing::error!("❌ Cannot get beacon API data: {:?}", err);
(
StatusCode::INTERNAL_SERVER_ERROR,
[("Cache-Control", "max-age=300, must-revalidate")],
Expand All @@ -391,7 +400,7 @@ async fn get_beacon_slot(
/// get_eth_head returns Ethereum head with the latest slot/block that is stored and a time.
#[inline(always)]
async fn get_eth_head(State(state): State<Arc<AppState>>) -> impl IntoResponse {
let pallet = "Succinct";
let pallet = "Vector";
let head = "Head";
let timestamp = "Timestamps";

Expand All @@ -400,7 +409,6 @@ async fn get_eth_head(State(state): State<Arc<AppState>>) -> impl IntoResponse {
hex::encode(twox_128(pallet.as_bytes())),
hex::encode(twox_128(head.as_bytes()))
);

let head_response: Result<String, Error> = state
.avail_client
.request("state_getStorage", rpc_params![head_key])
Expand Down
Loading