Skip to content

Commit

Permalink
GH-744: Added batch lifetime
Browse files Browse the repository at this point in the history
  • Loading branch information
Syther007 committed Oct 10, 2023
1 parent 5b25bce commit ffe6b81
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
10 changes: 6 additions & 4 deletions node/src/blockchain/batch_payable_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use web3::transports::Batch;
use web3::types::{Bytes, SignedTransaction, TransactionParameters, H256};
use web3::{BatchTransport, Error as Web3Error, Web3};

pub trait BatchPayableTools<T>
pub trait BatchPayableTools<'batch, T>
where
T: BatchTransport,
T: BatchTransport + 'batch,
{
fn sign_transaction(
&self,
Expand Down Expand Up @@ -48,7 +48,9 @@ impl<T: BatchTransport> Default for BatchPayableToolsReal<T> {
}
}

impl<T: BatchTransport + Debug> BatchPayableTools<T> for BatchPayableToolsReal<T> {
impl<'batch, T: BatchTransport + Debug + 'batch> BatchPayableTools<'batch, T>
for BatchPayableToolsReal<T>
{
fn sign_transaction(
&self,
transaction_params: TransactionParameters,
Expand Down Expand Up @@ -89,7 +91,7 @@ impl<T: BatchTransport + Debug> BatchPayableTools<T> for BatchPayableToolsReal<T
) -> Box<dyn Future<Item = Vec<web3::transports::Result<Value>>, Error = Web3Error>> {
Box::new(web3.transport().submit_batch())
}
}
}:w

#[cfg(test)]
mod tests {
Expand Down
12 changes: 6 additions & 6 deletions node/src/blockchain/blockchain_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,14 @@ impl BlockchainInterfaceNull {
}
}

pub struct BlockchainInterfaceWeb3<T: BatchTransport + Debug> {
pub struct BlockchainInterfaceWeb3<'batch, T: BatchTransport + Debug> {
logger: Logger,
chain: Chain,
// This must not be dropped for Web3 requests to be completed
_event_loop_handle: EventLoopHandle,
web3: Web3<T>,
batch_web3: Web3<Batch<T>>,
batch_payable_tools: Box<dyn BatchPayableTools<T>>,
batch_payable_tools: Box<dyn BatchPayableTools<'batch, T>>,
contract: Contract<T>,
}

Expand All @@ -322,9 +322,9 @@ pub fn to_wei(gwub: u64) -> U256 {
subgwei.full_mul(GWEI).try_into().expect("Internal Error")
}

impl<T> BlockchainInterface for BlockchainInterfaceWeb3<T>
impl<'batch, T> BlockchainInterface for BlockchainInterfaceWeb3<'batch, T>
where
T: BatchTransport + Debug + 'static,
T: BatchTransport + Debug + 'batch,
{
fn contract_address(&self) -> Address {
self.chain.rec().contract
Expand Down Expand Up @@ -572,9 +572,9 @@ pub struct RpcPayableFailure {

type HashAndAmountResult = Result<Vec<(H256, u128)>, PayableTransactionError>;

impl<T> BlockchainInterfaceWeb3<T>
impl<'batch, T> BlockchainInterfaceWeb3<'batch, T>
where
T: BatchTransport + Debug + 'static,
T: BatchTransport + Debug + 'batch,
{
pub fn new(transport: T, event_loop_handle: EventLoopHandle, chain: Chain) -> Self {
let web3 = Web3::new(transport.clone());
Expand Down
8 changes: 4 additions & 4 deletions node/src/blockchain/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,11 @@ pub fn make_fake_event_loop_handle() -> EventLoopHandle {
}

#[derive(Default)]
pub struct BatchPayableToolsFactoryMock<T> {
make_results: RefCell<Vec<Box<dyn BatchPayableTools<T>>>>,
pub struct BatchPayableToolsFactoryMock<'batch, T> {
make_results: RefCell<Vec<Box<dyn BatchPayableTools<'batch, T>>>>,
}

impl<T> BatchPayableToolsFactoryMock<T> {
impl<'batch, T> BatchPayableToolsFactoryMock<'batch, T> {
pub fn make_result(self, result: Box<dyn BatchPayableTools<T>>) -> Self {
self.make_results.borrow_mut().push(result);
self
Expand Down Expand Up @@ -412,7 +412,7 @@ pub struct BatchPayableToolsMock<T: BatchTransport> {
RefCell<Vec<Result<Vec<web3::transports::Result<rpc::Value>>, Web3Error>>>,
}

impl<T: BatchTransport> BatchPayableTools<T> for BatchPayableToolsMock<T> {
impl<'batch, T: BatchTransport + 'batch> BatchPayableTools<'batch, T> for BatchPayableToolsMock<T> {
fn sign_transaction(
&self,
transaction_params: TransactionParameters,
Expand Down

0 comments on commit ffe6b81

Please sign in to comment.