anoma / namada

Rust implementation of Namada, a Proof-of-Stake L1 for interchain asset-agnostic privacy
https://namada.net
GNU General Public License v3.0
2.39k stars 944 forks source link

Refactor inner `Tx`s interface #3200

Open grarco opened 4 months ago

grarco commented 4 months ago

Possible improvement of the way we access the section commitments of an inner tx

enum TxCommitmentRef {
    Id(TxCommitments),
    Hash(Hash),
    Index(usize),
}

impl TxCommitmentRef {
    fn get_commitments(
        &self,
        batch: impl IntoIterator<Item = &TxCommitments>,
    ) -> Option<&TxCommitments> {
        match self {
            Self::Id(commitments) => {
                // FIXME: check that `commitments` is present in `batch`?
                commitments
            }
            Self::Hash(commitments_hash) => batch.into_iter().find_map(|commitments| {
                (hash(commitments) == commitments_hash).then_some(commitments)
            }),
            Self::Index(index) => batch.into_iter().nth(index),
        }
    }
}

_Originally posted by @sug0 in https://github.com/anoma/namada/pull/3103#discussion_r1589154606_

sug0 commented 4 months ago

Depends on #3103

cwgoes commented 3 weeks ago

@grarco Is this still applicable?

grarco commented 3 weeks ago

Yes it is