mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(db): transaction value type (#175)
This commit is contained in:
@ -53,7 +53,7 @@ impl ScaleValue for Vec<u8> {}
|
||||
impl sealed::Sealed for Vec<u8> {}
|
||||
|
||||
impl_scale!(U256, H256, H160);
|
||||
impl_scale!(Header, Account, Log, Receipt, TxType, StorageEntry);
|
||||
impl_scale!(Header, Account, Log, Receipt, TxType, StorageEntry, TransactionSigned);
|
||||
impl_scale!(AccountBeforeTx);
|
||||
|
||||
impl_scale_value!(u8, u32, u16, u64);
|
||||
|
||||
@ -9,8 +9,8 @@ use crate::db::{
|
||||
DupSort,
|
||||
};
|
||||
use reth_primitives::{
|
||||
Account, Address, BlockHash, BlockNumber, Header, IntegerList, Receipt, StorageEntry, TxNumber,
|
||||
H256,
|
||||
Account, Address, BlockHash, BlockNumber, Header, IntegerList, Receipt, StorageEntry,
|
||||
TransactionSigned, TxNumber, H256,
|
||||
};
|
||||
|
||||
/// Enum for the type of table present in libmdbx.
|
||||
@ -128,11 +128,11 @@ table!(
|
||||
|
||||
table!(
|
||||
/// Stores the transaction body from non canonical transactions.
|
||||
NonCanonicalTransactions => BlockNumHashTxNumber => RlpTxBody);
|
||||
NonCanonicalTransactions => BlockNumHashTxNumber => TransactionSigned);
|
||||
|
||||
table!(
|
||||
/// Stores the transaction body from canonical transactions. Canonical only
|
||||
Transactions => TxNumber => RlpTxBody);
|
||||
Transactions => TxNumber => TransactionSigned);
|
||||
|
||||
table!(
|
||||
/// Stores transaction receipts. Canonical only
|
||||
@ -244,8 +244,6 @@ pub type BlockNumHashTxNumber = Vec<u8>;
|
||||
/// Temporary placeholder type for DB.
|
||||
pub type RlpTotalDifficulty = Vec<u8>;
|
||||
/// Temporary placeholder type for DB.
|
||||
pub type RlpTxBody = Vec<u8>;
|
||||
/// Temporary placeholder type for DB.
|
||||
pub type AddressStorageKey = Vec<u8>;
|
||||
/// Temporary placeholder type for DB.
|
||||
pub type Bytecode = Vec<u8>;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
use reth_codecs::main_codec;
|
||||
use reth_rlp::{Decodable, DecodeError, Encodable};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use serde::{Deserialize, Deserializer, Serializer};
|
||||
use std::{
|
||||
borrow::Borrow,
|
||||
clone::Clone,
|
||||
@ -10,7 +11,8 @@ use std::{
|
||||
use thiserror::Error;
|
||||
|
||||
/// Wrapper type around Bytes to deserialize/serialize "0x" prefixed ethereum hex strings
|
||||
#[derive(Clone, Default, PartialEq, Eq, Hash, Serialize, Deserialize, Ord, PartialOrd)]
|
||||
#[main_codec]
|
||||
#[derive(Clone, Default, PartialEq, Eq, Hash, Ord, PartialOrd)]
|
||||
pub struct Bytes(
|
||||
#[serde(serialize_with = "serialize_bytes", deserialize_with = "deserialize_bytes")]
|
||||
pub bytes::Bytes,
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
use reth_codecs::main_codec;
|
||||
use reth_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{Address, H256};
|
||||
|
||||
/// A list of addresses and storage keys that the transaction plans to access.
|
||||
/// Accesses outside the list are possible, but become more expensive.
|
||||
#[derive(
|
||||
Clone, Debug, PartialEq, Eq, Hash, Default, RlpDecodable, RlpEncodable, Serialize, Deserialize,
|
||||
)]
|
||||
#[main_codec]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Default, RlpDecodable, RlpEncodable)]
|
||||
pub struct AccessListItem {
|
||||
/// Account addresses that would be loaded at the start of execution
|
||||
pub address: Address,
|
||||
@ -16,16 +15,6 @@ pub struct AccessListItem {
|
||||
}
|
||||
|
||||
/// AccessList as defined in EIP-2930
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
PartialEq,
|
||||
Eq,
|
||||
Hash,
|
||||
Default,
|
||||
RlpDecodableWrapper,
|
||||
RlpEncodableWrapper,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
)]
|
||||
#[main_codec]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Default, RlpDecodableWrapper, RlpEncodableWrapper)]
|
||||
pub struct AccessList(pub Vec<AccessListItem>);
|
||||
|
||||
@ -6,6 +6,7 @@ use crate::{Address, Bytes, TxHash, U256};
|
||||
pub use access_list::{AccessList, AccessListItem};
|
||||
use bytes::Buf;
|
||||
use ethers_core::utils::keccak256;
|
||||
use reth_codecs::main_codec;
|
||||
use reth_rlp::{length_of_length, Decodable, DecodeError, Encodable, Header, EMPTY_STRING_CODE};
|
||||
pub use signature::Signature;
|
||||
use std::ops::Deref;
|
||||
@ -13,6 +14,7 @@ pub use tx_type::TxType;
|
||||
|
||||
/// Raw Transaction.
|
||||
/// Transaction type is introduced in EIP-2718: https://eips.ethereum.org/EIPS/eip-2718
|
||||
#[main_codec]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum Transaction {
|
||||
/// Legacy transaciton.
|
||||
@ -388,6 +390,7 @@ impl Encodable for Transaction {
|
||||
}
|
||||
|
||||
/// Whether or not the transaction is a contract creation.
|
||||
#[main_codec]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum TransactionKind {
|
||||
/// A transaction that creates a contract.
|
||||
@ -428,11 +431,15 @@ impl Decodable for TransactionKind {
|
||||
}
|
||||
|
||||
/// Signed transaction.
|
||||
#[main_codec]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TransactionSigned {
|
||||
transaction: Transaction,
|
||||
hash: TxHash,
|
||||
signature: Signature,
|
||||
/// Raw transaction info
|
||||
pub transaction: Transaction,
|
||||
/// Transaction hash
|
||||
pub hash: TxHash,
|
||||
/// The transaction signature values
|
||||
pub signature: Signature,
|
||||
}
|
||||
|
||||
impl AsRef<Transaction> for TransactionSigned {
|
||||
@ -456,6 +463,7 @@ impl Encodable for TransactionSigned {
|
||||
// add the length of the RLP header
|
||||
len + length_of_length(len)
|
||||
}
|
||||
|
||||
fn encode(&self, out: &mut dyn bytes::BufMut) {
|
||||
if let Transaction::Legacy { chain_id, .. } = self.transaction {
|
||||
let header = Header { list: true, payload_length: self.payload_len() };
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
use reth_codecs::main_codec;
|
||||
use reth_rlp::{Decodable, DecodeError, Encodable};
|
||||
|
||||
use crate::U256;
|
||||
@ -5,6 +6,7 @@ use crate::U256;
|
||||
/// r, s: Values corresponding to the signature of the
|
||||
/// transaction and used to determine the sender of
|
||||
/// the transaction; formally Tr and Ts. This is expanded in Appendix F of yellow paper.
|
||||
#[main_codec]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Signature {
|
||||
/// The R field of the signature; the point on the curve.
|
||||
|
||||
Reference in New Issue
Block a user