From dccec409b10f281367e45ab78d72513b58796f96 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 7 Dec 2021 04:51:37 +0100 Subject: [PATCH] return Bytes instead --- ethers-solc/src/artifacts.rs | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/ethers-solc/src/artifacts.rs b/ethers-solc/src/artifacts.rs index f3c7d95e6c..be0ce23e0d 100644 --- a/ethers-solc/src/artifacts.rs +++ b/ethers-solc/src/artifacts.rs @@ -840,19 +840,14 @@ impl BytecodeObject { /// Tries to resolve the unlinked string object a valid bytecode object in place /// /// Returns the string if it is a valid - pub fn resolve(&mut self) -> Option { - let mut resolved = None; - + pub fn resolve(&mut self) -> Option<&Bytes> { if let BytecodeObject::Unlinked(unlinked) = self { if let Ok(linked) = hex::decode(unlinked) { - resolved = Some(BytecodeObject::Bytecode(linked.into())); + *self = BytecodeObject::Bytecode(linked.into()); + return self.as_bytes() } } - if let Some(resolved) = resolved { - std::mem::replace(self, resolved).into_unlinked().map(LinkedByteCode) - } else { - None - } + None } /// Link using the fully qualified name of a library @@ -916,16 +911,6 @@ impl AsRef<[u8]> for BytecodeObject { } } -/// A fully linked byte code that represents a valid hex string -#[derive(Debug, Clone)] -pub struct LinkedByteCode(String); - -impl From for Bytes { - fn from(inner: LinkedByteCode) -> Self { - hex::decode(&inner.0).expect("Is valid hex").into() - } -} - #[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)] #[serde(rename_all = "camelCase")] pub struct FunctionDebugData {