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 toRuntimeArgs::new.target: Specifies the target of the transaction, which can be native or other custom targets. Defaults toTransactionTarget::Native.scheduling: Determines the scheduling mechanism of the transaction, e.g., standard or immediate, and is initialized toTransactionScheduling::Standard.entry_point: Defines the transaction’s entry point, such as transfer or another defined action. Defaults toTransactionEntryPoint::Transfer.chain_name: The name of the blockchain where the transaction will be executed. Initially set toNoneand must be provided before building the transaction.
§Time-Related Fields
timestamp: The timestamp at which the transaction is created. It is either set to the current time usingTimestamp::noworTimestamp::zerowithout thestd-fs-iofeature.ttl: Time-to-live for the transaction, specified as aTimeDiff, representing how long the transaction is valid for execution. Defaults toSelf::DEFAULT_TTL.
§Pricing and Initiator Fields
pricing_mode: Specifies the pricing mode to use for transaction execution (e.g., fixed or dynamic). Defaults toSelf::DEFAULT_PRICING_MODE.initiator_addr: The address of the initiator who creates and signs the transaction. Initially set toNoneand 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
stdfeature enabled, it holds an owned secret key (Option<SecretKey>).
- In normal mode, it holds a reference to the secret key (
§Phantom Data
_phantom_data: Ensures the correct lifetime'ais respected for the builder, helping with proper borrowing and memory safety.
Implementations§
Source§impl<'a> TransactionV1Builder<'a>
impl<'a> TransactionV1Builder<'a>
Sourcepub const DEFAULT_TTL: TimeDiff
pub const DEFAULT_TTL: TimeDiff
The default time-to-live for transactions, i.e. 30 minutes.
Sourcepub const DEFAULT_PRICING_MODE: PricingMode
pub const DEFAULT_PRICING_MODE: PricingMode
The default pricing mode for v1 transactions, ie FIXED cost.
Sourcepub const DEFAULT_SCHEDULING: TransactionScheduling = TransactionScheduling::Standard
pub const DEFAULT_SCHEDULING: TransactionScheduling = TransactionScheduling::Standard
The default scheduling for transactions, i.e. Standard.
Sourcepub fn new_transfer<A: Into<U512>, T: Into<TransferTarget>>(
amount: A,
maybe_source: Option<URef>,
target: T,
maybe_id: Option<u64>,
) -> Result<Self, CLValueError>
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.
Sourcepub 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>
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.
Sourcepub fn new_withdraw_bid<A: Into<U512>>(
public_key: PublicKey,
amount: A,
) -> Result<Self, CLValueError>
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.
Sourcepub fn new_delegate<A: Into<U512>>(
delegator: PublicKey,
validator: PublicKey,
amount: A,
) -> Result<Self, CLValueError>
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.
Sourcepub fn new_undelegate<A: Into<U512>>(
delegator: PublicKey,
validator: PublicKey,
amount: A,
) -> Result<Self, CLValueError>
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.
Sourcepub fn new_redelegate<A: Into<U512>>(
delegator: PublicKey,
validator: PublicKey,
amount: A,
new_validator: PublicKey,
) -> Result<Self, CLValueError>
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.
Sourcepub fn new_activate_bid(validator: PublicKey) -> Result<Self, CLValueError>
pub fn new_activate_bid(validator: PublicKey) -> Result<Self, CLValueError>
Returns a new TransactionV1Builder suitable for building a native activate_bid
transaction.
Sourcepub fn new_change_bid_public_key(
public_key: PublicKey,
new_public_key: PublicKey,
) -> Result<Self, CLValueError>
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.
Sourcepub fn new_add_reservations(
reservations: Vec<Reservation>,
) -> Result<Self, CLValueError>
pub fn new_add_reservations( reservations: Vec<Reservation>, ) -> Result<Self, CLValueError>
Returns a new TransactionV1Builder suitable for building a native add_reservations
transaction.
Sourcepub fn new_cancel_reservations(
validator: PublicKey,
delegators: Vec<DelegatorKind>,
) -> Result<Self, CLValueError>
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.
Sourcepub fn new_targeting_invocable_entity<E: Into<String>>(
hash: AddressableEntityHash,
entry_point: E,
runtime: TransactionRuntimeParams,
) -> Self
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.
Sourcepub fn new_targeting_invocable_entity_via_alias<A: Into<String>, E: Into<String>>(
alias: A,
entry_point: E,
runtime: TransactionRuntimeParams,
) -> Self
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.
Sourcepub fn new_targeting_package<E: Into<String>>(
hash: PackageHash,
version: Option<EntityVersion>,
entry_point: E,
runtime: TransactionRuntimeParams,
) -> Self
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.
Sourcepub fn new_targeting_package_with_version_key<E: Into<String>>(
hash: PackageHash,
version: Option<EntityVersionKey>,
entry_point: E,
runtime: TransactionRuntimeParams,
) -> Self
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.
Sourcepub fn new_targeting_package_via_alias<A: Into<String>, E: Into<String>>(
alias: A,
version: Option<EntityVersion>,
entry_point: E,
runtime: TransactionRuntimeParams,
) -> Self
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.
Sourcepub 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
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.
Sourcepub fn new_session(
is_install_upgrade: bool,
module_bytes: Bytes,
runtime: TransactionRuntimeParams,
) -> Self
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.
Sourcepub fn with_chain_name<C: Into<String>>(self, chain_name: C) -> Self
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.
Sourcepub fn with_timestamp(self, timestamp: Timestamp) -> Self
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.
Sourcepub fn with_ttl(self, ttl: TimeDiff) -> Self
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.
Sourcepub fn with_pricing_mode(self, pricing_mode: PricingMode) -> Self
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.
Sourcepub fn with_initiator_addr<I: Into<InitiatorAddr>>(
self,
initiator_addr: I,
) -> Self
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.
Sourcepub fn with_secret_key(self, secret_key: &'a SecretKey) -> Self
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.
Sourcepub fn with_runtime_args(self, args: RuntimeArgs) -> Self
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].
Sourcepub fn with_chunked_args(self, args: Bytes) -> Self
pub fn with_chunked_args(self, args: Bytes) -> Self
Sets the runtime args in the transaction.
Sourcepub fn with_entry_point(self, entry_point: TransactionEntryPoint) -> Self
pub fn with_entry_point(self, entry_point: TransactionEntryPoint) -> Self
Sets the entry point for the transaction.
Sourcepub fn build(self) -> Result<TransactionV1, TransactionV1BuilderError>
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§
Auto Trait Implementations§
impl<'a> Freeze for TransactionV1Builder<'a>
impl<'a> RefUnwindSafe for TransactionV1Builder<'a>
impl<'a> Send for TransactionV1Builder<'a>
impl<'a> Sync for TransactionV1Builder<'a>
impl<'a> Unpin for TransactionV1Builder<'a>
impl<'a> UnwindSafe for TransactionV1Builder<'a>
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> 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 more