Struct solders_hash::Hash
source · 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 PartialEq for Hash
impl PartialEq for Hash
source§impl PartialOrd for Hash
impl PartialOrd for Hash
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§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
§type ThreadChecker = ThreadCheckerStub<Hash>
type ThreadChecker = ThreadCheckerStub<Hash>
§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
§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
§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.