pub struct Contract<Code> { /* private fields */ }
Expand description
Represents a contract that can be deployed either directly (Contract::regular
) or through a loader Contract::convert_to_loader
.
Provides the ability to calculate the ContractId
(Contract::contract_id
) without needing to deploy the contract.
This struct also manages contract code updates with configurable
s
(Contract::with_configurables
) and can automatically
load storage slots (via Contract::load_from
).
Implementations§
Source§impl Contract<Regular>
impl Contract<Regular>
pub fn with_code(self, code: Vec<u8>) -> Self
pub fn with_configurables(self, configurables: impl Into<Configurables>) -> Self
pub fn code(&self) -> Vec<u8> ⓘ
pub fn contract_id(&self) -> ContractId
pub fn code_root(&self) -> Bytes32
pub fn state_root(&self) -> Bytes32
Sourcepub fn load_from(
binary_filepath: impl AsRef<Path>,
config: LoadConfiguration,
) -> Result<Contract<Regular>>
pub fn load_from( binary_filepath: impl AsRef<Path>, config: LoadConfiguration, ) -> Result<Contract<Regular>>
Loads a contract from a binary file. Salt and storage slots are loaded as well, depending on the configuration provided.
Sourcepub fn regular(
code: Vec<u8>,
salt: Salt,
storage_slots: Vec<StorageSlot>,
) -> Contract<Regular>
pub fn regular( code: Vec<u8>, salt: Salt, storage_slots: Vec<StorageSlot>, ) -> Contract<Regular>
Creates a regular contract with the given code, salt, and storage slots.
Sourcepub async fn deploy(
self,
account: &impl Account,
tx_policies: TxPolicies,
) -> Result<Bech32ContractId>
pub async fn deploy( self, account: &impl Account, tx_policies: TxPolicies, ) -> Result<Bech32ContractId>
Deploys a compiled contract to a running node. To deploy a contract, you need an account with enough assets to pay for deployment. This account will also receive the change.
Sourcepub async fn deploy_if_not_exists(
self,
account: &impl Account,
tx_policies: TxPolicies,
) -> Result<Bech32ContractId>
pub async fn deploy_if_not_exists( self, account: &impl Account, tx_policies: TxPolicies, ) -> Result<Bech32ContractId>
Deploys a compiled contract to a running node if a contract with
the corresponding ContractId
doesn’t exist.
Sourcepub fn convert_to_loader(
self,
max_words_per_blob: usize,
) -> Result<Contract<Loader<BlobsNotUploaded>>>
pub fn convert_to_loader( self, max_words_per_blob: usize, ) -> Result<Contract<Loader<BlobsNotUploaded>>>
Converts a regular contract into a loader contract, splitting the code into blobs.
Sourcepub async fn smart_deploy(
self,
account: &impl Account,
tx_policies: TxPolicies,
max_words_per_blob: usize,
) -> Result<Bech32ContractId>
pub async fn smart_deploy( self, account: &impl Account, tx_policies: TxPolicies, max_words_per_blob: usize, ) -> Result<Bech32ContractId>
Deploys the contract either as a regular contract or as a loader contract if it exceeds the size limit.
Source§impl Contract<Loader<BlobsNotUploaded>>
impl Contract<Loader<BlobsNotUploaded>>
pub fn code(&self) -> Vec<u8> ⓘ
pub fn contract_id(&self) -> ContractId
pub fn code_root(&self) -> Bytes32
pub fn state_root(&self) -> Bytes32
Sourcepub fn loader_from_blobs(
blobs: Vec<Blob>,
salt: Salt,
storage_slots: Vec<StorageSlot>,
) -> Result<Self>
pub fn loader_from_blobs( blobs: Vec<Blob>, salt: Salt, storage_slots: Vec<StorageSlot>, ) -> Result<Self>
Creates a loader contract for the code found in blobs
. Calling deploy
on this contract
does two things:
- Uploads the code blobs.
- Deploys the loader contract.
The loader contract, when executed, will load all the given blobs into memory and delegate the call to the original contract code contained in the blobs.
pub fn blobs(&self) -> &[Blob]
pub fn blob_ids(&self) -> Vec<BlobId>
Sourcepub async fn upload_blobs(
self,
account: &impl Account,
tx_policies: TxPolicies,
) -> Result<Contract<Loader<BlobsUploaded>>>
pub async fn upload_blobs( self, account: &impl Account, tx_policies: TxPolicies, ) -> Result<Contract<Loader<BlobsUploaded>>>
Uploads the blobs associated with this contract. Calling deploy
on the result will only
deploy the loader contract.
Sourcepub async fn deploy(
self,
account: &impl Account,
tx_policies: TxPolicies,
) -> Result<Bech32ContractId>
pub async fn deploy( self, account: &impl Account, tx_policies: TxPolicies, ) -> Result<Bech32ContractId>
Deploys the loader contract after uploading the code blobs.
Sourcepub async fn deploy_if_not_exists(
self,
account: &impl Account,
tx_policies: TxPolicies,
) -> Result<Bech32ContractId>
pub async fn deploy_if_not_exists( self, account: &impl Account, tx_policies: TxPolicies, ) -> Result<Bech32ContractId>
Deploys the loader contract after uploading the code blobs, if there is no contract with this ContractId Already.
Sourcepub fn revert_to_regular(self) -> Contract<Regular>
pub fn revert_to_regular(self) -> Contract<Regular>
Reverts the contract from a loader contract back to a regular contract.
Source§impl Contract<Loader<BlobsUploaded>>
impl Contract<Loader<BlobsUploaded>>
pub fn code(&self) -> Vec<u8> ⓘ
pub fn contract_id(&self) -> ContractId
pub fn code_root(&self) -> Bytes32
pub fn state_root(&self) -> Bytes32
pub fn compute_roots(&self) -> (ContractId, Bytes32, Bytes32)
Sourcepub fn loader_from_blob_ids(
blob_ids: Vec<BlobId>,
salt: Salt,
storage_slots: Vec<StorageSlot>,
) -> Result<Self>
pub fn loader_from_blob_ids( blob_ids: Vec<BlobId>, salt: Salt, storage_slots: Vec<StorageSlot>, ) -> Result<Self>
Creates a loader contract using previously uploaded blobs.
The contract code has been uploaded in blobs with BlobId
s specified in blob_ids
.
This will create a loader contract that, when deployed and executed, will load all the specified blobs into memory and delegate the call to the code contained in the blobs.
pub fn blob_ids(&self) -> &[BlobId]
Sourcepub async fn deploy(
self,
account: &impl Account,
tx_policies: TxPolicies,
) -> Result<Bech32ContractId>
pub async fn deploy( self, account: &impl Account, tx_policies: TxPolicies, ) -> Result<Bech32ContractId>
Deploys the loader contract.
pub async fn deploy_if_not_exists( self, account: &impl Account, tx_policies: TxPolicies, ) -> Result<Bech32ContractId>
Source§impl<T> Contract<T>
impl<T> Contract<T>
pub fn salt(&self) -> Salt
pub fn with_salt(self, salt: impl Into<Salt>) -> Self
pub fn storage_slots(&self) -> &[StorageSlot]
pub fn with_storage_slots(self, storage_slots: Vec<StorageSlot>) -> Self
Trait Implementations§
impl<Code> StructuralPartialEq for Contract<Code>
Auto Trait Implementations§
impl<Code> Freeze for Contract<Code>where
Code: Freeze,
impl<Code> RefUnwindSafe for Contract<Code>where
Code: RefUnwindSafe,
impl<Code> Send for Contract<Code>where
Code: Send,
impl<Code> Sync for Contract<Code>where
Code: Sync,
impl<Code> Unpin for Contract<Code>where
Code: Unpin,
impl<Code> UnwindSafe for Contract<Code>where
Code: UnwindSafe,
Blanket Implementations§
Source§impl<T> AnyDebug for T
impl<T> AnyDebug for T
Source§fn as_any_ref(&self) -> &(dyn Any + 'static)
fn as_any_ref(&self) -> &(dyn Any + 'static)
Any
.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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<S> IteratorOverTable for S
impl<S> IteratorOverTable for S
Source§fn iter_all_keys<M>(
&self,
direction: Option<IterDirection>,
) -> BoxedIter<'_, Result<<M as Mappable>::OwnedKey, Error>>where
M: Mappable,
Self: IterableTable<M>,
fn iter_all_keys<M>(
&self,
direction: Option<IterDirection>,
) -> BoxedIter<'_, Result<<M as Mappable>::OwnedKey, Error>>where
M: Mappable,
Self: IterableTable<M>,
Source§fn iter_all_by_prefix_keys<M, P>(
&self,
prefix: Option<P>,
) -> BoxedIter<'_, Result<<M as Mappable>::OwnedKey, Error>>
fn iter_all_by_prefix_keys<M, P>( &self, prefix: Option<P>, ) -> BoxedIter<'_, Result<<M as Mappable>::OwnedKey, Error>>
Source§fn iter_all_by_start_keys<M>(
&self,
start: Option<&<M as Mappable>::Key>,
direction: Option<IterDirection>,
) -> BoxedIter<'_, Result<<M as Mappable>::OwnedKey, Error>>where
M: Mappable,
Self: IterableTable<M>,
fn iter_all_by_start_keys<M>(
&self,
start: Option<&<M as Mappable>::Key>,
direction: Option<IterDirection>,
) -> BoxedIter<'_, Result<<M as Mappable>::OwnedKey, Error>>where
M: Mappable,
Self: IterableTable<M>,
Source§fn iter_all_filtered_keys<M, P>(
&self,
prefix: Option<P>,
start: Option<&<M as Mappable>::Key>,
direction: Option<IterDirection>,
) -> BoxedIter<'_, Result<<M as Mappable>::OwnedKey, Error>>
fn iter_all_filtered_keys<M, P>( &self, prefix: Option<P>, start: Option<&<M as Mappable>::Key>, direction: Option<IterDirection>, ) -> BoxedIter<'_, Result<<M as Mappable>::OwnedKey, Error>>
Source§fn iter_all<M>(
&self,
direction: Option<IterDirection>,
) -> BoxedIter<'_, Result<(<M as Mappable>::OwnedKey, <M as Mappable>::OwnedValue), Error>>where
M: Mappable,
Self: IterableTable<M>,
fn iter_all<M>(
&self,
direction: Option<IterDirection>,
) -> BoxedIter<'_, Result<(<M as Mappable>::OwnedKey, <M as Mappable>::OwnedValue), Error>>where
M: Mappable,
Self: IterableTable<M>,
Source§fn iter_all_by_prefix<M, P>(
&self,
prefix: Option<P>,
) -> BoxedIter<'_, Result<(<M as Mappable>::OwnedKey, <M as Mappable>::OwnedValue), Error>>
fn iter_all_by_prefix<M, P>( &self, prefix: Option<P>, ) -> BoxedIter<'_, Result<(<M as Mappable>::OwnedKey, <M as Mappable>::OwnedValue), Error>>
Source§fn iter_all_by_start<M>(
&self,
start: Option<&<M as Mappable>::Key>,
direction: Option<IterDirection>,
) -> BoxedIter<'_, Result<(<M as Mappable>::OwnedKey, <M as Mappable>::OwnedValue), Error>>where
M: Mappable,
Self: IterableTable<M>,
fn iter_all_by_start<M>(
&self,
start: Option<&<M as Mappable>::Key>,
direction: Option<IterDirection>,
) -> BoxedIter<'_, Result<(<M as Mappable>::OwnedKey, <M as Mappable>::OwnedValue), Error>>where
M: Mappable,
Self: IterableTable<M>,
Source§fn iter_all_filtered<M, P>(
&self,
prefix: Option<P>,
start: Option<&<M as Mappable>::Key>,
direction: Option<IterDirection>,
) -> BoxedIter<'_, Result<(<M as Mappable>::OwnedKey, <M as Mappable>::OwnedValue), Error>>
fn iter_all_filtered<M, P>( &self, prefix: Option<P>, start: Option<&<M as Mappable>::Key>, direction: Option<IterDirection>, ) -> BoxedIter<'_, Result<(<M as Mappable>::OwnedKey, <M as Mappable>::OwnedValue), Error>>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§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 moreSource§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 moreSource§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
Source§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
Source§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.Source§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.Source§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.Source§impl<T> StorageAsMut for T
impl<T> StorageAsMut for T
fn storage<Type>(&mut self) -> StorageMut<'_, Self, Type>where
Type: Mappable,
fn storage_as_mut<Type>(&mut self) -> StorageMut<'_, Self, Type>where
Type: Mappable,
Source§impl<T> StorageAsRef for T
impl<T> StorageAsRef for T
fn storage<Type>(&self) -> StorageRef<'_, Self, Type>where
Type: Mappable,
fn storage_as_ref<Type>(&self) -> StorageRef<'_, Self, Type>where
Type: Mappable,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§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 moreSource§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 moreSource§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 moreSource§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 moreSource§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 moreSource§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 moreSource§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.