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

AccessLists #489

Merged
merged 2 commits into from
Apr 30, 2021
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
5 changes: 5 additions & 0 deletions src/api/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ mod tests {
from: None, to: Some(Address::from_low_u64_be(0x123)),
gas: None, gas_price: None,
value: Some(0x1.into()), data: None,
transaction_type: None, access_list: None,
}, None
=>
"eth_call", vec![r#"{"to":"0x0000000000000000000000000000000000000123","value":"0x1"}"#, r#""latest""#];
Expand Down Expand Up @@ -517,6 +518,7 @@ mod tests {
from: None, to: Some(Address::from_low_u64_be(0x123)),
gas: None, gas_price: None,
value: Some(0x1.into()), data: None,
transaction_type: None, access_list: None,
}, None
=>
"eth_estimateGas", vec![r#"{"to":"0x0000000000000000000000000000000000000123","value":"0x1"}"#];
Expand All @@ -528,6 +530,7 @@ mod tests {
from: None, to: None,
gas: None, gas_price: None,
value: Some(0x1.into()), data: None,
transaction_type: None, access_list: None,
}, None
=>
"eth_estimateGas", vec![r#"{"value":"0x1"}"#];
Expand All @@ -539,6 +542,7 @@ mod tests {
from: None, to: Some(Address::from_low_u64_be(0x123)),
gas: None, gas_price: None,
value: Some(0x1.into()), data: None,
transaction_type: None, access_list: None,
}, Some(0x123.into())
=>
"eth_estimateGas", vec![r#"{"to":"0x0000000000000000000000000000000000000123","value":"0x1"}"#, r#""0x123""#];
Expand Down Expand Up @@ -776,6 +780,7 @@ mod tests {
gas: None, gas_price: Some(0x1.into()),
value: Some(0x1.into()), data: None,
nonce: None, condition: None,
transaction_type: None, access_list: None,
}
=>
"eth_sendTransaction", vec![r#"{"from":"0x0000000000000000000000000000000000000123","gasPrice":"0x1","to":"0x0000000000000000000000000000000000000123","value":"0x1"}"#];
Expand Down
8 changes: 7 additions & 1 deletion src/api/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ mod tests {
gas_price: None,
value: Some(0x1.into()),
data: None,
transaction_type: None,
access_list: None,
},
CallRequest {
from: Some(Address::from_low_u64_be(0x321)),
Expand All @@ -105,14 +107,18 @@ mod tests {
gas_price: None,
value: None,
data: Some(hex!("0493").into()),
transaction_type: None,
access_list: None,
},
CallRequest {
from: None,
to: Some(Address::from_low_u64_be(0x765)),
gas: None,
gas_price: None,
value: Some(0x5.into()),
data: Some(hex!("0723").into())
data: Some(hex!("0723").into()),
transaction_type: None,
access_list: None,
}
] => "parity_call", vec![
r#"[{"to":"0x0000000000000000000000000000000000000123","value":"0x1"},{"data":"0x0493","from":"0x0000000000000000000000000000000000000321","to":"0x0000000000000000000000000000000000000123"},{"data":"0x0723","to":"0x0000000000000000000000000000000000000765","value":"0x5"}]"#
Expand Down
3 changes: 3 additions & 0 deletions src/api/personal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ mod tests {
gas: None, gas_price: Some(0x1.into()),
value: Some(0x1.into()), data: None,
nonce: None, condition: None,
transaction_type: None, access_list: None,
}, "hunter2"
=>
"personal_sendTransaction", vec![r#"{"from":"0x0000000000000000000000000000000000000123","gasPrice":"0x1","to":"0x0000000000000000000000000000000000000123","value":"0x1"}"#, r#""hunter2""#];
Expand All @@ -158,6 +159,8 @@ mod tests {
data: Some(hex!("603880600c6000396000f300603880600c6000396000f3603880600c6000396000f360").into()),
nonce: Some(0x0.into()),
condition: None,
transaction_type: None,
access_list: None,
}, "hunter2"
=>
"personal_signTransaction", vec![r#"{"data":"0x603880600c6000396000f300603880600c6000396000f3603880600c6000396000f360","from":"0x407d73d8a49eeb85d32cf465507dd71d507100c1","gas":"0x7f110","gasPrice":"0x9184e72a000","nonce":"0x0","to":"0x853f43d8a49eeb85d32cf465507dd71d507100c1","value":"0x7f110"}"#, r#""hunter2""#];
Expand Down
1 change: 1 addition & 0 deletions src/api/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ mod tests {
from: None, to: Some(Address::from_low_u64_be(0x123)),
gas: None, gas_price: None,
value: Some(0x1.into()), data: None,
transaction_type: None, access_list: None,
}, vec![TraceType::Trace], None
=>
"trace_call", vec![r#"{"to":"0x0000000000000000000000000000000000000123","value":"0x1"}"#, r#"["trace"]"#, r#""latest""#];
Expand Down
3 changes: 3 additions & 0 deletions src/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ mod tests {
data: None,
nonce: None,
condition: None,
transaction_type: None,
access_list: None,
};

let transaction_receipt = TransactionReceipt {
Expand All @@ -155,6 +157,7 @@ mod tests {
status: Some(1.into()),
root: Some(H256::zero()),
logs_bloom: Default::default(),
transaction_type: None,
};

let poll_interval = Duration::from_secs(0);
Expand Down
4 changes: 4 additions & 0 deletions src/contract/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ impl<T: Transport> Builder<T> {
.data
.expect("Tried to deploy a contract but transaction data wasn't set"),
chain_id,
transaction_type: tx.transaction_type,
access_list: tx.access_list,
};
let signed_tx = crate::api::Accounts::new(transport.clone())
.sign_transaction(tx, from)
Expand Down Expand Up @@ -204,6 +206,8 @@ impl<T: Transport> Builder<T> {
nonce: options.nonce,
data: Some(Bytes(data)),
condition: options.condition,
transaction_type: options.transaction_type,
access_list: options.access_list,
};
let receipt = send(tx).await?;
match receipt.status {
Expand Down
18 changes: 16 additions & 2 deletions src/contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::{
contract::tokens::{Detokenize, Tokenize},
futures::Future,
types::{
Address, BlockId, Bytes, CallRequest, FilterBuilder, TransactionCondition, TransactionReceipt,
TransactionRequest, H256, U256,
AccessList, Address, BlockId, Bytes, CallRequest, FilterBuilder, TransactionCondition, TransactionReceipt,
TransactionRequest, H256, U256, U64,
},
Transport,
};
Expand Down Expand Up @@ -35,6 +35,10 @@ pub struct Options {
pub nonce: Option<U256>,
/// A condition to satisfy before including transaction.
pub condition: Option<TransactionCondition>,
/// Transaction type, Some(1) for AccessList transaction, None for Legacy
pub transaction_type: Option<U64>,
/// Access list
pub access_list: Option<AccessList>,
}

impl Options {
Expand Down Expand Up @@ -127,6 +131,8 @@ impl<T: Transport> Contract<T> {
value,
nonce,
condition,
transaction_type,
access_list,
} = options;
self.eth
.send_transaction(TransactionRequest {
Expand All @@ -138,6 +144,8 @@ impl<T: Transport> Contract<T> {
nonce,
data: Some(Bytes(data)),
condition,
transaction_type,
access_list,
})
.await
.map_err(Error::from)
Expand Down Expand Up @@ -170,6 +178,8 @@ impl<T: Transport> Contract<T> {
nonce: options.nonce,
data: Some(Bytes(fn_data)),
condition: options.condition,
transaction_type: options.transaction_type,
access_list: options.access_list,
};
confirm::send_transaction_with_confirmation(
self.eth.transport().clone(),
Expand All @@ -195,6 +205,8 @@ impl<T: Transport> Contract<T> {
gas_price: options.gas_price,
value: options.value,
data: Some(Bytes(data)),
transaction_type: options.transaction_type,
access_list: options.access_list,
},
None,
)
Expand Down Expand Up @@ -234,6 +246,8 @@ impl<T: Transport> Contract<T> {
gas_price: options.gas_price,
value: options.value,
data: Some(Bytes(call)),
transaction_type: options.transaction_type,
access_list: options.access_list,
},
block.into(),
);
Expand Down
2 changes: 1 addition & 1 deletion src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub use self::{
AccountDiff, BlockTrace, ChangedType, Diff, MemoryDiff, StateDiff, StorageDiff, TraceType, TransactionTrace,
VMExecutedOperation, VMOperation, VMTrace,
},
transaction::{RawTransaction, Receipt as TransactionReceipt, Transaction},
transaction::{AccessList, AccessListItem, RawTransaction, Receipt as TransactionReceipt, Transaction},
transaction_id::TransactionId,
transaction_request::{CallRequest, TransactionCondition, TransactionRequest},
txpool::{TxpoolContentInfo, TxpoolInspectInfo, TxpoolStatus},
Expand Down
12 changes: 11 additions & 1 deletion src/types/signed.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::types::{Address, Bytes, CallRequest, H256, U256};
use crate::types::{AccessList, Address, Bytes, CallRequest, H256, U256, U64};
use serde::{Deserialize, Serialize};

/// Struct representing signed data returned from `Accounts::sign` method.
Expand Down Expand Up @@ -53,6 +53,10 @@ pub struct TransactionParameters {
pub data: Bytes,
/// The chain ID (None for network ID)
pub chain_id: Option<u64>,
/// Transaction type, Some(1) for AccessList transaction, None for Legacy
pub transaction_type: Option<U64>,
/// Access list
pub access_list: Option<AccessList>,
}

/// The default fas for transactions.
Expand All @@ -73,6 +77,8 @@ impl Default for TransactionParameters {
value: U256::zero(),
data: Bytes::default(),
chain_id: None,
transaction_type: None,
access_list: None,
}
}
}
Expand All @@ -87,6 +93,8 @@ impl From<CallRequest> for TransactionParameters {
value: call.value.unwrap_or_default(),
data: call.data.unwrap_or_default(),
chain_id: None,
transaction_type: call.transaction_type,
access_list: call.access_list,
}
}
}
Expand All @@ -100,6 +108,8 @@ impl Into<CallRequest> for TransactionParameters {
gas_price: self.gas_price,
value: Some(self.value),
data: Some(self.data),
transaction_type: self.transaction_type,
access_list: self.access_list,
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/types/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ pub struct Transaction {
/// Raw transaction data
#[serde(default, skip_serializing_if = "Option::is_none")]
pub raw: Option<Bytes>,
/// Transaction type, Some(1) for AccessList transaction, None for Legacy
#[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
pub transaction_type: Option<U64>,
/// Access list
#[serde(rename = "accessList", default, skip_serializing_if = "Option::is_none")]
pub access_list: Option<AccessList>,
}

/// "Receipt" of an executed transaction: details of its execution.
Expand Down Expand Up @@ -80,6 +86,9 @@ pub struct Receipt {
/// Logs bloom
#[serde(rename = "logsBloom")]
pub logs_bloom: H2048,
/// Transaction type, Some(1) for AccessList transaction, None for Legacy
#[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
pub transaction_type: Option<U64>,
}

/// Raw bytes of a signed, but not yet sent transaction
Expand All @@ -91,6 +100,19 @@ pub struct RawTransaction {
pub tx: Transaction,
}

/// Access list
pub type AccessList = Vec<AccessListItem>;

/// Access list item
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AccessListItem {
/// Accessed address
pub address: H160,
/// Accessed storage keys
pub storage_keys: Vec<H256>,
}

#[cfg(test)]
mod tests {
use super::{RawTransaction, Receipt};
Expand Down
18 changes: 17 additions & 1 deletion src/types/transaction_request.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::types::{Address, Bytes, U256};
use crate::types::{AccessList, Address, Bytes, U256, U64};
use serde::{Deserialize, Serialize};

/// Call contract request (eth_call / eth_estimateGas)
Expand Down Expand Up @@ -27,6 +27,12 @@ pub struct CallRequest {
/// Data (None for empty data)
#[serde(skip_serializing_if = "Option::is_none")]
pub data: Option<Bytes>,
/// Transaction type, Some(1) for AccessList transaction, None for Legacy
#[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
pub transaction_type: Option<U64>,
/// Access list
#[serde(rename = "accessList", default, skip_serializing_if = "Option::is_none")]
pub access_list: Option<AccessList>,
}

/// Send Transaction Parameters
Expand Down Expand Up @@ -56,6 +62,12 @@ pub struct TransactionRequest {
/// Min block inclusion (None for include immediately)
#[serde(skip_serializing_if = "Option::is_none")]
pub condition: Option<TransactionCondition>,
/// Transaction type, Some(1) for AccessList transaction, None for Legacy
#[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
pub transaction_type: Option<U64>,
/// Access list
#[serde(rename = "accessList", default, skip_serializing_if = "Option::is_none")]
pub access_list: Option<AccessList>,
}

/// Represents condition on minimum block number or block timestamp.
Expand Down Expand Up @@ -85,6 +97,8 @@ mod tests {
gas_price: None,
value: Some(5_000_000.into()),
data: Some(hex!("010203").into()),
transaction_type: None,
access_list: None,
};

// when
Expand Down Expand Up @@ -132,6 +146,8 @@ mod tests {
data: Some(hex!("010203").into()),
nonce: None,
condition: Some(TransactionCondition::Block(5)),
transaction_type: None,
access_list: None,
};

// when
Expand Down