ccnext_abi_encoding/common/
mod.rs1use alloy::dyn_abi::DynSolValue;
2use alloy::primitives::{FixedBytes, U256};
3use alloy::signers::Signature;
4use serde::{Deserialize, Serialize};
5
6#[derive(Serialize, Deserialize, Debug)]
7pub struct AbiEncodeResult {
8 pub types: Vec<String>,
9 pub abi: Vec<u8>,
10}
11
12pub fn compute_v(signature: &Signature, chain_id: Option<u64>) -> U256 {
13 let parity = signature.v() as u64; match chain_id {
16 Some(id) => U256::from(35 + 2 * id + parity), None => U256::from(27 + parity), }
19}
20
21pub fn compute_y_parity(signature: &Signature) -> u8 {
22 if signature.v() {
23 1
24 } else {
25 0
26 }
27}
28
29pub fn encode_blob_hashes(blob_hashes: Vec<FixedBytes<32>>) -> DynSolValue {
30 let mut result = Vec::new();
31 for hash in blob_hashes {
32 result.push(DynSolValue::FixedBytes(hash, 32));
33 }
34 DynSolValue::Array(result)
35}