github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/validator/src/execution/py_executor.rs (about)

     1  /*
     2   * Copyright 2018 Intel Corporation
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   * ------------------------------------------------------------------------------
    16   */
    17  
    18  use cpython;
    19  use cpython::ObjectProtocol;
    20  
    21  use execution::execution_platform::ExecutionPlatform;
    22  
    23  use scheduler::py_scheduler::PyScheduler;
    24  use scheduler::Scheduler;
    25  
    26  pub struct PyExecutor {
    27      executor: cpython::PyObject,
    28  }
    29  
    30  impl PyExecutor {
    31      pub fn new(executor: cpython::PyObject) -> Result<PyExecutor, cpython::PyErr> {
    32          Ok(PyExecutor { executor })
    33      }
    34  }
    35  
    36  impl ExecutionPlatform for PyExecutor {
    37      fn create_scheduler(&self, state_hash: &str) -> Result<Box<Scheduler>, cpython::PyErr> {
    38          let py = unsafe { cpython::Python::assume_gil_acquired() };
    39  
    40          let scheduler = self.executor
    41              .call_method(py, "create_scheduler", (state_hash,), None)
    42              .expect(
    43                  "no method create_scheduler on sawtooth_validator.execution.py_executor.PyExecutor",
    44              );
    45          Ok(Box::new(PyScheduler::new(scheduler)))
    46      }
    47  }