macro_rules! impl_pk_and_param_getters {
($param_type: ident, $param_variant: ident, $pk_type: ident, $pk_variant: ident) => {
pub fn get_params<'a>(
&'a self,
setup_params: &'a [SetupParams<E>],
st_idx: usize,
) -> Result<&'a $param_type<E>, ProofSystemError> {
extract_param!(
setup_params,
&self.params,
self.params_ref,
$param_variant,
IncompatibleAccumulatorSetupParamAtIndex,
st_idx
)
}
pub fn get_public_key<'a>(
&'a self,
setup_params: &'a [SetupParams<E>],
st_idx: usize,
) -> Result<&'a $pk_type<E>, ProofSystemError> {
extract_param!(
setup_params,
&self.public_key,
self.public_key_ref,
$pk_variant,
IncompatibleAccumulatorSetupParamAtIndex,
st_idx
)
}
};
}
macro_rules! impl_getters {
( $param_type: ident, $param_variant: ident, $pk_type: ident, $pk_variant: ident, $prk_type:ident, $prk_variant:ident) => {
impl_pk_and_param_getters!($param_type, $param_variant, $pk_type, $pk_variant);
pub fn get_proving_key<'a>(
&'a self,
setup_params: &'a [SetupParams<E>],
st_idx: usize,
) -> Result<&'a $prk_type<E::G1Affine>, ProofSystemError> {
extract_param!(
setup_params,
&self.proving_key,
self.proving_key_ref,
$prk_variant,
IncompatibleAccumulatorSetupParamAtIndex,
st_idx
)
}
};
}
macro_rules! impl_struct_and_funcs {
($(#[$doc:meta])*
$name:ident, $param_type: ident, $param_variant: ident, $pk_type: ident, $pk_variant: ident, $statement_variant:ident, $prk_type:ident, $prk_variant:ident) => {
#[serde_as]
#[derive(
Clone,
Debug,
PartialEq,
Eq,
CanonicalSerialize,
CanonicalDeserialize,
Serialize,
Deserialize,
)]
#[serde(bound = "")]
pub struct $name<E: Pairing> {
#[serde_as(as = "ArkObjectBytes")]
pub accumulator_value: E::G1Affine,
pub params: Option<$param_type<E>>,
pub public_key: Option<$pk_type<E>>,
pub proving_key: Option<$prk_type<E::G1Affine>>,
pub params_ref: Option<usize>,
pub public_key_ref: Option<usize>,
pub proving_key_ref: Option<usize>,
}
impl<E: Pairing> $name<E> {
pub fn new_statement_from_params(
params: $param_type<E>,
public_key: $pk_type<E>,
proving_key: $prk_type<E::G1Affine>,
accumulator_value: E::G1Affine,
) -> Statement<E> {
Statement::$statement_variant(Self {
accumulator_value,
params: Some(params),
public_key: Some(public_key),
proving_key: Some(proving_key),
params_ref: None,
public_key_ref: None,
proving_key_ref: None,
})
}
pub fn new_statement_from_params_ref(
params_ref: usize,
public_key_ref: usize,
proving_key_ref: usize,
accumulator_value: E::G1Affine,
) -> Statement<E> {
Statement::$statement_variant(Self {
accumulator_value,
params: None,
public_key: None,
proving_key: None,
params_ref: Some(params_ref),
public_key_ref: Some(public_key_ref),
proving_key_ref: Some(proving_key_ref),
})
}
impl_getters!(
$param_type,
$param_variant,
$pk_type,
$pk_variant,
$prk_type,
$prk_variant
);
}
};
}