pub fn from<T>(
        id: &FragmentId,
        auth_tx: &AuthenticatedTransaction<Address, T>,
        discrimination: Discrimination,
        transactions: &Transactions,
        blocks: &Blocks,
        certificate: Option<Certificate>,
    ) -> ExplorerTransaction {
        let outputs = auth_tx.transaction.outputs.iter();
        let inputs = auth_tx.transaction.inputs.iter();
        let witnesses = auth_tx.witnesses.iter();

        let new_outputs = outputs
            .map(|output| ExplorerOutput {
                address: output.address.clone(),
                value: output.value,
            })
            .collect();

        let new_inputs = inputs
            .map(|i| i.to_enum())
            .zip(witnesses)
            .filter_map(|input_with_witness| match input_with_witness {
                (InputEnum::AccountInput(id, value), Witness::Account(_)) => {
                    let kind = chain_addr::Kind::Account(
                        id.to_single_account()
                            .expect("the input to be validated")
                            .into(),
                    );
                    let address = Address(discrimination, kind);
                    Some(ExplorerInput { address, value })
                }
                (InputEnum::AccountInput(_id, _value), Witness::Multisig(_)) => {
                    // TODO
                    None
                }
                (InputEnum::UtxoInput(utxo_pointer), _witness) => {
                    let tx = utxo_pointer.transaction_id;
                    let index = utxo_pointer.output_index;

                    let block_id = transactions.lookup(&tx).expect("the input to be validated");

                    let block = blocks.lookup(&block_id).expect("the input to be validated");

                    let output = &block.transactions[&tx].outputs[index as usize];

                    Some(ExplorerInput {
                        address: output.address.clone(),
                        value: output.value,
                    })
                }
                _ => None,
            })
            .collect();

        ExplorerTransaction {
            id: *id,
            inputs: new_inputs,
            outputs: new_outputs,
            certificate,
        }
    }
/// Map the given AuthenticatedTransaction to the ExplorerTransaction API representation
/// type.
/// the fragment id is the associated to the given AuthenticatedTransaction before 'unwrapping'
/// The discrimination is needed to get addresses from account inputs.
/// The transactions and blocks are used to resolve utxo inputs
Map the given AuthenticatedTransaction to the ExplorerTransaction API representation
type.
the fragment id is the associated to the given AuthenticatedTransaction before 'unwrapping'
The discrimination is needed to get addresses from account inputs.
The transactions and blocks are used to resolve utxo inputs
Map the given AuthenticatedTransaction to the ExplorerTransaction API representation type . the fragment id is the associated to the given AuthenticatedTransaction before ' unwrapping ' The discrimination is needed to get addresses from account inputs . The transactions and blocks are used to resolve utxo inputs
pub fn from<T>(
        id: &FragmentId,
        auth_tx: &AuthenticatedTransaction<Address, T>,
        discrimination: Discrimination,
        transactions: &Transactions,
        blocks: &Blocks,
        certificate: Option<Certificate>,
    ) -> ExplorerTransaction {
        let outputs = auth_tx.transaction.outputs.iter();
        let inputs = auth_tx.transaction.inputs.iter();
        let witnesses = auth_tx.witnesses.iter();
        let new_outputs = outputs
            .map(|output| ExplorerOutput {
                address: output.address.clone(),
                value: output.value,
            })
            .collect();
        let new_inputs = inputs
            .map(|i| i.to_enum())
            .zip(witnesses)
            .filter_map(|input_with_witness| match input_with_witness {
                (InputEnum::AccountInput(id, value), Witness::Account(_)) => {
                    let kind = chain_addr::Kind::Account(
                        id.to_single_account()
                            .expect("the input to be validated")
                            .into(),
                    );
                    let address = Address(discrimination, kind);
                    Some(ExplorerInput { address, value })
                }
                (InputEnum::AccountInput(_id, _value), Witness::Multisig(_)) => {
                    // TODO
                    None
                }
                (InputEnum::UtxoInput(utxo_pointer), _witness) => {
                    let tx = utxo_pointer.transaction_id;
                    let index = utxo_pointer.output_index;
                    let block_id = transactions.lookup(&tx).expect("the input to be validated");
                    let block = blocks.lookup(&block_id).expect("the input to be validated");
                    let output = &block.transactions[&tx].outputs[index as usize];
                    Some(ExplorerInput {
                        address: output.address.clone(),
                        value: output.value,
                    })
                }
                _ => None,
            })
            .collect();
        ExplorerTransaction {
            id: *id,
            inputs: new_inputs,
            outputs: new_outputs,
            certificate,
        }
    }
pub fn from < T > ( id : & FragmentId , auth_tx : & AuthenticatedTransaction < Address , T > , discrimination : Discrimination , transactions : & Transactions , blocks : & Blocks , certificate : Option < Certificate > , ) -> ExplorerTransaction { let outputs = auth_tx . transaction . outputs . iter ( ) ; let inputs = auth_tx . transaction . inputs . iter ( ) ; let witnesses = auth_tx . witnesses . iter ( ) ; let new_outputs = outputs . map ( | output | ExplorerOutput { address : output . address . clone ( ) , value : output . value , } ) . collect ( ) ; let new_inputs = inputs . map ( | i | i . to_enum ( ) ) . zip ( witnesses ) . filter_map ( | input_with_witness | match input_with_witness { ( InputEnum :: AccountInput ( id , value ) , Witness :: Account ( _ ) ) => { let kind = chain_addr :: Kind :: Account ( id . to_single_account ( ) . expect ( " " ) . into ( ) , ) ; let address = Address ( discrimination , kind ) ; Some ( ExplorerInput { address , value } ) } ( InputEnum :: AccountInput ( _id , _value ) , Witness :: Multisig ( _ ) ) => { // TODO None } ( InputEnum :: UtxoInput ( utxo_pointer ) , _witness ) => { let tx = utxo_pointer . transaction_id ; let index = utxo_pointer . output_index ; let block_id = transactions . lookup ( & tx ) . expect ( " " ) ; let block = blocks . lookup ( & block_id ) . expect ( " " ) ; let output = & block . transactions [ & tx ] . outputs [ index as usize ] ; Some ( ExplorerInput { address : output . address . clone ( ) , value : output . value , } ) } _ => None , } ) . collect ( ) ; ExplorerTransaction { id : * id , inputs : new_inputs , outputs : new_outputs , certificate , } }
Map the given AuthenticatedTransaction to the ExplorerTransaction API representation
type.
Map the given AuthenticatedTransaction to the ExplorerTransaction API representation type .
id
&FragmentId
auth_tx
&AuthenticatedTransaction<Address, T>
discrimination
Discrimination
transactions
&Transactions
blocks
&Blocks
certificate
Option<Certificate>
id
&FragmentId
auth_tx
&AuthenticatedTransaction<Address, T>
discrimination
Discrimination
transactions
&Transactions
blocks
&Blocks
certificate
Option<Certificate>