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

Support casper 2 rc4 #4

Merged
merged 3 commits into from
Sep 27, 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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ crate-type = ["cdylib"]

[dependencies]
base16 = { version = "0.2.1", default-features = false, features = ["alloc"] }
casper-litmus = { git = "https://github.com/cspr-rad/litmus" }
casper-litmus = { version = "0.2", git = "https://github.com/cspr-rad/litmus" }
casper-types = "4.0.1"
serde = { version = "1.0.195", default-features = false, features = ["derive"] }
serde-wasm-bindgen = "0.6.5"
Expand Down
23 changes: 10 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ extern crate alloc;
use alloc::collections::BTreeMap;

use casper_litmus::{
block::Block, json_compatibility::JsonBlock, kernel::EraInfo, merkle_proof::TrieMerkleProof,
casper_types::{self, JsonBlockWithSignatures, PublicKey, U512},
kernel::EraInfo,
merkle_proof::TrieMerkleProof,
};
use casper_types::{PublicKey, U512};
use serde_json::json;
use wasm_bindgen::prelude::*;

Expand All @@ -30,25 +31,21 @@ impl BlockValidator {

#[wasm_bindgen]
pub fn validate(&self, json_block_js_value: JsValue) -> Result<(), String> {
let json_block: JsonBlock = serde_wasm_bindgen::from_value(json_block_js_value)
.map_err(|err| format!("{err:?}"))?;
let block = Block::try_from(json_block).map_err(|err| format!("{err:?}"))?;
let json_block: JsonBlockWithSignatures =
serde_wasm_bindgen::from_value(json_block_js_value)
.map_err(|err| format!("{err:?}"))?;
self.era_info
.validate(block.block_header_with_signatures())
.validate(json_block)
.map_err(|err| format!("{err:?}"))
}
}

#[wasm_bindgen]
pub fn block_hash(json_block_js_value: JsValue) -> Result<String, String> {
let json_block: JsonBlock =
let json_block: JsonBlockWithSignatures =
serde_wasm_bindgen::from_value(json_block_js_value).map_err(|err| format!("{err:?}"))?;
let block = Block::try_from(json_block).map_err(|err| format!("{err:?}"))?;
let block_hash = block
.block_header_with_signatures()
.block_header()
.block_hash();
Ok(block_hash.to_hex())
let block_hash = json_block.block.hash();
Ok(base16::encode_lower(&block_hash))
}

#[wasm_bindgen]
Expand Down