Struct massa_ledger_exports::LedgerChanges
source · pub struct LedgerChanges(pub PreHashMap<Address, SetUpdateOrDelete<LedgerEntry, LedgerEntryUpdate>>);Expand description
represents a list of changes to multiple ledger entries
Tuple Fields§
§0: PreHashMap<Address, SetUpdateOrDelete<LedgerEntry, LedgerEntryUpdate>>Implementations§
source§impl LedgerChanges
impl LedgerChanges
sourcepub fn get(
&self,
addr: &Address,
) -> Option<&SetUpdateOrDelete<LedgerEntry, LedgerEntryUpdate>>
pub fn get( &self, addr: &Address, ) -> Option<&SetUpdateOrDelete<LedgerEntry, LedgerEntryUpdate>>
Get an item from the LedgerChanges
sourcepub fn get_bytecode_updates(&self) -> Vec<Bytecode>
pub fn get_bytecode_updates(&self) -> Vec<Bytecode>
Retrieves all the bytcode updates contained in the current changes
sourcepub fn create_address(&mut self, address: &Address)
pub fn create_address(&mut self, address: &Address)
Create a new, empty address. Overwrites the address if it is already there.
sourcepub fn get_balance_or_else<F: FnOnce() -> Option<Amount>>(
&self,
addr: &Address,
f: F,
) -> Option<Amount>
pub fn get_balance_or_else<F: FnOnce() -> Option<Amount>>( &self, addr: &Address, f: F, ) -> Option<Amount>
Tries to return the balance of an entry or gets it from a function if the entry’s status is unknown.
This function is used as an optimization:
if the value can be deduced unambiguously from the LedgerChanges,
no need to dig further (for example in the FinalLedger).
§Arguments
addr: address for which to get the valuef: fallback function with no arguments and returningOption<Amount>
§Returns
- Some(v) if a value is present, where v is a copy of the value
- None if the value is absent
- f() if the value is unknown
sourcepub fn get_bytecode_or_else<F: FnOnce() -> Option<Bytecode>>(
&self,
addr: &Address,
f: F,
) -> Option<Bytecode>
pub fn get_bytecode_or_else<F: FnOnce() -> Option<Bytecode>>( &self, addr: &Address, f: F, ) -> Option<Bytecode>
Tries to return the executable bytecode of an entry or gets it from a function if the entry’s status is unknown.
This function is used as an optimization:
if the value can be deduced unambiguously from the LedgerChanges,
no need to dig further (for example in the FinalLedger).
§Arguments
addr: address for which to get the valuef: fallback function with no arguments and returningOption<Vec<u8>>
§Returns
- Some(v) if a value is present, where v is a copy of the value
- None if the value is absent
- f() if the value is unknown
sourcepub fn entry_exists_or_else<F: FnOnce() -> bool>(
&self,
addr: &Address,
f: F,
) -> bool
pub fn entry_exists_or_else<F: FnOnce() -> bool>( &self, addr: &Address, f: F, ) -> bool
Tries to return whether an entry exists or gets the information from a function if the entry’s status is unknown.
This function is used as an optimization:
if the result can be deduced unambiguously from the LedgerChanges,
no need to dig further (for example in the FinalLedger).
§Arguments
addr: address to search forf: fallback function with no arguments and returning a boolean
§Returns
- true if the entry exists
- false if the value is absent
- f() if the value’s existence is unknown
sourcepub fn set_balance(&mut self, addr: Address, balance: Amount)
pub fn set_balance(&mut self, addr: Address, balance: Amount)
Set the balance of an address. If the address doesn’t exist, its ledger entry is created.
§Arguments
addr: target addressbalance: balance to set for the provided address
sourcepub fn set_bytecode(&mut self, addr: Address, bytecode: Bytecode)
pub fn set_bytecode(&mut self, addr: Address, bytecode: Bytecode)
Set the executable bytecode of an address. If the address doesn’t exist, its ledger entry is created.
§Parameters
addr: target addressbytecode: executable bytecode to assign to that address
sourcepub fn get_data_entry_or_else<F: FnOnce() -> Option<Vec<u8>>>(
&self,
addr: &Address,
key: &[u8],
f: F,
) -> Option<Vec<u8>>
pub fn get_data_entry_or_else<F: FnOnce() -> Option<Vec<u8>>>( &self, addr: &Address, key: &[u8], f: F, ) -> Option<Vec<u8>>
Tries to return a datastore entry for a given address, or gets it from a function if the value’s status is unknown.
This function is used as an optimization:
if the result can be deduced unambiguously from the LedgerChanges,
no need to dig further (for example in the FinalLedger).
§Arguments
addr: target addresskey: datastore keyf: fallback function with no arguments and returningOption<Vec<u8>>
§Returns
- Some(v) if the value was found, where v is a copy of the value
- None if the value is absent
- f() if the value is unknown
sourcepub fn has_writes(&self, addr: &Address, key: Option<Vec<u8>>) -> bool
pub fn has_writes(&self, addr: &Address, key: Option<Vec<u8>>) -> bool
Tries to return whether the ledger changes contain a write for the given address and optionally if a datastore key write also exists in the address’s datastore. Notes:
- A ledger entry could be written to without any changes on the values associated, for example if the value was changed multiple times in the same slot.
- This code assumes Delete cannot be shadowed by Set operations in the same slot, which may not be the case when / if we allow full entry Delete given the current LedgerChanges::Delete handling. In that case, a rework may be necessary.
§Arguments
addr: target addresskey: optional datastore key
§Returns
- true if the address and, optionally the datastore key, exists in the ledger changes
sourcepub fn has_data_entry_or_else<F: FnOnce() -> bool>(
&self,
addr: &Address,
key: &[u8],
f: F,
) -> bool
pub fn has_data_entry_or_else<F: FnOnce() -> bool>( &self, addr: &Address, key: &[u8], f: F, ) -> bool
Tries to return whether a datastore entry exists for a given address, or gets it from a function if the datastore entry’s status is unknown.
This function is used as an optimization:
if the result can be deduced unambiguously from the LedgerChanges,
no need to dig further (for example in the FinalLedger).
§Arguments
addr: target addresskey: datastore keyf: fallback function with no arguments and returning a boolean
§Returns
- true if the ledger entry exists and the key is present in its datastore
- false if the ledger entry is absent, or if the key is not in its datastore
- f() if the existence of the ledger entry or datastore entry is unknown
sourcepub fn set_data_entry(&mut self, addr: Address, key: Vec<u8>, data: Vec<u8>)
pub fn set_data_entry(&mut self, addr: Address, key: Vec<u8>, data: Vec<u8>)
Set a datastore entry for a given address. If the address doesn’t exist, its ledger entry is created. If the datastore entry exists, its value is replaced, otherwise it is created.
§Arguments
addr: target addresskey: datastore keydata: datastore value to set
Trait Implementations§
source§impl Applicable<LedgerChanges> for LedgerChanges
impl Applicable<LedgerChanges> for LedgerChanges
source§fn apply(&mut self, changes: LedgerChanges)
fn apply(&mut self, changes: LedgerChanges)
extends the current LedgerChanges with another one
source§impl Clone for LedgerChanges
impl Clone for LedgerChanges
source§fn clone(&self) -> LedgerChanges
fn clone(&self) -> LedgerChanges
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for LedgerChanges
impl Debug for LedgerChanges
source§impl Default for LedgerChanges
impl Default for LedgerChanges
source§fn default() -> LedgerChanges
fn default() -> LedgerChanges
source§impl<'de> Deserialize<'de> for LedgerChanges
impl<'de> Deserialize<'de> for LedgerChanges
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 Deserializer<LedgerChanges> for LedgerChangesDeserializer
impl Deserializer<LedgerChanges> for LedgerChangesDeserializer
source§fn deserialize<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(
&self,
buffer: &'a [u8],
) -> IResult<&'a [u8], LedgerChanges, E>
fn deserialize<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>( &self, buffer: &'a [u8], ) -> IResult<&'a [u8], LedgerChanges, E>
§Example
use massa_serialization::{Deserializer, Serializer, DeserializeError};
use massa_ledger_exports::{LedgerEntry, LedgerChanges, LedgerChangesSerializer, LedgerChangesDeserializer};
use std::str::FromStr;
use std::collections::BTreeMap;
use massa_models::types::{SetUpdateOrDelete};
use massa_models::{amount::Amount, address::Address, bytecode::Bytecode};
let key = "hello world".as_bytes().to_vec();
let mut datastore = BTreeMap::new();
datastore.insert(key, vec![1, 2, 3]);
let balance = Amount::from_str("1").unwrap();
let bytecode = Bytecode(vec![1, 2, 3]);
let ledger_entry = LedgerEntry {
balance,
bytecode,
datastore,
};
let mut serialized = Vec::new();
let mut changes = LedgerChanges::default();
changes.0.insert(
Address::from_str("AU12dG5xP1RDEB5ocdHkymNVvvSJmUL9BgHwCksDowqmGWxfpm93x").unwrap(),
SetUpdateOrDelete::Set(ledger_entry),
);
LedgerChangesSerializer::new().serialize(&changes, &mut serialized).unwrap();
let (rest, changes_deser) = LedgerChangesDeserializer::new(255, 255, 10000, 10000).deserialize::<DeserializeError>(&serialized).unwrap();
assert!(rest.is_empty());
assert_eq!(changes, changes_deser);source§impl PartialEq for LedgerChanges
impl PartialEq for LedgerChanges
source§fn eq(&self, other: &LedgerChanges) -> bool
fn eq(&self, other: &LedgerChanges) -> bool
self and other values to be equal, and is used
by ==.source§impl Serialize for LedgerChanges
impl Serialize for LedgerChanges
source§impl Serializer<LedgerChanges> for LedgerChangesSerializer
impl Serializer<LedgerChanges> for LedgerChangesSerializer
source§fn serialize(
&self,
value: &LedgerChanges,
buffer: &mut Vec<u8>,
) -> Result<(), SerializeError>
fn serialize( &self, value: &LedgerChanges, buffer: &mut Vec<u8>, ) -> Result<(), SerializeError>
§Example
use massa_serialization::Serializer;
use massa_ledger_exports::{LedgerEntry, LedgerChanges, LedgerChangesSerializer};
use std::str::FromStr;
use massa_models::types::{SetUpdateOrDelete};
use std::collections::BTreeMap;
use massa_models::{amount::Amount, address::Address, bytecode::Bytecode};
let key = "hello world".as_bytes().to_vec();
let mut datastore = BTreeMap::new();
datastore.insert(key, vec![1, 2, 3]);
let balance = Amount::from_str("1").unwrap();
let bytecode = Bytecode(vec![1, 2, 3]);
let ledger_entry = LedgerEntry {
balance,
bytecode,
datastore,
};
let mut serialized = Vec::new();
let mut changes = LedgerChanges::default();
changes.0.insert(
Address::from_str("AU12dG5xP1RDEB5ocdHkymNVvvSJmUL9BgHwCksDowqmGWxfpm93x").unwrap(),
SetUpdateOrDelete::Set(ledger_entry),
);
LedgerChangesSerializer::new().serialize(&changes, &mut serialized).unwrap();impl Eq for LedgerChanges
impl StructuralPartialEq for LedgerChanges
Auto Trait Implementations§
impl Freeze for LedgerChanges
impl RefUnwindSafe for LedgerChanges
impl Send for LedgerChanges
impl Sync for LedgerChanges
impl Unpin for LedgerChanges
impl UnwindSafe for LedgerChanges
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.