Skip to content

Commit

Permalink
Make group_by_zkapp_command_rev generic, to use it in tx pool
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiencs committed Mar 9, 2024
1 parent e6abf86 commit c9318ef
Showing 1 changed file with 37 additions and 20 deletions.
57 changes: 37 additions & 20 deletions ledger/src/proofs/zkapp.rs
Expand Up @@ -87,7 +87,7 @@ pub struct ZkappParams<'a> {
pub proved_path: Option<&'a str>,
}

mod group {
pub mod group {
use super::*;
use crate::scan_state::transaction_logic::zkapp_command::{AccountUpdate, Control};

Expand Down Expand Up @@ -119,26 +119,31 @@ mod group {
}

#[derive(Debug)]
pub struct State {
pub global: GlobalState<SparseLedger>,
pub local: LocalStateEnv<SparseLedger>,
pub struct State<GlobalState, LocalState> {
pub global: GlobalState,
pub local: LocalState,
}

#[derive(Debug)]
pub struct ZkappCommandIntermediateState {
pub struct ZkappCommandIntermediateState<GlobalState, LocalState, ConnectingLedgerHash> {
pub kind: Kind,
pub spec: SegmentBasic,
pub state_before: State,
pub state_after: State,
pub connecting_ledger: Fp,
pub state_before: State<GlobalState, LocalState>,
pub state_after: State<GlobalState, LocalState>,
pub connecting_ledger: ConnectingLedgerHash,
}

fn intermediate_state(
fn intermediate_state<GlobalState, LocalState, ConnectingLedgerHash>(
kind: Kind,
spec: SegmentBasic,
before: &(GlobalState<SparseLedger>, LocalStateEnv<SparseLedger>, Fp),
after: &(GlobalState<SparseLedger>, LocalStateEnv<SparseLedger>, Fp),
) -> ZkappCommandIntermediateState {
before: &(GlobalState, LocalState, ConnectingLedgerHash),
after: &(GlobalState, LocalState, ConnectingLedgerHash),
) -> ZkappCommandIntermediateState<GlobalState, LocalState, ConnectingLedgerHash>
where
GlobalState: Clone,
LocalState: Clone,
ConnectingLedgerHash: Clone,
{
let (global_before, local_before, _) = before;
let (global_after, local_after, connecting_ledger) = after;
ZkappCommandIntermediateState {
Expand All @@ -157,17 +162,24 @@ mod group {
}

// Note: Unlike OCaml, the returned value (the list) is not reversed, but we keep the same method name
pub fn group_by_zkapp_command_rev(
pub fn group_by_zkapp_command_rev<GlobalState, LocalState, ConnectingLedgerHash>(
zkapp_command: Vec<&ZkAppCommand>,
stmtss: Vec<Vec<(GlobalState<SparseLedger>, LocalStateEnv<SparseLedger>, Fp)>>,
) -> Vec<ZkappCommandIntermediateState> {
stmtss: Vec<Vec<(GlobalState, LocalState, ConnectingLedgerHash)>>,
) -> Vec<ZkappCommandIntermediateState<GlobalState, LocalState, ConnectingLedgerHash>>
where
GlobalState: Clone,
LocalState: Clone,
ConnectingLedgerHash: Clone,
{
let mut zkapp_account_updatess = zkapp_command
.iter()
.map(|zkapp_command| zkapp_command.all_account_updates_list())
.collect::<Vec<_>>();
zkapp_account_updatess.insert(0, vec![]);

let mut acc = Vec::<ZkappCommandIntermediateState>::with_capacity(32);
let mut acc = Vec::<
ZkappCommandIntermediateState<GlobalState, LocalState, ConnectingLedgerHash>,
>::with_capacity(32);

// Convert to slices, to allow matching below
let zkapp_account_updatess = zkapp_account_updatess
Expand All @@ -177,11 +189,16 @@ mod group {
let stmtss = stmtss.iter().map(|v| v.as_slice()).collect::<Vec<_>>();

#[rustfmt::skip]
fn group_by_zkapp_command_rev_impl(
fn group_by_zkapp_command_rev_impl<G, L, C>(
zkapp_commands: &[&[AccountUpdate]],
stmtss: &[&[(GlobalState<SparseLedger>, LocalStateEnv<SparseLedger>, Fp)]],
acc: &mut Vec<ZkappCommandIntermediateState>,
) {
stmtss: &[&[(G, L, C)]],
acc: &mut Vec<ZkappCommandIntermediateState<G, L, C>>,
)
where
G: Clone,
L: Clone,
C: Clone,
{
use Kind::{New, Same, TwoNew};
use Control::{Proof, Signature, NoneGiven};

Expand Down

0 comments on commit c9318ef

Please sign in to comment.