/// Convert a NodeId to the correct NodeIndex, based on the transcript operation
///
/// The NodeIndex is such that it allows the previous transcript(s) (if any)
/// to be properly recombined (i.e. the indices are for the previous sharing,
/// if this is a resharing or multiplication).
Convert a NodeId to the correct NodeIndex, based on the transcript operation
The NodeIndex is such that it allows the previous transcript(s) (if any)
to be properly recombined .
Convert a NodeId to the correct NodeIndex based on the transcript operation The NodeIndex is such that it allows the previous transcript ( s ) ( if any ) to be properly recombined .
fn id_to_index(
    id: NodeId,
    dealers: &IDkgDealers,
    op_type: &IDkgTranscriptOperation,
) -> Result<NodeIndex, IDkgCreateTranscriptError> {
    fn dealer_id_to_index(
        id: NodeId,
        dealers: &IDkgDealers,
    ) -> Result<NodeIndex, IDkgCreateTranscriptError> {
        dealers
            .position(id)
            .ok_or(IDkgCreateTranscriptError::DealerNotAllowed { node_id: id })
        // this should already have been checked by
        // `ensure_dealers_allowed_by_params`
    }
    fn receiver_id_to_index(
        id: NodeId,
        receivers: &IDkgReceivers,
    ) -> Result<NodeIndex, IDkgCreateTranscriptError> {
        receivers
            .position(id)
            .ok_or(IDkgCreateTranscriptError::DealerNotAllowed { node_id: id })
        // this should already have been checked by
        // IDkgTranscriptParams::new
    }
    match op_type {
        IDkgTranscriptOperation::Random => dealer_id_to_index(id, dealers),
        IDkgTranscriptOperation::ReshareOfMasked(transcript) => {
            receiver_id_to_index(id, &transcript.receivers)
        }
        IDkgTranscriptOperation::ReshareOfUnmasked(transcript) => {
            receiver_id_to_index(id, &transcript.receivers)
        }
        IDkgTranscriptOperation::UnmaskedTimesMasked(transcript, _) => {
            // transcript_1.receivers == transcript_2.receivers already checked by
            // IDkgTranscriptParams::new
            receiver_id_to_index(id, &transcript.receivers)
        }
    }
}
fn id_to_index ( id : NodeId , dealers : & IDkgDealers , op_type : & IDkgTranscriptOperation , ) -> Result < NodeIndex , IDkgCreateTranscriptError > { fn dealer_id_to_index ( id : NodeId , dealers : & IDkgDealers , ) -> Result < NodeIndex , IDkgCreateTranscriptError > { dealers . position ( id ) . ok_or ( IDkgCreateTranscriptError :: DealerNotAllowed { node_id : id } ) // this should already have been checked by // `ensure_dealers_allowed_by_params` } fn receiver_id_to_index ( id : NodeId , receivers : & IDkgReceivers , ) -> Result < NodeIndex , IDkgCreateTranscriptError > { receivers . position ( id ) . ok_or ( IDkgCreateTranscriptError :: DealerNotAllowed { node_id : id } ) // this should already have been checked by // IDkgTranscriptParams::new } match op_type { IDkgTranscriptOperation :: Random => dealer_id_to_index ( id , dealers ) , IDkgTranscriptOperation :: ReshareOfMasked ( transcript ) => { receiver_id_to_index ( id , & transcript . receivers ) } IDkgTranscriptOperation :: ReshareOfUnmasked ( transcript ) => { receiver_id_to_index ( id , & transcript . receivers ) } IDkgTranscriptOperation :: UnmaskedTimesMasked ( transcript , _ ) => { // transcript_1.receivers == transcript_2.receivers already checked by // IDkgTranscriptParams::new receiver_id_to_index ( id , & transcript . receivers ) } } }
Convert a NodeId to the correct NodeIndex, based on the transcript operation
The NodeIndex is such that it allows the previous transcript(s) (if any)
to be properly recombined (i.e.
Convert a NodeId to the correct NodeIndex based on the transcript operation The NodeIndex is such that it allows the previous transcript ( s ) ( if any ) to be properly recombined ( i . e .
id
NodeId
dealers
&IDkgDealers
op_type
&IDkgTranscriptOperation