pub fn eval(config: &GlobalConfig, transactions: &[Transaction]) -> Result<EvaluationResult> {
    // set up empty evaluation result
    let mut res = EvaluationResult {
        outputs: vec![],
        status: Status::Failure,
    };

    // set up a fake executor with the genesis block and create the accounts
    let mut exec = FakeExecutor::from_genesis_with_options(VMPublishingOption::Open);
    for data in config.accounts.values() {
        exec.add_account_data(&data);
    }

    // set up standard library
    // needed to compile transaction programs
    let mut deps = build_stdlib(&AccountAddress::default());

    for transaction in transactions {
        // get the account data of the sender
        let data = config.accounts.get(&transaction.config.sender).unwrap();
        let addr = data.address();

        // start processing a new transaction
        // insert a barrier in the output
        res.outputs.push(EvaluationOutput::Transaction);

        // stage 1: parse the program
        res.outputs.push(EvaluationOutput::Stage(Stage::Parser));
        let parsed_program = unwrap_or_log!(parse_program(&transaction.program), res);
        res.outputs
            .push(EvaluationOutput::Output(format!("{:?}", parsed_program)));

        // stage 2: compile the program
        res.outputs.push(EvaluationOutput::Stage(Stage::Compiler));
        let compiled_program = unwrap_or_log!(compile_program(addr, &parsed_program, &deps), res);
        res.outputs
            .push(EvaluationOutput::Output(format!("{:?}", compiled_program)));

        // stage 3: verify the program
        if !transaction.config.no_verify {
            res.outputs.push(EvaluationOutput::Stage(Stage::Verifier));
            unwrap_or_log!(do_verify_program(&compiled_program, &deps), res);
            res.outputs.push(EvaluationOutput::Output("".to_string()));
        }

        // add all modules to be published to the vec of dependencies
        // TODO: currently the compiler only checks the module name when looking up a module
        //       it should check that both the name and address match
        for m in &compiled_program.modules {
            deps.push(m.clone());
        }

        // stage 4: execute the program
        if !transaction.config.no_execute {
            res.outputs.push(EvaluationOutput::Stage(Stage::Runtime));
            let txn_output = unwrap_or_log!(
                run_transaction(&mut exec, data, &compiled_program, &transaction.config.args),
                res
            );
            res.outputs
                .push(EvaluationOutput::Output(format!("{:?}", txn_output)));

            // apply the writeset
            exec.apply_write_set(txn_output.write_set());
        }
    }

    res.status = Status::Success;
    Ok(res)
}
/// Feeds all given transactions through the pipeline and produces an EvaluationResult.
Feeds all given transactions through the pipeline and produces an EvaluationResult.
Feeds all given transactions through the pipeline and produces an EvaluationResult .
pub fn eval(config: &GlobalConfig, transactions: &[Transaction]) -> Result<EvaluationResult> {
    // set up empty evaluation result
    let mut res = EvaluationResult {
        outputs: vec![],
        status: Status::Failure,
    };
    // set up a fake executor with the genesis block and create the accounts
    let mut exec = FakeExecutor::from_genesis_with_options(VMPublishingOption::Open);
    for data in config.accounts.values() {
        exec.add_account_data(&data);
    }
    // set up standard library
    // needed to compile transaction programs
    let mut deps = build_stdlib(&AccountAddress::default());
    for transaction in transactions {
        // get the account data of the sender
        let data = config.accounts.get(&transaction.config.sender).unwrap();
        let addr = data.address();
        // start processing a new transaction
        // insert a barrier in the output
        res.outputs.push(EvaluationOutput::Transaction);
        // stage 1: parse the program
        res.outputs.push(EvaluationOutput::Stage(Stage::Parser));
        let parsed_program = unwrap_or_log!(parse_program(&transaction.program), res);
        res.outputs
            .push(EvaluationOutput::Output(format!("{:?}", parsed_program)));
        // stage 2: compile the program
        res.outputs.push(EvaluationOutput::Stage(Stage::Compiler));
        let compiled_program = unwrap_or_log!(compile_program(addr, &parsed_program, &deps), res);
        res.outputs
            .push(EvaluationOutput::Output(format!("{:?}", compiled_program)));
        // stage 3: verify the program
        if !transaction.config.no_verify {
            res.outputs.push(EvaluationOutput::Stage(Stage::Verifier));
            unwrap_or_log!(do_verify_program(&compiled_program, &deps), res);
            res.outputs.push(EvaluationOutput::Output("".to_string()));
        }
        // add all modules to be published to the vec of dependencies
        // TODO: currently the compiler only checks the module name when looking up a module
        //       it should check that both the name and address match
        for m in &compiled_program.modules {
            deps.push(m.clone());
        }
        // stage 4: execute the program
        if !transaction.config.no_execute {
            res.outputs.push(EvaluationOutput::Stage(Stage::Runtime));
            let txn_output = unwrap_or_log!(
                run_transaction(&mut exec, data, &compiled_program, &transaction.config.args),
                res
            );
            res.outputs
                .push(EvaluationOutput::Output(format!("{:?}", txn_output)));
            // apply the writeset
            exec.apply_write_set(txn_output.write_set());
        }
    }
    res.status = Status::Success;
    Ok(res)
}
pub fn eval ( config : & GlobalConfig , transactions : & [ Transaction ] ) -> Result < EvaluationResult > { // set up empty evaluation result let mut res = EvaluationResult { outputs : vec ! [ ] , status : Status :: Failure , } ; // set up a fake executor with the genesis block and create the accounts let mut exec = FakeExecutor :: from_genesis_with_options ( VMPublishingOption :: Open ) ; for data in config . accounts . values ( ) { exec . add_account_data ( & data ) ; } // set up standard library // needed to compile transaction programs let mut deps = build_stdlib ( & AccountAddress :: default ( ) ) ; for transaction in transactions { // get the account data of the sender let data = config . accounts . get ( & transaction . config . sender ) . unwrap ( ) ; let addr = data . address ( ) ; // start processing a new transaction // insert a barrier in the output res . outputs . push ( EvaluationOutput :: Transaction ) ; // stage 1: parse the program res . outputs . push ( EvaluationOutput :: Stage ( Stage :: Parser ) ) ; let parsed_program = unwrap_or_log ! ( parse_program ( transaction program ) res ) ; res . outputs . push ( EvaluationOutput :: Output ( format ! ( " " parsed_program ) ) ) ; // stage 2: compile the program res . outputs . push ( EvaluationOutput :: Stage ( Stage :: Compiler ) ) ; let compiled_program = unwrap_or_log ! ( compile_program ( addr parsed_program deps ) res ) ; res . outputs . push ( EvaluationOutput :: Output ( format ! ( " " compiled_program ) ) ) ; // stage 3: verify the program if ! transaction . config . no_verify { res . outputs . push ( EvaluationOutput :: Stage ( Stage :: Verifier ) ) ; unwrap_or_log ! ( do_verify_program ( compiled_program deps ) res ) ; res . outputs . push ( EvaluationOutput :: Output ( " " . to_string ( ) ) ) ; } // add all modules to be published to the vec of dependencies // TODO: currently the compiler only checks the module name when looking up a module //       it should check that both the name and address match for m in & compiled_program . modules { deps . push ( m . clone ( ) ) ; } // stage 4: execute the program if ! transaction . config . no_execute { res . outputs . push ( EvaluationOutput :: Stage ( Stage :: Runtime ) ) ; let txn_output = unwrap_or_log ! ( run_transaction ( mut exec data compiled_program transaction config args ) res ) ; res . outputs . push ( EvaluationOutput :: Output ( format ! ( " " txn_output ) ) ) ; // apply the writeset exec . apply_write_set ( txn_output . write_set ( ) ) ; } } res . status = Status :: Success ; Ok ( res ) }
Feeds all given transactions through the pipeline and produces an EvaluationResult.
Feeds all given transactions through the pipeline and produces an EvaluationResult .
config
&GlobalConfig
transactions
&[Transaction]
config
&GlobalConfig
transactions
&[Transaction]