ccnext_abi_encoding/common/
mod.rs

1use alloy::dyn_abi::DynSolValue;
2use alloy::primitives::{FixedBytes, U256};
3use alloy::signers::Signature;
4use serde::{Deserialize, Serialize};
5
6
7#[derive(Serialize, Deserialize, Debug)]
8pub struct AbiEncodeResult
9{
10    pub types: Vec<String>,
11    pub abi: Vec<u8>
12}
13
14pub fn compute_v(signature: &Signature, chain_id: Option<u64>) -> U256 {
15    let parity = signature.v() as u64; // Get y_parity (boolean as 0 or 1)
16
17    match chain_id {
18        Some(id) => U256::from(35 + 2 * id + parity), // Corrected EIP-155 format
19        None => U256::from(27 + parity), // Legacy format
20    }
21}
22
23pub fn compute_y_parity(signature: &Signature) -> u8 {
24    if signature.v() { 1 } else { 0 }
25}
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}