Struct noble_contracts::chain_extension::Environment [−][src]
Grants the chain extension access to its parameters and execution environment.
It uses the typestate pattern to enforce the correct usage of the parameters passed to the chain extension.
Implementations
impl<'a, 'b, E: Ext, S: State> Environment<'a, 'b, E, S> where
<E::T as SysConfig>::AccountId: UncheckedFrom<<E::T as SysConfig>::Hash> + AsRef<[u8]>,
[src]
<E::T as SysConfig>::AccountId: UncheckedFrom<<E::T as SysConfig>::Hash> + AsRef<[u8]>,
Functions that are available in every state of this type.
pub fn charge_weight(&mut self, amount: Weight) -> Result<()>
[src]
Charge the passed amount
of weight from the overall limit.
It returns Ok
when there the remaining weight budget is larger than the passed
weight
. It returns Err
otherwise. In this case the chain extension should
abort the execution and pass through the error.
Note
Weight is synonymous with gas in tetcore.
pub fn ext(&mut self) -> &mut E
[src]
Grants access to the execution environment of the current contract call.
Consult the functions on the returned type before re-implementing those functions.
impl<'a, 'b, E: Ext> Environment<'a, 'b, E, Init>
[src]
Functions that are only available in the initial state of this type.
Those are the functions that determine how the arguments to the chain extensions should be consumed.
pub fn only_in(self) -> Environment<'a, 'b, E, OnlyIn>
[src]
Use all arguments as integer values.
pub fn prim_in_buf_out(self) -> Environment<'a, 'b, E, PrimInBufOut>
[src]
Use input arguments as integer and output arguments as pointer to a buffer.
pub fn buf_in_buf_out(self) -> Environment<'a, 'b, E, BufInBufOut>
[src]
Use input and output arguments as pointers to a buffer.
impl<'a, 'b, E: Ext, S: PrimIn> Environment<'a, 'b, E, S>
[src]
Functions to use the input arguments as integers.
pub fn val0(&self) -> u32
[src]
The input_ptr
argument.
pub fn val1(&self) -> u32
[src]
The input_len
argument.
impl<'a, 'b, E: Ext, S: PrimOut> Environment<'a, 'b, E, S>
[src]
Functions to use the output arguments as integers.
pub fn val2(&self) -> u32
[src]
The output_ptr
argument.
pub fn val3(&self) -> u32
[src]
The output_len_ptr
argument.
impl<'a, 'b, E: Ext, S: BufIn> Environment<'a, 'b, E, S> where
<E::T as SysConfig>::AccountId: UncheckedFrom<<E::T as SysConfig>::Hash> + AsRef<[u8]>,
[src]
<E::T as SysConfig>::AccountId: UncheckedFrom<<E::T as SysConfig>::Hash> + AsRef<[u8]>,
Functions to use the input arguments as pointer to a buffer.
pub fn read(&self, max_len: u32) -> Result<Vec<u8>>
[src]
Reads min(max_len, in_len)
from contract memory.
This does not charge any weight. The caller must make sure that the an
appropriate amount of weight is charged before reading from contract memory.
The reason for that is that usually the costs for reading data and processing
said data cannot be separated in a benchmark. Therefore a chain extension would
charge the overall costs either using max_len
(worst case approximation) or using
in_len()
.
pub fn read_into(&self, buffer: &mut &mut [u8]) -> Result<()>
[src]
Reads `min(buffer.len(), in_len) from contract memory.
This takes a mutable pointer to a buffer fills it with data and shrinks it to
the size of the actual data. Apart from supporting pre-allocated buffers it is
equivalent to to read()
.
pub fn read_as<T: Decode>(&mut self) -> Result<T>
[src]
Reads in_len
from contract memory and scale decodes it.
This function is secure and recommended for all input types of fixed size
as long as the cost of reading the memory is included in the overall already charged
weight of the chain extension. This should usually be the case when fixed input types
are used. Non fixed size types (like everything using Vec
) usually need to use
in_len()
in order to properly charge the necessary weight.
pub fn in_len(&self) -> u32
[src]
The length of the input as passed in as input_len
.
A chain extension would use this value to calculate the dynamic part of its
weight. For example a chain extension that calculates the hash of some passed in
bytes would use in_len
to charge the costs of hashing that amount of bytes.
This also subsumes the act of copying those bytes as a benchmarks measures both.
impl<'a, 'b, E: Ext, S: BufOut> Environment<'a, 'b, E, S> where
<E::T as SysConfig>::AccountId: UncheckedFrom<<E::T as SysConfig>::Hash> + AsRef<[u8]>,
[src]
<E::T as SysConfig>::AccountId: UncheckedFrom<<E::T as SysConfig>::Hash> + AsRef<[u8]>,
Functions to use the output arguments as pointer to a buffer.
pub fn write(
&mut self,
buffer: &[u8],
allow_skip: bool,
weight_per_byte: Option<Weight>
) -> Result<()>
[src]
&mut self,
buffer: &[u8],
allow_skip: bool,
weight_per_byte: Option<Weight>
) -> Result<()>
Write the supplied buffer to contract memory.
If the contract supplied buffer is smaller than the passed buffer
an Err
is returned.
If allow_skip
is set to true the contract is allowed to skip the copying of the buffer
by supplying the guard value of u32::max_value()
as out_ptr
. The
weight_per_byte
is only charged when the write actually happens and is not skipped or
failed due to a too small output buffer.
Auto Trait Implementations
impl<'a, 'b, E, S> !RefUnwindSafe for Environment<'a, 'b, E, S>
impl<'a, 'b, E, S> !Send for Environment<'a, 'b, E, S>
impl<'a, 'b, E, S> !Sync for Environment<'a, 'b, E, S>
impl<'a, 'b, E, S> Unpin for Environment<'a, 'b, E, S> where
S: Unpin,
'b: 'a,
S: Unpin,
'b: 'a,
impl<'a, 'b, E, S> !UnwindSafe for Environment<'a, 'b, E, S>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> CheckedConversion for T
[src]
pub fn checked_from<T>(t: T) -> Option<Self> where
Self: TryFrom<T>,
[src]
Self: TryFrom<T>,
pub fn checked_into<T>(self) -> Option<T> where
Self: TryInto<T>,
[src]
Self: TryInto<T>,
impl<T> Downcast for T where
T: Any,
T: Any,
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn as_any(&self) -> &(dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> IsType<T> for T
[src]
pub fn from_ref(t: &T) -> &T
[src]
pub fn into_ref(&self) -> &T
[src]
pub fn from_mut(t: &mut T) -> &mut T
[src]
pub fn into_mut(&mut self) -> &mut T
[src]
impl<T, Outer> IsWrappedBy<Outer> for T where
T: From<Outer>,
Outer: AsRef<T> + AsMut<T> + From<T>,
[src]
T: From<Outer>,
Outer: AsRef<T> + AsMut<T> + From<T>,
pub fn from_ref(outer: &Outer) -> &T
[src]
Get a reference to the inner from the outer.
pub fn from_mut(outer: &mut Outer) -> &mut T
[src]
Get a mutable reference to the inner from the outer.
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> SaturatedConversion for T
pub fn saturated_from<T>(t: T) -> Self where
Self: UniqueSaturatedFrom<T>,
Self: UniqueSaturatedFrom<T>,
pub fn saturated_into<T>(self) -> T where
Self: UniqueSaturatedInto<T>,
Self: UniqueSaturatedInto<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<S, T> UncheckedInto<T> for S where
T: UncheckedFrom<S>,
[src]
T: UncheckedFrom<S>,
pub fn unchecked_into(self) -> T
[src]
impl<T, S> UniqueSaturatedInto<T> for S where
T: Bounded,
S: TryInto<T>,
T: Bounded,
S: TryInto<T>,
pub fn unique_saturated_into(self) -> T
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,