Skip to content

Commit

Permalink
update: format code using cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Brianspha committed Nov 28, 2024
1 parent 34e018a commit b2150f7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ impl From<ResolcContractArtifact> for CompactContractBytecode {

impl From<ResolcContractArtifact> for CompactContract {
fn from(value: ResolcContractArtifact) -> Self {
// See https://docs.soliditylang.org/en/develop/abi-spec.html
let (standard_abi, compact_bytecode, _) = create_byte_code(&value);
Self { bin: Some(compact_bytecode.object.clone()), bin_runtime: Some(compact_bytecode.object), abi: Some(standard_abi) }
Self {
bin: Some(compact_bytecode.object.clone()),
bin_runtime: Some(compact_bytecode.object),
abi: Some(standard_abi)
}
}
}

Expand Down Expand Up @@ -100,33 +103,20 @@ impl ResolcArtifactOutput {
contract: Contract,
source_file: Option<&SourceFile>,
) -> ResolcContractArtifact {
/* let Contract {
abi,
metadata,
userdoc,
devdoc,
ir,
storage_layout,
transient_storage_layout,
evm,
ewasm,
ir_optimized,
ir_optimized_ast,
} = contract;
let mut output = ResolcContractArtifact::default();*/
todo!("Implement this function converting standard json to revive json");

todo!("Implement this function converting standard json to revive json")
}
}

fn create_byte_code(
value: &ResolcContractArtifact,
) -> (JsonAbi, CompactBytecode, CompactDeployedBytecode) {
let binding = value.artifact.contracts.clone().unwrap();
let parent_contract =
binding.values().last().and_then(|inner_map| inner_map.values().next()).unwrap();
let abi_array: Vec<serde_json::Value> =
serde_json::from_value(parent_contract.clone().abi.unwrap()).unwrap();
let parent_contract = binding.values()
.last()
.and_then(|inner_map| inner_map.values().next())
.unwrap();

let abi_array: Vec<serde_json::Value> = serde_json::from_value(parent_contract.clone().abi.unwrap()).unwrap();
let mut standard_abi = JsonAbi {
constructor: None,
fallback: None,
Expand All @@ -138,30 +128,29 @@ fn create_byte_code(

for item in abi_array {
match item["type"].as_str() {
Some("constructor") => {
standard_abi.constructor = serde_json::from_value(item).unwrap();
}
Some("fallback") => {
standard_abi.fallback = serde_json::from_value(item).unwrap();
}
Some("receive") => {
standard_abi.receive = serde_json::from_value(item).unwrap();
}
Some("constructor") => standard_abi.constructor = serde_json::from_value(item).unwrap(),
Some("fallback") => standard_abi.fallback = serde_json::from_value(item).unwrap(),
Some("receive") => standard_abi.receive = serde_json::from_value(item).unwrap(),
Some("function") => {
let function: Function = serde_json::from_value(item).unwrap();
standard_abi
.functions
standard_abi.functions
.entry(function.name.clone())
.or_insert_with(Vec::new)
.push(function);
}
Some("event") => {
let event: Event = serde_json::from_value(item).unwrap();
standard_abi.events.entry(event.name.clone()).or_insert_with(Vec::new).push(event);
standard_abi.events
.entry(event.name.clone())
.or_insert_with(Vec::new)
.push(event);
}
Some("error") => {
let error: alloy_json_abi::Error = serde_json::from_value(item).unwrap();
standard_abi.errors.entry(error.name.clone()).or_insert_with(Vec::new).push(error);
standard_abi.errors
.entry(error.name.clone())
.or_insert_with(Vec::new)
.push(error);
}
_ => continue,
}
Expand All @@ -173,8 +162,7 @@ fn create_byte_code(
let raw_deployed_bytecode = binding.object.as_str();

let bytecode = BytecodeObject::Bytecode(Bytes::from(hex::decode(raw_bytecode).unwrap()));
let deployed_bytecode =
BytecodeObject::Bytecode(Bytes::from(hex::decode(raw_deployed_bytecode).unwrap()));
let deployed_bytecode = BytecodeObject::Bytecode(Bytes::from(hex::decode(raw_deployed_bytecode).unwrap()));

let compact_bytecode = CompactBytecode {
object: bytecode,
Expand All @@ -192,4 +180,4 @@ fn create_byte_code(
};

(standard_abi, compact_bytecode, compact_deployed_bytecode)
}
}
2 changes: 1 addition & 1 deletion crates/compilers/src/compilers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use std::{
};

pub mod multi;
pub mod solc;
pub mod resolc;
pub mod solc;
pub mod vyper;
pub use vyper::*;

Expand Down
4 changes: 2 additions & 2 deletions crates/compilers/src/compilers/resolc/input.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use foundry_compilers_artifacts::{Source, Sources, SolcLanguage};
use foundry_compilers_artifacts::{SolcLanguage, Source, Sources};
use semver::Version;
use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -70,4 +70,4 @@ impl ResolcInput {
fn new(language: SolcLanguage, sources: Sources, settings: ResolcSettings) -> Self {
Self { language, sources, settings }
}
}
}
2 changes: 1 addition & 1 deletion crates/compilers/src/compilers/resolc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ mod settings;

pub use compiler::Resolc;
pub use input::{ResolcInput, ResolcVersionedInput};
pub use settings::{ResolcOptimizer, ResolcRestrictions, ResolcSettings};
pub use settings::{ResolcOptimizer, ResolcRestrictions, ResolcSettings};
2 changes: 1 addition & 1 deletion crates/compilers/src/compilers/resolc/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ impl CompilerSettings for ResolcSettings {
fn with_include_paths(self, _include_paths: &BTreeSet<PathBuf>) -> Self {
self
}
}
}

0 comments on commit b2150f7

Please sign in to comment.