Skip to content

Commit

Permalink
fix: calldata need hex bytecode
Browse files Browse the repository at this point in the history
  • Loading branch information
librelois committed Jul 18, 2024
1 parent 4b66d8a commit 67fc5be
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 31 deletions.
29 changes: 0 additions & 29 deletions pallets/moonbeam-foreign-assets/build.rs

This file was deleted.

19 changes: 17 additions & 2 deletions pallets/moonbeam-foreign-assets/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ struct ForeignErc20ConstructorArgs {

pub(crate) struct EvmCaller<T: crate::Config>(core::marker::PhantomData<T>);


// Length of encoded constructor parameters
const PARAMS_LEN: usize = 256;

impl<T: crate::Config> EvmCaller<T> {
/// Deploy foreign asset erc20 contract
pub(crate) fn erc20_create(
Expand All @@ -97,9 +101,20 @@ impl<T: crate::Config> EvmCaller<T> {
ticker: &str,
token_name: &str,
) -> Result<(), Error<T>> {
// Get contract initializer code
let init_code_str = include_str!("../resources/foreign_erc20_initcode.hex");

// The encoded parameters at the end of the initializer bytecode should be removed,
// (the runtime will append the constructor parameters dynamically).
let init_code_end = if init_code_str.len() > PARAMS_LEN {
init_code_str.len() - PARAMS_LEN
} else {
0
};

// Get init code
let mut init = Vec::with_capacity(ERC20_CREATE_MAX_CALLDATA_SIZE);
init.extend_from_slice(include_bytes!("../resources/foreign_erc20_initcode.bin"));
init.extend_from_slice(init_code_str[..init_code_end].as_bytes());

// Add constructor parameters
let args = ForeignErc20ConstructorArgs {
Expand All @@ -122,7 +137,7 @@ impl<T: crate::Config> EvmCaller<T> {
None,
None,
Default::default(),
true,
false,
false,
None,
None,
Expand Down

0 comments on commit 67fc5be

Please sign in to comment.