Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
return Bytes instead
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Dec 7, 2021
1 parent 38dcba1 commit dccec40
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions ethers-solc/src/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<LinkedByteCode> {
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
Expand Down Expand Up @@ -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<LinkedByteCode> 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 {
Expand Down

0 comments on commit dccec40

Please sign in to comment.