-
Notifications
You must be signed in to change notification settings - Fork 249
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: implement sign_transaction on Trezor #100
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
mod common; | ||
pub use common::TxKind; | ||
|
||
mod eip1559; | ||
pub use eip1559::TxEip1559; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
use crate::Receipt; | ||
use alloy_primitives::{Bytes, ChainId, Signature, B256, U256}; | ||
use alloy_rlp::{BufMut, Decodable, Encodable}; | ||
use alloy_rlp::{BufMut, Encodable}; | ||
|
||
mod common; | ||
pub use common::TxKind; | ||
|
||
mod signed; | ||
pub use signed::Signed; | ||
|
||
/// Represents a minimal EVM transaction. | ||
pub trait Transaction: Encodable + Decodable + Send + Sync + 'static { | ||
pub trait Transaction: std::any::Any + Encodable + Send + Sync + 'static { | ||
/// The signature type for this transaction. | ||
/// | ||
/// This is usually [`alloy_primitives::Signature`], however, it may be different for future | ||
/// EIP-2718 transaction types, or in other networks. For example, in Optimism, the deposit | ||
/// transaction signature is the unit type `()`. | ||
type Signature; | ||
|
||
/// The receipt type for this transaction. | ||
type Receipt: Receipt; | ||
|
||
/// Convert to a signed transaction by adding a signature and computing the | ||
Comment on lines
-17
to
-19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we'll bring this back per Prestwich thinking right? in that case let's leave this commented out instead of removing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know honestly, should receipts be tied to a specific transaction? Keeping this will make it impossible to have signers use dyn transaction because know that also has to be specified |
||
/// hash. | ||
fn into_signed(self, signature: Signature) -> Signed<Self, Self::Signature> | ||
|
@@ -45,6 +44,11 @@ pub trait Transaction: Encodable + Decodable + Send + Sync + 'static { | |
/// Set `data`. | ||
fn set_input(&mut self, data: Bytes); | ||
|
||
/// Get `to`. | ||
fn to(&self) -> TxKind; | ||
/// Set `to`. | ||
fn set_to(&mut self, to: TxKind); | ||
|
||
/// Get `value`. | ||
fn value(&self) -> U256; | ||
/// Set `value`. | ||
|
@@ -64,6 +68,23 @@ pub trait Transaction: Encodable + Decodable + Send + Sync + 'static { | |
fn gas_limit(&self) -> u64; | ||
/// Set `gas_limit`. | ||
fn set_gas_limit(&mut self, limit: u64); | ||
|
||
/// Get `gas_price`. | ||
fn gas_price(&self) -> Option<U256>; | ||
/// Set `gas_price`. | ||
fn set_gas_price(&mut self, price: U256); | ||
} | ||
|
||
// TODO: Remove in favor of dyn trait upcasting (1.76+) | ||
#[doc(hidden)] | ||
impl<S: 'static> dyn Transaction<Signature = S> { | ||
pub fn __downcast_ref<T: std::any::Any>(&self) -> Option<&T> { | ||
if std::any::Any::type_id(self) == std::any::TypeId::of::<T>() { | ||
unsafe { Some(&*(self as *const _ as *const T)) } | ||
} else { | ||
None | ||
} | ||
} | ||
} | ||
|
||
/// Captures getters and setters common across EIP-1559 transactions across all networks | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bleh do we need to explicitly declare the Any here? I guess it'll be always there for most types we impl transaction for, would add a note in the code on why it's needed