TransactionV1Builder

Struct TransactionV1Builder 

Source
pub struct TransactionV1Builder<'a> { /* private fields */ }
Expand description

A builder for constructing TransactionV1 instances with various configuration options.

The TransactionV1Builder provides a flexible API for specifying different transaction parameters like the target, scheduling, entry point, and signing options. Once all the required fields are set, the transaction can be built by calling build.

§Fields

  • args: Arguments passed to the transaction’s runtime, initialized to RuntimeArgs::new.
  • target: Specifies the target of the transaction, which can be native or other custom targets. Defaults to TransactionTarget::Native.
  • scheduling: Determines the scheduling mechanism of the transaction, e.g., standard or immediate, and is initialized to TransactionScheduling::Standard.
  • entry_point: Defines the transaction’s entry point, such as transfer or another defined action. Defaults to TransactionEntryPoint::Transfer.
  • chain_name: The name of the blockchain where the transaction will be executed. Initially set to None and must be provided before building the transaction.
  • timestamp: The timestamp at which the transaction is created. It is either set to the current time using Timestamp::now or Timestamp::zero without the std-fs-io feature.
  • ttl: Time-to-live for the transaction, specified as a TimeDiff, representing how long the transaction is valid for execution. Defaults to Self::DEFAULT_TTL.

§Pricing and Initiator Fields

  • pricing_mode: Specifies the pricing mode to use for transaction execution (e.g., fixed or dynamic). Defaults to Self::DEFAULT_PRICING_MODE.
  • initiator_addr: The address of the initiator who creates and signs the transaction. Initially set to None and must be set before building.

§Signing Fields

  • secret_key: The secret key used to sign the transaction. This field is conditional based on the compilation environment:
    • In normal mode, it holds a reference to the secret key (Option<&'a SecretKey>).
    • In testing mode or with the std feature enabled, it holds an owned secret key (Option<SecretKey>).

§Phantom Data

  • _phantom_data: Ensures the correct lifetime 'a is respected for the builder, helping with proper borrowing and memory safety.

Implementations§

Source§

impl<'a> TransactionV1Builder<'a>

Source

pub const DEFAULT_TTL: TimeDiff

The default time-to-live for transactions, i.e. 30 minutes.

Source

pub const DEFAULT_PRICING_MODE: PricingMode

The default pricing mode for v1 transactions, ie FIXED cost.

Source

pub const DEFAULT_SCHEDULING: TransactionScheduling = TransactionScheduling::Standard

The default scheduling for transactions, i.e. Standard.

Source

pub fn new_transfer<A: Into<U512>, T: Into<TransferTarget>>( amount: A, maybe_source: Option<URef>, target: T, maybe_id: Option<u64>, ) -> Result<Self, CLValueError>

Returns a new TransactionV1Builder suitable for building a native transfer transaction.

Source

pub fn new_add_bid<A: Into<U512>>( public_key: PublicKey, delegation_rate: u8, amount: A, minimum_delegation_amount: Option<u64>, maximum_delegation_amount: Option<u64>, reserved_slots: Option<u32>, ) -> Result<Self, CLValueError>

Returns a new TransactionV1Builder suitable for building a native add_bid transaction.

Source

pub fn new_withdraw_bid<A: Into<U512>>( public_key: PublicKey, amount: A, ) -> Result<Self, CLValueError>

Returns a new TransactionV1Builder suitable for building a native withdraw_bid transaction.

Source

pub fn new_delegate<A: Into<U512>>( delegator: PublicKey, validator: PublicKey, amount: A, ) -> Result<Self, CLValueError>

Returns a new TransactionV1Builder suitable for building a native delegate transaction.

Source

pub fn new_undelegate<A: Into<U512>>( delegator: PublicKey, validator: PublicKey, amount: A, ) -> Result<Self, CLValueError>

Returns a new TransactionV1Builder suitable for building a native undelegate transaction.

Source

pub fn new_redelegate<A: Into<U512>>( delegator: PublicKey, validator: PublicKey, amount: A, new_validator: PublicKey, ) -> Result<Self, CLValueError>

Returns a new TransactionV1Builder suitable for building a native redelegate transaction.

Source

pub fn new_activate_bid(validator: PublicKey) -> Result<Self, CLValueError>

Returns a new TransactionV1Builder suitable for building a native activate_bid transaction.

Source

pub fn new_change_bid_public_key( public_key: PublicKey, new_public_key: PublicKey, ) -> Result<Self, CLValueError>

Returns a new TransactionV1Builder suitable for building a native change_bid_public_key transaction.

Source

pub fn new_add_reservations( reservations: Vec<Reservation>, ) -> Result<Self, CLValueError>

Returns a new TransactionV1Builder suitable for building a native add_reservations transaction.

Source

pub fn new_cancel_reservations( validator: PublicKey, delegators: Vec<DelegatorKind>, ) -> Result<Self, CLValueError>

Returns a new TransactionV1Builder suitable for building a native cancel_reservations transaction.

Source

pub fn new_targeting_invocable_entity<E: Into<String>>( hash: AddressableEntityHash, entry_point: E, runtime: TransactionRuntimeParams, ) -> Self

Returns a new TransactionV1Builder suitable for building a transaction targeting a stored entity.

Source

pub fn new_targeting_invocable_entity_via_alias<A: Into<String>, E: Into<String>>( alias: A, entry_point: E, runtime: TransactionRuntimeParams, ) -> Self

Returns a new TransactionV1Builder suitable for building a transaction targeting a stored entity via its alias.

Source

pub fn new_targeting_package<E: Into<String>>( hash: PackageHash, version: Option<EntityVersion>, entry_point: E, runtime: TransactionRuntimeParams, ) -> Self

Returns a new TransactionV1Builder suitable for building a transaction targeting a package.

Source

pub fn new_targeting_package_with_version_key<E: Into<String>>( hash: PackageHash, version: Option<EntityVersionKey>, entry_point: E, runtime: TransactionRuntimeParams, ) -> Self

Returns a new TransactionV1Builder suitable for building a transaction targeting a package.

Source

pub fn new_targeting_package_via_alias<A: Into<String>, E: Into<String>>( alias: A, version: Option<EntityVersion>, entry_point: E, runtime: TransactionRuntimeParams, ) -> Self

Returns a new TransactionV1Builder suitable for building a transaction targeting a package via its alias.

Source

pub fn new_targeting_package_via_alias_with_version_key<A: Into<String>, E: Into<String>>( alias: A, version: Option<EntityVersionKey>, entry_point: E, runtime: TransactionRuntimeParams, ) -> Self

Returns a new TransactionV1Builder suitable for building a transaction targeting a package via its alias.

Source

pub fn new_session( is_install_upgrade: bool, module_bytes: Bytes, runtime: TransactionRuntimeParams, ) -> Self

Returns a new TransactionV1Builder suitable for building a transaction for running session logic, i.e. compiled Wasm.

Source

pub fn with_chain_name<C: Into<String>>(self, chain_name: C) -> Self

Sets the chain_name in the transaction.

Must be provided or building will fail.

Source

pub fn with_timestamp(self, timestamp: Timestamp) -> Self

Sets the timestamp in the transaction.

If not provided, the timestamp will be set to the time when the builder was constructed.

Source

pub fn with_ttl(self, ttl: TimeDiff) -> Self

Sets the ttl (time-to-live) in the transaction.

If not provided, the ttl will be set to Self::DEFAULT_TTL.

Source

pub fn with_pricing_mode(self, pricing_mode: PricingMode) -> Self

Sets the pricing_mode in the transaction.

If not provided, the pricing mode will be set to Self::DEFAULT_PRICING_MODE.

Source

pub fn with_initiator_addr<I: Into<InitiatorAddr>>( self, initiator_addr: I, ) -> Self

Sets the initiator_addr in the transaction.

If not provided, the public key derived from the secret key used in the builder will be used as the InitiatorAddr::PublicKey in the transaction.

Source

pub fn with_secret_key(self, secret_key: &'a SecretKey) -> Self

Sets the secret key used to sign the transaction on calling build.

If not provided, the transaction can still be built, but will be unsigned and will be invalid until subsequently signed.

Source

pub fn with_runtime_args(self, args: RuntimeArgs) -> Self

Sets the runtime args in the transaction.

NOTE: this overwrites any existing runtime args. To append to existing args, use [TransactionV1Builder::with_runtime_arg].

Source

pub fn with_chunked_args(self, args: Bytes) -> Self

Sets the runtime args in the transaction.

Source

pub fn with_entry_point(self, entry_point: TransactionEntryPoint) -> Self

Sets the entry point for the transaction.

Source

pub fn build(self) -> Result<TransactionV1, TransactionV1BuilderError>

Returns the new transaction, or an error if non-defaulted fields were not set.

For more info, see the TransactionBuilder documentation.

Trait Implementations§

Source§

impl<'a> Debug for TransactionV1Builder<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,