namada icon indicating copy to clipboard operation
namada copied to clipboard

Refactor inner `Tx`s interface

Open grarco opened this issue 1 year ago • 3 comments

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

grarco avatar May 08 '24 15:05 grarco

Depends on #3103

sug0 avatar May 13 '24 12:05 sug0

@grarco Is this still applicable?

cwgoes avatar Aug 22 '24 07:08 cwgoes

Yes it is

grarco avatar Aug 22 '24 08:08 grarco