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

Embed TxEnvelope into rpc-types-eth::Transaction #1460

Merged
merged 25 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d77a265
refactor: embed TxEnvelope into rpc Transaction
prestwich Oct 13, 2024
ca2232b
refactor: bytes
prestwich Oct 13, 2024
1ff7e61
feat: AnyTxEnvelope and AnyTypedTransaction
prestwich Oct 13, 2024
e0b53c5
fix: impl transaction
prestwich Oct 13, 2024
867e3f0
feat: deser memoization
prestwich Oct 13, 2024
6fd788b
fix: serde when tag is missing
prestwich Oct 13, 2024
85777e4
fix: CI
prestwich Oct 13, 2024
2b2c634
feat: asref bound for transaction response
prestwich Oct 13, 2024
d1b1993
doc: more of them for anynetwork
prestwich Oct 14, 2024
8ea0a4d
doc: fix link
prestwich Oct 14, 2024
045383e
fix: incorrect rename
prestwich Oct 16, 2024
74c9d97
chore: delete unused variants of ConversionError
prestwich Oct 16, 2024
81fb96b
fix: trie_hash for anytxenvelope
prestwich Oct 28, 2024
96f88a7
fix: trie_hash on encodable2718 for envelope
prestwich Oct 28, 2024
e4f2d3f
fix: clippy
prestwich Oct 28, 2024
342ee88
refactor: make encoding panic
prestwich Oct 29, 2024
3304b2c
chore: remove commented code
prestwich Oct 29, 2024
f4660c0
cleanup: misc use of deser_by_key
prestwich Oct 29, 2024
914ef71
fix: hash in anytx, generic default on block
prestwich Oct 31, 2024
ee2deec
fix: make Unknown variants their own types
prestwich Oct 31, 2024
bc158e1
fix: flattens
prestwich Oct 31, 2024
156d7d9
refactor: break out more files
prestwich Oct 31, 2024
3a199d1
lint: clippy
prestwich Oct 31, 2024
a600b06
fix: doclinks
prestwich Oct 31, 2024
5978390
Update crates/network/Cargo.toml
klkvr Oct 31, 2024
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
26 changes: 26 additions & 0 deletions crates/consensus/src/transaction/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,16 @@ impl Encodable2718 for TxEnvelope {
}
}
}

fn trie_hash(&self) -> B256 {
match self {
Self::Legacy(tx) => *tx.hash(),
Self::Eip2930(tx) => *tx.hash(),
Self::Eip1559(tx) => *tx.hash(),
Self::Eip4844(tx) => *tx.hash(),
Self::Eip7702(tx) => *tx.hash(),
}
}
}

impl Transaction for TxEnvelope {
Expand Down Expand Up @@ -1000,6 +1010,7 @@ mod tests {
let tx_envelope: TxEnvelope = tx.into_signed(signature).into();

let serialized = serde_json::to_string(&tx_envelope).unwrap();

let deserialized: TxEnvelope = serde_json::from_str(&serialized).unwrap();

assert_eq!(tx_envelope, deserialized);
Expand Down Expand Up @@ -1124,4 +1135,19 @@ mod tests {
};
test_serde_roundtrip(tx);
}

#[test]
#[cfg(feature = "serde")]
fn serde_tx_from_contract_call() {
let rpc_tx = r#"{"hash":"0x018b2331d461a4aeedf6a1f9cc37463377578244e6a35216057a8370714e798f","nonce":"0x1","blockHash":"0x3ca295f1dcaf8ac073c543dc0eccf18859f411206df181731e374e9917252931","blockNumber":"0x2","transactionIndex":"0x0","from":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266","to":"0x5fbdb2315678afecb367f032d93f642f64180aa3","value":"0x0","gasPrice":"0x3a29f0f8","gas":"0x1c9c380","maxFeePerGas":"0xba43b7400","maxPriorityFeePerGas":"0x5f5e100","input":"0xd09de08a","r":"0xd309309a59a49021281cb6bb41d164c96eab4e50f0c1bd24c03ca336e7bc2bb7","s":"0x28a7f089143d0a1355ebeb2a1b9f0e5ad9eca4303021c1400d61bc23c9ac5319","v":"0x0","yParity":"0x0","chainId":"0x7a69","accessList":[],"type":"0x2"}"#;

let te = serde_json::from_str::<TxEnvelope>(rpc_tx).unwrap();

assert_eq!(
*te.tx_hash(),
alloy_primitives::b256!(
"018b2331d461a4aeedf6a1f9cc37463377578244e6a35216057a8370714e798f"
)
);
}
}
1 change: 1 addition & 0 deletions crates/contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ thiserror.workspace = true
alloy-pubsub = { workspace = true, optional = true }

[dev-dependencies]
alloy-consensus.workspace = true
alloy-rpc-client = { workspace = true, features = ["pubsub", "ws"] }
alloy-transport-http.workspace = true
alloy-node-bindings.workspace = true
Expand Down
5 changes: 3 additions & 2 deletions crates/contract/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ impl<T, P, D: CallDecoder, N: Network> std::fmt::Debug for CallBuilder<T, P, D,
#[cfg(test)]
mod tests {
use super::*;
use alloy_consensus::Transaction;
use alloy_primitives::{address, b256, bytes, hex, utils::parse_units, B256};
use alloy_provider::{
layers::AnvilProvider, Provider, ProviderBuilder, RootProvider, WalletProvider,
Expand Down Expand Up @@ -781,13 +782,13 @@ mod tests {
.expect("failed to fetch tx")
.expect("tx not included");
assert_eq!(
transaction.max_fee_per_gas.expect("max_fee_per_gas of the transaction should be set"),
transaction.max_fee_per_gas(),
max_fee_per_gas.to(),
"max_fee_per_gas of the transaction should be set to the right value"
);
assert_eq!(
transaction
.max_priority_fee_per_gas
.max_priority_fee_per_gas()
.expect("max_priority_fee_per_gas of the transaction should be set"),
max_priority_fee_per_gas.to(),
"max_priority_fee_per_gas of the transaction should be set to the right value"
Expand Down
2 changes: 2 additions & 0 deletions crates/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ alloy-sol-types.workspace = true
auto_impl.workspace = true
async-trait.workspace = true
futures-utils-wasm.workspace = true
serde.workspace = true
serde_json = "1.0.128"
klkvr marked this conversation as resolved.
Show resolved Hide resolved
thiserror.workspace = true

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/network/src/any/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl TransactionBuilder<AnyNetwork> for WithOtherFields<TransactionRequest> {
)
.into_unbuilt(self));
}
Ok(self.inner.build_typed_tx().expect("checked by missing_keys"))
Ok(self.inner.build_typed_tx().expect("checked by missing_keys").into())
}

async fn build<W: NetworkWallet<AnyNetwork>>(
Expand Down
Loading