Skip to content

Commit

Permalink
Merge branch master into evm_queue_state_root_tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouzo committed Sep 7, 2023
2 parents fec2262 + c18c9c9 commit 90fec7c
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 45 deletions.
1 change: 1 addition & 0 deletions lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fmt-check:

.PHONY: fmt
fmt:
$(CARGO) fmt $(CARGO_MANIFEST_ARG) --all
$(CARGO) fmt $(CARGO_MANIFEST_ARG) --all 2> >(grep -v -E 'group_imports|unstable_features|imports_granularity')

clean-local:
$(CARGO) clean $(CARGO_MANIFEST_ARG) && \
Expand Down
1 change: 1 addition & 0 deletions lib/ain-contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ hex.workspace = true
sha3.workspace = true
sp-core.workspace = true
lazy_static.workspace = true
ethabi.workspace = true

[build-dependencies]
ethers.workspace = true
Expand Down
9 changes: 4 additions & 5 deletions lib/ain-contracts/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ fn main() -> Result<()> {
let manifest_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?);
let solc_path_str = env::var("SOLC_PATH")?;

// If TARGET_DIR is set, which we do from Makefile, uses that instead of OUT_DIR.
// Otherwise, use the path for OUT_DIR that cargo sets, as usual.
// We use CARGO_TARGET_DIR from Makefile instead of OUT_DIR.
// Reason: Currently setting --out-dir is nightly only, so there's no way to get OUT_DIR
// out of cargo reliably for pointing deps determinisitcally.
let target_dir: PathBuf = PathBuf::from(env::var("CARGO_TARGET_DIR").or(env::var("OUT_DIR"))?);
// out of cargo reliably for pointing non cargo deps (eg: python test files) determinisitcally.
let target_dir: PathBuf = PathBuf::from(env::var("CARGO_TARGET_DIR")?);
let solc_artifact_dir = target_dir.join("sol_artifacts");

// Solidity project root and contract names relative to our project
Expand Down Expand Up @@ -77,7 +76,7 @@ fn main() -> Result<()> {

fs::create_dir_all(&sol_project_outdir)?;
for (file_name, contents) in items {
fs::write(sol_project_outdir.join(file_name), contents.as_bytes())?
fs::write(sol_project_outdir.join(file_name), contents.as_bytes())?;
}
}

Expand Down
1 change: 0 additions & 1 deletion lib/ain-contracts/dst20/input.json

This file was deleted.

50 changes: 37 additions & 13 deletions lib/ain-contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,30 @@ fn get_bytecode(input: &str) -> Result<Vec<u8>> {
hex::decode(&bytecode_raw[2..]).map_err(|e| format_err!(e.to_string()))
}

pub fn get_dst20_deploy_input(init_bytecode: Vec<u8>, name: &str, symbol: &str) -> Result<Vec<u8>> {
let name = ethabi::Token::String(name.to_string());
let symbol = ethabi::Token::String(symbol.to_string());

let constructor = ethabi::Constructor {
inputs: vec![
ethabi::Param {
name: String::from("name"),
kind: ethabi::ParamType::String,
internal_type: None,
},
ethabi::Param {
name: String::from("symbol"),
kind: ethabi::ParamType::String,
internal_type: None,
},
],
};

constructor
.encode_input(init_bytecode, &[name, symbol])
.map_err(|e| format_err!(e))
}

pub fn dst20_address_from_token_id(token_id: u64) -> Result<H160> {
let number_str = format!("{:x}", token_id);
let padded_number_str = format!("{number_str:0>38}");
Expand All @@ -58,8 +82,8 @@ pub fn intrinsics_address_from_id(id: u64) -> Result<H160> {
#[derive(Clone)]
pub struct Contract {
pub codehash: H256,
pub bytecode: Vec<u8>,
pub input: Vec<u8>,
pub runtime_bytecode: Vec<u8>,
pub init_bytecode: Vec<u8>,
}

#[derive(Clone)]
Expand All @@ -75,8 +99,8 @@ lazy_static::lazy_static! {
FixedContract {
contract: Contract {
codehash: Blake2Hasher::hash(&bytecode),
bytecode,
input: Vec::new(),
runtime_bytecode: bytecode,
init_bytecode: Vec::new(),
},
fixed_address: H160([
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
Expand All @@ -98,8 +122,8 @@ lazy_static::lazy_static! {
FixedContract {
contract: Contract {
codehash: Blake2Hasher::hash(&bytecode),
bytecode,
input,
runtime_bytecode: bytecode,
init_bytecode: input,
},
fixed_address: H160([
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
Expand All @@ -112,14 +136,14 @@ lazy_static::lazy_static! {
let bytecode = solc_artifact_bytecode_str!(
"dst20", "deployed_bytecode.json"
);
let input = get_bytecode(include_str!(
"../dst20/input.json"
)).unwrap();
let input = solc_artifact_bytecode_str!(
"dst20", "bytecode.json"
);

Contract {
codehash: Blake2Hasher::hash(&bytecode),
bytecode,
input,
runtime_bytecode: bytecode,
init_bytecode: input,
}
};

Expand All @@ -131,8 +155,8 @@ lazy_static::lazy_static! {

Contract {
codehash: Blake2Hasher::hash(&bytecode),
bytecode,
input: Vec::new(),
runtime_bytecode: bytecode,
init_bytecode: Vec::new(),
}
};
}
Expand Down
24 changes: 10 additions & 14 deletions lib/ain-evm/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn intrinsics_contract(

Ok(DeployContractInfo {
address: fixed_address,
bytecode: Bytes::from(contract.bytecode),
bytecode: Bytes::from(contract.runtime_bytecode),
storage: vec![
(H256::from_low_u64_be(0), u256_to_h256(U256::one())),
(H256::from_low_u64_be(1), u256_to_h256(evm_block_number)),
Expand All @@ -92,16 +92,16 @@ pub fn transfer_domain_contract() -> Result<DeployContractInfo> {

Ok(DeployContractInfo {
address: fixed_address,
bytecode: Bytes::from(contract.bytecode),
bytecode: Bytes::from(contract.runtime_bytecode),
storage: Vec::new(),
})
}

pub fn dst20_contract(
backend: &EVMBackend,
address: H160,
name: String,
symbol: String,
name: &str,
symbol: &str,
) -> Result<DeployContractInfo> {
match backend.get_account(&address) {
None => {}
Expand All @@ -113,21 +113,17 @@ pub fn dst20_contract(
}
}

let Contract { bytecode, .. } = get_dst20_contract();
let Contract {
runtime_bytecode, ..
} = get_dst20_contract();
let storage = vec![
(
H256::from_low_u64_be(3),
get_abi_encoded_string(name.as_str()),
),
(
H256::from_low_u64_be(4),
get_abi_encoded_string(symbol.as_str()),
),
(H256::from_low_u64_be(3), get_abi_encoded_string(name)),
(H256::from_low_u64_be(4), get_abi_encoded_string(symbol)),
];

Ok(DeployContractInfo {
address,
bytecode: Bytes::from(bytecode),
bytecode: Bytes::from(runtime_bytecode),
storage,
})
}
Expand Down
Loading

0 comments on commit 90fec7c

Please sign in to comment.