-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sam H. Smith <sam.henning.smith@protonmail.com>
- Loading branch information
Showing
2 changed files
with
157 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,72 @@ | ||
use pyo3::prelude::*; | ||
|
||
pub fn register_items(_py: Python<'_>, _module: &PyModule) -> PyResult<()> { | ||
use super::PyMirror; | ||
use iroha_data_model::prelude::PermissionToken; | ||
use iroha_data_model::prelude::Role; | ||
|
||
#[pyclass(name = "Role")] | ||
#[derive(Clone, derive_more::From, derive_more::Into, derive_more::Deref)] | ||
pub struct PyRole(pub Role); | ||
|
||
impl PyMirror for Role { | ||
type Mirror = PyRole; | ||
|
||
fn mirror(self) -> PyResult<Self::Mirror> { | ||
Ok(PyRole(self)) | ||
} | ||
} | ||
|
||
#[pymethods] | ||
impl PyRole { | ||
#[getter] | ||
fn get_role_id(&self) -> String { | ||
self.0.id.name.to_string() | ||
} | ||
|
||
#[getter] | ||
fn get_permissions(&self) -> Vec<PyPermissionToken> { | ||
self.0 | ||
.permissions | ||
.iter() | ||
.map(|x| PyPermissionToken(x.clone())) | ||
.collect() | ||
} | ||
|
||
fn __repr__(&self) -> String { | ||
format!("{:?}", self.0) | ||
} | ||
} | ||
|
||
#[pyclass(name = "PermissionToken")] | ||
#[derive(Clone, derive_more::From, derive_more::Into, derive_more::Deref)] | ||
pub struct PyPermissionToken(pub PermissionToken); | ||
|
||
impl PyMirror for PermissionToken { | ||
type Mirror = PyPermissionToken; | ||
|
||
fn mirror(self) -> PyResult<Self::Mirror> { | ||
Ok(PyPermissionToken(self)) | ||
} | ||
} | ||
|
||
#[pymethods] | ||
impl PyPermissionToken { | ||
#[getter] | ||
fn get_definition_id(&self) -> String { | ||
format!("{:?}", self.0.definition_id) | ||
} | ||
|
||
#[getter] | ||
fn get_payload(&self) -> String { | ||
format!("{:?}", self.0.payload) | ||
} | ||
|
||
fn __repr__(&self) -> String { | ||
format!("{:?}", self.0) | ||
} | ||
} | ||
|
||
pub fn register_items(_py: Python<'_>, module: &PyModule) -> PyResult<()> { | ||
module.add_class::<PyRole>()?; | ||
Ok(()) | ||
} |