pub struct Hash(/* private fields */);
Expand description
A SHA-256 hash, most commonly used for blockhashes.
Args: hash_bytes (bytes): the hashed bytes.
Implementations§
Source§impl Hash
impl Hash
pub const LENGTH: usize = 32usize
pub fn new(hash_bytes: [u8; 32]) -> Self
Sourcepub fn new_from_string(s: &str) -> PyResult<Self>
pub fn new_from_string(s: &str) -> PyResult<Self>
Create a Hash
from a base-58 string.
Args: s (str): The base-58 encoded string
Returns:
Hash: a Hash
object.
Example:
>>> from solders.hash import Hash
>>> Hash.from_string("4uQeVj5tqViQh7yWWGStvkEG1Zmhx6uasJtWCJziofM")
Hash(
4uQeVj5tqViQh7yWWGStvkEG1Zmhx6uasJtWCJziofM,
)
Sourcepub fn new_unique() -> Self
pub fn new_unique() -> Self
Create a unique Hash for tests and benchmarks.
Returns:
Hash: a Hash
object.
Sourcepub fn new_default() -> Self
pub fn new_default() -> Self
The default Hash
object.
Returns:
Hash: a Hash
object.
Example:
>>> from solders.hash import Hash
>>> Hash.default()
Hash(
11111111111111111111111111111111,
)
Sourcepub fn hash(val: &[u8]) -> Self
pub fn hash(val: &[u8]) -> Self
Return a Sha256 hash for the given data.
Args: val (bytes): the data to hash.
Returns:
Hash: a Hash
object.
Example: >>> from solders.hash import Hash >>> Hash.hash(b“foo“) Hash( 3yMApqCuCjXDWPrbjfR5mjCPTHqFG8Pux1TxQrEM35jj, )
Sourcepub fn from_bytes(raw_bytes: [u8; 32]) -> PyResult<Self>
pub fn from_bytes(raw_bytes: [u8; 32]) -> PyResult<Self>
Construct from bytes
. Equivalent to Hash.__init__
but included for the sake of consistency.
Args: raw_bytes (bytes): the hashed bytes.
Returns:
Hash: a Hash
object.
pub fn __hash__(&self) -> u64
pub fn __richcmp__(&self, other: &Self, op: CompareOp) -> bool
pub fn __bytes__<'a>(&self, py: Python<'a>) -> &'a PyBytes
pub fn __str__(&self) -> String
pub fn __repr__(&self) -> String
pub fn __reduce__(&self) -> PyResult<(PyObject, PyObject)>
Trait Implementations§
Source§impl AsRef<Hash> for Hash
impl AsRef<Hash> for Hash
Source§fn as_ref(&self) -> &HashOriginal
fn as_ref(&self) -> &HashOriginal
Source§impl CommonMethods<'_> for Hash
impl CommonMethods<'_> for Hash
fn py_to_json(&self) -> String
fn py_from_json(raw: &'a str) -> Result<Self, PyErr>
Source§impl CommonMethodsCore for Hash
impl CommonMethodsCore for Hash
Source§impl<'de> Deserialize<'de> for Hash
impl<'de> Deserialize<'de> for Hash
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<Hash> for Hash
impl From<Hash> for Hash
Source§fn from(original: HashOriginal) -> Hash
fn from(original: HashOriginal) -> Hash
Source§impl Ord for Hash
impl Ord for Hash
Source§impl PartialOrd for Hash
impl PartialOrd for Hash
Source§impl PyBytesGeneral for Hash
impl PyBytesGeneral for Hash
fn pybytes_general<'a>(&self, py: Python<'a>) -> &'a PyBytes
Source§impl PyBytesSlice for Hash
impl PyBytesSlice for Hash
fn pybytes_slice<'a>(&self, py: Python<'a>) -> &'a PyBytes
Source§impl PyClassImpl for Hash
impl PyClassImpl for Hash
Source§const IS_BASETYPE: bool = true
const IS_BASETYPE: bool = true
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§type ThreadChecker = SendablePyClass<Hash>
type ThreadChecker = SendablePyClass<Hash>
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny
by default, and when you declare
#[pyclass(extends=PyDict)]
, it’s PyDict
.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
Source§impl PyClassNewTextSignature<Hash> for PyClassImplCollector<Hash>
impl PyClassNewTextSignature<Hash> for PyClassImplCollector<Hash>
fn new_text_signature(self) -> Option<&'static str>
Source§impl PyFromBytesGeneral for Hash
impl PyFromBytesGeneral for Hash
fn py_from_bytes_general(raw: &[u8]) -> PyResult<Self>
Source§impl PyMethods<Hash> for PyClassImplCollector<Hash>
impl PyMethods<Hash> for PyClassImplCollector<Hash>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for Hash
impl PyTypeInfo for Hash
Source§type AsRefTarget = PyCell<Hash>
type AsRefTarget = PyCell<Hash>
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
Source§fn type_object(py: Python<'_>) -> &PyType
fn type_object(py: Python<'_>) -> &PyType
Source§fn is_type_of(object: &PyAny) -> bool
fn is_type_of(object: &PyAny) -> bool
object
is an instance of this type or a subclass of this type.Source§fn is_exact_type_of(object: &PyAny) -> bool
fn is_exact_type_of(object: &PyAny) -> bool
object
is an instance of this type.impl Copy for Hash
impl Eq for Hash
impl StructuralPartialEq for Hash
Auto Trait Implementations§
impl Freeze for Hash
impl RefUnwindSafe for Hash
impl Send for Hash
impl Sync for Hash
impl Unpin for Hash
impl UnwindSafe for Hash
Blanket Implementations§
Source§impl<T> AbiEnumVisitor for T
impl<T> AbiEnumVisitor for T
default fn visit_for_abi( &self, _digester: &mut AbiDigester, ) -> Result<AbiDigester, DigestError>
Source§impl<T> AbiEnumVisitor for T
impl<T> AbiEnumVisitor for T
default fn visit_for_abi( &self, digester: &mut AbiDigester, ) -> Result<AbiDigester, DigestError>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<'a, T> FromPyObject<'a> for T
impl<'a, T> FromPyObject<'a> for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more