Struct massa_models::secure_share::SecureShare
source · pub struct SecureShare<T, ID>{
pub content: T,
pub serialized_data: Vec<u8>,
pub signature: Signature,
pub content_creator_pub_key: PublicKey,
pub content_creator_address: Address,
pub id: ID,
}
Expand description
Packages type T such that it can be securely sent and received in a trust-free network
If the internal content is mutated, then it must be re-wrapped, as the associated signature, serialized data, etc. would no longer be in sync
Fields§
§content: T
Reference contents. Not required for the security protocols.
Use the Lightweight equivalent structures when you need verifiable serialized data, but do not need to read the values directly (such as when sending)
serialized_data: Vec<u8>
Content in sharable, deserializable form. Is used in the secure verification protocols.
signature: Signature
A cryptographically generated value using serialized_data
and a public key.
content_creator_pub_key: PublicKey
The public-key component used in the generation of the signature
content_creator_address: Address
Derived from the same public key used to generate the signature
id: ID
A secure hash of the data. See also massa_hash::Hash
Implementations§
sourcepub fn bytes_count(&self) -> u64
pub fn bytes_count(&self) -> u64
size in bytes of the whole block
sourcepub fn contains_operation(&self, op: SecureShareOperation) -> bool
pub fn contains_operation(&self, op: SecureShareOperation) -> bool
true if given operation is included in the block
sourcepub fn get_fitness(&self) -> u64
pub fn get_fitness(&self) -> u64
returns the fitness of the block
sourcepub fn get_fitness(&self) -> u64
pub fn get_fitness(&self) -> u64
gets the header fitness
sourcepub fn get_validity_range(
&self,
operation_validity_period: u64,
) -> RangeInclusive<u64>
pub fn get_validity_range( &self, operation_validity_period: u64, ) -> RangeInclusive<u64>
get the range of periods during which an operation is valid
Range: (op.expire_period - cfg.operation_validity_period) -> op.expire_period
(included)
sourcepub fn get_gas_usage(
&self,
base_operation_gas_cost: u64,
sp_compilation_cost: u64,
) -> u64
pub fn get_gas_usage( &self, base_operation_gas_cost: u64, sp_compilation_cost: u64, ) -> u64
Get the maximum amount of gas used by the operation.
base_operation_gas_cost comes from the configuration and is the cost of a basic operation (BASE_OPERATION_GAS_COST)
sourcepub fn get_ledger_involved_addresses(&self) -> PreHashSet<Address>
pub fn get_ledger_involved_addresses(&self) -> PreHashSet<Address>
get the addresses that are involved in this operation from a ledger point of view
sourcepub fn get_max_spending(&self, roll_price: Amount) -> Amount
pub fn get_max_spending(&self, roll_price: Amount) -> Amount
Gets the maximal amount of coins that may be spent by this operation (incl. fee)
sourcepub fn get_roll_involved_addresses(
&self,
) -> Result<PreHashSet<Address>, ModelsError>
pub fn get_roll_involved_addresses( &self, ) -> Result<PreHashSet<Address>, ModelsError>
get the addresses that are involved in this operation from a rolls point of view
sourcepub fn sign(
keypair: &KeyPair,
content_hash: &Hash,
_content: &T,
) -> Result<Signature, ModelsError>
pub fn sign( keypair: &KeyPair, content_hash: &Hash, _content: &T, ) -> Result<Signature, ModelsError>
Sign the SecureShare given the content
sourcepub fn verify_signature(&self) -> Result<(), ModelsError>
pub fn verify_signature(&self) -> Result<(), ModelsError>
check if self has been signed by public key
sourcepub fn compute_signed_hash(&self) -> Hash
pub fn compute_signed_hash(&self) -> Hash
Compute the signed hash
sourcepub fn serialized_size(&self) -> usize
pub fn serialized_size(&self) -> usize
get full serialized size
Trait Implementations§
source§fn clone(&self) -> SecureShare<T, ID>
fn clone(&self) -> SecureShare<T, ID>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§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§fn deserialize<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(
&self,
buffer: &'a [u8],
) -> IResult<&'a [u8], SecureShare<T, ID>, E>
fn deserialize<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>( &self, buffer: &'a [u8], ) -> IResult<&'a [u8], SecureShare<T, ID>, E>
use massa_models::block_id::BlockId;
use massa_models::config::CHAINID;
let content = Endorsement {
slot: Slot::new(10, 1),
index: 0,
endorsed_block: BlockId::generate_from_hash(Hash::compute_from("blk".as_bytes())),
};
let keypair = KeyPair::generate(0).unwrap();
let secured: SecureShare<Endorsement, BlockId> = Endorsement::new_verifiable(
content,
EndorsementSerializer::new(),
&keypair,
*CHAINID
).unwrap();
let mut serialized_data = Vec::new();
let serialized = SecureShareSerializer::new().serialize(&secured, &mut serialized_data).unwrap();
let deserializer = SecureShareDeserializer::new(EndorsementDeserializer::new(32, 1), 77);
let (rest, deserialized): (&[u8], SecureShare<Endorsement, BlockId>) = deserializer.deserialize::<DeserializeError>(&serialized_data).unwrap();
assert!(rest.is_empty());
assert_eq!(secured.id, deserialized.id);
source§fn from(value: &SecuredHeader) -> Self
fn from(value: &SecuredHeader) -> Self
source§fn from(value: &SecureShareEndorsement) -> Self
fn from(value: &SecureShareEndorsement) -> Self
source§fn from(value: SecureShareBlock) -> Self
fn from(value: SecureShareBlock) -> Self
source§fn from(value: SecuredHeader) -> Self
fn from(value: SecuredHeader) -> Self
source§fn from(value: SecureShareEndorsement) -> Self
fn from(value: SecureShareEndorsement) -> Self
source§fn from(value: SecureShareOperation) -> Self
fn from(value: SecureShareOperation) -> Self
source§fn eq(&self, other: &SecureShare<T, ID>) -> bool
fn eq(&self, other: &SecureShare<T, ID>) -> bool
self
and other
values to be equal, and is used
by ==
.source§fn serialize(
&self,
value: &SecureShare<T, ID>,
buffer: &mut Vec<u8>,
) -> Result<(), SerializeError>
fn serialize( &self, value: &SecureShare<T, ID>, buffer: &mut Vec<u8>, ) -> Result<(), SerializeError>
Auto Trait Implementations§
Blanket Implementations§
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> Conv for T
impl<T> Conv for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.