Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: alloy-dyn-contract #149

Merged
merged 18 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: add some builders to CallRequest
  • Loading branch information
onbjerg committed Jan 25, 2024
commit f220ca51cc8eb32c247dc41594b6e19d81744304
29 changes: 14 additions & 15 deletions crates/alloy-dyn-contract/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ impl<P> CallBuilder<P> {
}

/// Sets the `from` field in the transaction to the provided value
pub const fn from(mut self, from: Address) -> Self {
self.request.from = Some(from);
pub fn from(mut self, from: Address) -> Self {
self.request = self.request.from(from);
self
}

Expand All @@ -50,35 +50,34 @@ impl<P> CallBuilder<P> {
}

/// Sets the `gas` field in the transaction to the provided value
pub const fn gas(mut self, gas: U256) -> Self {
self.request.gas = Some(gas);
pub fn gas(mut self, gas: U256) -> Self {
self.request = self.request.gas(gas);
self
}

/// Sets the `gas_price` field in the transaction to the provided value
/// If the internal transaction is an EIP-1559 one, then it sets both
/// `max_fee_per_gas` and `max_priority_fee_per_gas` to the same value
pub const fn gas_price(mut self, gas_price: U256) -> Self {
// todo: Add EIP-1559 support
self.request.gas_price = Some(gas_price);
pub fn gas_price(mut self, gas_price: U256) -> Self {
self.request = self.request.gas_price(gas_price);
self
}

/// Sets the `value` field in the transaction to the provided value
pub const fn value(mut self, value: U256) -> Self {
self.request.value = Some(value);
pub fn value(mut self, value: U256) -> Self {
self.request = self.request.value(value);
self
}

/// Sets the `block` field for sending the tx to the chain
pub const fn block(mut self, block: BlockId) -> Self {
self.block = Some(block);
/// Sets the `nonce` field in the transaction to the provided value
pub fn nonce(mut self, nonce: U64) -> Self {
self.request = self.request.nonce(nonce);
self
}

/// Sets the `nonce` field in the transaction to the provided value
pub const fn nonce(mut self, nonce: U64) -> Self {
self.request.nonce = Some(nonce);
/// Sets the `block` field for sending the tx to the chain
pub const fn block(mut self, block: BlockId) -> Self {
self.block = Some(block);
self
}

Expand Down
34 changes: 34 additions & 0 deletions crates/rpc-types/src/eth/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,40 @@ impl CallRequest {
pub fn has_empty_blob_hashes(&self) -> bool {
self.blob_versioned_hashes.as_ref().map(|blobs| blobs.is_empty()).unwrap_or(false)
}

/// Sets the `from` field in the call to the provided address
#[inline]
pub const fn from(mut self, from: Address) -> Self {
self.from = Some(from);
self
}

/// Sets the `gas` field in the transaction to the provided value
pub const fn gas(mut self, gas: U256) -> Self {
self.gas = Some(gas);
self
}

/// Sets the `gas_price` field in the transaction to the provided value
/// If the internal transaction is an EIP-1559 one, then it sets both
/// `max_fee_per_gas` and `max_priority_fee_per_gas` to the same value
pub const fn gas_price(mut self, gas_price: U256) -> Self {
// todo: Add EIP-1559 support
self.gas_price = Some(gas_price);
self
}

/// Sets the `value` field in the transaction to the provided value
pub const fn value(mut self, value: U256) -> Self {
self.value = Some(value);
self
}

/// Sets the `nonce` field in the transaction to the provided value
pub const fn nonce(mut self, nonce: U64) -> Self {
self.nonce = Some(nonce);
self
}
}

/// Helper type that supports both `data` and `input` fields that map to transaction input data.
Expand Down