Skip to main content

SafeTransaction

Struct SafeTransaction 

Source
pub struct SafeTransaction {
    pub to: [u8; 20],
    pub value: [u8; 32],
    pub data: Vec<u8>,
    pub operation: Operation,
    pub safe_tx_gas: [u8; 32],
    pub base_gas: [u8; 32],
    pub gas_price: [u8; 32],
    pub gas_token: [u8; 20],
    pub refund_receiver: [u8; 20],
    pub nonce: [u8; 32],
}
Expand description

A Gnosis Safe transaction for EIP-712 typed signing.

All u256 fields are stored as 32-byte big-endian arrays to avoid overflow issues and match the ABI encoding directly.

Fields§

§to: [u8; 20]

Target address of the transaction.

§value: [u8; 32]

ETH value in wei (32-byte BE uint256).

§data: Vec<u8>

Transaction calldata.

§operation: Operation

Call type: Call or DelegateCall.

§safe_tx_gas: [u8; 32]

Gas allocated for the Safe execution (after gasleft() check).

§base_gas: [u8; 32]

Gas costs not related to the Safe execution (signatures, base overhead).

§gas_price: [u8; 32]

Gas price used for the refund calculation. 0 = no refund.

§gas_token: [u8; 20]

Token address for gas payment (0x0 = ETH).

§refund_receiver: [u8; 20]

Address that receives the gas refund (0x0 = tx.origin).

§nonce: [u8; 32]

Safe nonce for replay protection.

Implementations§

Source§

impl SafeTransaction

Source

pub fn type_hash() -> [u8; 32]

The Safe’s SAFE_TX_TYPEHASH.

keccak256("SafeTx(address to,uint256 value,bytes data,uint8 operation,uint256 safeTxGas,uint256 baseGas,uint256 gasPrice,address gasToken,address refundReceiver,uint256 nonce)")

Source

pub fn struct_hash(&self) -> [u8; 32]

Compute the EIP-712 struct hash for this transaction.

keccak256(abi.encode(SAFE_TX_TYPEHASH, to, value, keccak256(data), operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, nonce))

Source

pub fn signing_hash(&self, domain_separator: &[u8; 32]) -> [u8; 32]

Compute the EIP-712 signing hash (safeTxHash).

keccak256("\x19\x01" || domainSeparator || structHash)

Source

pub fn sign( &self, signer: &EthereumSigner, domain_separator: &[u8; 32], ) -> Result<EthereumSignature, SignerError>

Sign this Safe transaction using EIP-712.

Returns an EthereumSignature that can be packed with encode_signatures.

Source

pub fn encode_exec_transaction( &self, signatures: &[EthereumSignature], ) -> Result<Vec<u8>, SignerError>

ABI-encode the execTransaction(...) calldata.

This produces the full calldata to call execTransaction on the Safe contract, ready for use in a transaction’s data field.

Trait Implementations§

Source§

impl Clone for SafeTransaction

Source§

fn clone(&self) -> SafeTransaction

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SafeTransaction

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.