Skip to content

Commit 737014a

Browse files
committed
chain/ethereum: Avoid a clone for EthereumCallData in ABI conversion
1 parent 6bf741d commit 737014a

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

chain/ethereum/src/runtime/abi.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,6 @@ impl AscType for AscLogParamArray {
3737
}
3838
}
3939

40-
impl ToAscObj<AscLogParamArray> for Vec<ethabi::LogParam> {
41-
fn to_asc_obj<H: AscHeap + ?Sized>(
42-
&self,
43-
heap: &mut H,
44-
gas: &GasCounter,
45-
) -> Result<AscLogParamArray, HostExportError> {
46-
let content: Result<Vec<_>, _> = self.iter().map(|x| asc_new(heap, x, gas)).collect();
47-
let content = content?;
48-
Ok(AscLogParamArray(Array::new(&content, heap, gas)?))
49-
}
50-
}
51-
5240
impl ToAscObj<AscLogParamArray> for &[ethabi::LogParam] {
5341
fn to_asc_obj<H: AscHeap + ?Sized>(
5442
&self,
@@ -737,7 +725,7 @@ impl<'a> ToAscObj<AscEthereumCall> for EthereumCallData<'a> {
737725
gas: &GasCounter,
738726
) -> Result<AscEthereumCall, HostExportError> {
739727
Ok(AscEthereumCall {
740-
address: asc_new(heap, &self.to, gas)?,
728+
address: asc_new(heap, self.to(), gas)?,
741729
block: asc_new(heap, &self.block, gas)?,
742730
transaction: asc_new(heap, &self.transaction, gas)?,
743731
inputs: asc_new(heap, &self.inputs, gas)?,
@@ -758,8 +746,8 @@ impl<'a> ToAscObj<AscEthereumCall_0_0_3<AscEthereumTransaction_0_0_2, AscEthereu
758746
HostExportError,
759747
> {
760748
Ok(AscEthereumCall_0_0_3 {
761-
to: asc_new(heap, &self.to, gas)?,
762-
from: asc_new(heap, &self.from, gas)?,
749+
to: asc_new(heap, self.to(), gas)?,
750+
from: asc_new(heap, self.from(), gas)?,
763751
block: asc_new(heap, &self.block, gas)?,
764752
transaction: asc_new(heap, &self.transaction, gas)?,
765753
inputs: asc_new(heap, &self.inputs, gas)?,
@@ -780,8 +768,8 @@ impl<'a> ToAscObj<AscEthereumCall_0_0_3<AscEthereumTransaction_0_0_6, AscEthereu
780768
HostExportError,
781769
> {
782770
Ok(AscEthereumCall_0_0_3 {
783-
to: asc_new(heap, &self.to, gas)?,
784-
from: asc_new(heap, &self.from, gas)?,
771+
to: asc_new(heap, self.to(), gas)?,
772+
from: asc_new(heap, self.from(), gas)?,
785773
block: asc_new(heap, &self.block, gas)?,
786774
transaction: asc_new(heap, &self.transaction, gas)?,
787775
inputs: asc_new(heap, &self.inputs, gas)?,

chain/ethereum/src/trigger.rs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use graph::runtime::AscPtr;
2525
use graph::runtime::HostExportError;
2626
use graph::semver::Version;
2727
use graph_runtime_wasm::module::ToAscPtr;
28-
use std::ops::Deref;
2928
use std::{cmp::Ordering, sync::Arc};
3029

3130
use crate::runtime::abi::AscEthereumBlock;
@@ -192,14 +191,7 @@ impl ToAscPtr for MappingTrigger {
192191
inputs,
193192
outputs,
194193
} => {
195-
let call = EthereumCallData {
196-
to: call.to,
197-
from: call.from,
198-
block: EthereumBlockData::from(block.as_ref()),
199-
transaction: EthereumTransactionData::new(transaction.deref()),
200-
inputs,
201-
outputs,
202-
};
194+
let call = EthereumCallData::new(&block, &transaction, &call, &inputs, &outputs);
203195
if heap.api_version() >= Version::new(0, 0, 6) {
204196
asc_new::<
205197
AscEthereumCall_0_0_3<AscEthereumTransaction_0_0_6, AscEthereumBlock_0_0_6>,
@@ -594,10 +586,35 @@ impl<'a> EthereumEventData<'a> {
594586
/// An Ethereum call executed within a transaction within a block to a contract address.
595587
#[derive(Debug, Clone)]
596588
pub struct EthereumCallData<'a> {
597-
pub from: Address,
598-
pub to: Address,
599589
pub block: EthereumBlockData<'a>,
600590
pub transaction: EthereumTransactionData<'a>,
601-
pub inputs: Vec<LogParam>,
602-
pub outputs: Vec<LogParam>,
591+
pub inputs: &'a [LogParam],
592+
pub outputs: &'a [LogParam],
593+
call: &'a EthereumCall,
594+
}
595+
596+
impl<'a> EthereumCallData<'a> {
597+
fn new(
598+
block: &'a Block<Transaction>,
599+
transaction: &'a Transaction,
600+
call: &'a EthereumCall,
601+
inputs: &'a [LogParam],
602+
outputs: &'a [LogParam],
603+
) -> EthereumCallData<'a> {
604+
EthereumCallData {
605+
block: EthereumBlockData::from(block),
606+
transaction: EthereumTransactionData::new(transaction),
607+
inputs,
608+
outputs,
609+
call,
610+
}
611+
}
612+
613+
pub fn from(&self) -> &Address {
614+
&self.call.from
615+
}
616+
617+
pub fn to(&self) -> &Address {
618+
&self.call.to
619+
}
603620
}

0 commit comments

Comments
 (0)