|
@@ -200,7 +200,8 @@ impl PolkadotTarget {
|
|
|
fn public_function_prelude<'a>(
|
|
fn public_function_prelude<'a>(
|
|
|
&self,
|
|
&self,
|
|
|
binary: &Binary<'a>,
|
|
binary: &Binary<'a>,
|
|
|
- function: FunctionValue,
|
|
|
|
|
|
|
+ function: FunctionValue<'a>,
|
|
|
|
|
+ storage_initializer: Option<FunctionValue>,
|
|
|
) -> (PointerValue<'a>, IntValue<'a>) {
|
|
) -> (PointerValue<'a>, IntValue<'a>) {
|
|
|
let entry = binary.context.append_basic_block(function, "entry");
|
|
let entry = binary.context.append_basic_block(function, "entry");
|
|
|
|
|
|
|
@@ -211,6 +212,11 @@ impl PolkadotTarget {
|
|
|
.builder
|
|
.builder
|
|
|
.build_call(binary.module.get_function("__init_heap").unwrap(), &[], "");
|
|
.build_call(binary.module.get_function("__init_heap").unwrap(), &[], "");
|
|
|
|
|
|
|
|
|
|
+ // Call the storage initializers on deploy
|
|
|
|
|
+ if let Some(initializer) = storage_initializer {
|
|
|
|
|
+ binary.builder.build_call(initializer, &[], "");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
let scratch_buf = binary.scratch.unwrap().as_pointer_value();
|
|
let scratch_buf = binary.scratch.unwrap().as_pointer_value();
|
|
|
let scratch_len = binary.scratch_len.unwrap().as_pointer_value();
|
|
let scratch_len = binary.scratch_len.unwrap().as_pointer_value();
|
|
|
|
|
|
|
@@ -336,24 +342,29 @@ impl PolkadotTarget {
|
|
|
external!("set_code_hash", i32_type, u8_ptr);
|
|
external!("set_code_hash", i32_type, u8_ptr);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /// Emits the "deploy" function if `init` is `Some`, otherwise emits the "call" function.
|
|
|
|
|
- fn emit_dispatch(&mut self, init: Option<FunctionValue>, bin: &mut Binary, ns: &Namespace) {
|
|
|
|
|
|
|
+ /// Emits the "deploy" function if `storage_initializer` is `Some`, otherwise emits the "call" function.
|
|
|
|
|
+ fn emit_dispatch(
|
|
|
|
|
+ &mut self,
|
|
|
|
|
+ storage_initializer: Option<FunctionValue>,
|
|
|
|
|
+ bin: &mut Binary,
|
|
|
|
|
+ ns: &Namespace,
|
|
|
|
|
+ ) {
|
|
|
let ty = bin.context.void_type().fn_type(&[], false);
|
|
let ty = bin.context.void_type().fn_type(&[], false);
|
|
|
- let export_name = if init.is_some() { "deploy" } else { "call" };
|
|
|
|
|
|
|
+ let export_name = if storage_initializer.is_some() {
|
|
|
|
|
+ "deploy"
|
|
|
|
|
+ } else {
|
|
|
|
|
+ "call"
|
|
|
|
|
+ };
|
|
|
let func = bin.module.add_function(export_name, ty, None);
|
|
let func = bin.module.add_function(export_name, ty, None);
|
|
|
- let (input, input_length) = self.public_function_prelude(bin, func);
|
|
|
|
|
|
|
+ let (input, input_length) = self.public_function_prelude(bin, func, storage_initializer);
|
|
|
let args = vec![
|
|
let args = vec![
|
|
|
BasicMetadataValueEnum::PointerValue(input),
|
|
BasicMetadataValueEnum::PointerValue(input),
|
|
|
BasicMetadataValueEnum::IntValue(input_length),
|
|
BasicMetadataValueEnum::IntValue(input_length),
|
|
|
BasicMetadataValueEnum::IntValue(self.value_transferred(bin, ns)),
|
|
BasicMetadataValueEnum::IntValue(self.value_transferred(bin, ns)),
|
|
|
BasicMetadataValueEnum::PointerValue(bin.selector.as_pointer_value()),
|
|
BasicMetadataValueEnum::PointerValue(bin.selector.as_pointer_value()),
|
|
|
];
|
|
];
|
|
|
- let dispatch_cfg_name = &init
|
|
|
|
|
- .map(|initializer| {
|
|
|
|
|
- // Call the storage initializers on deploy
|
|
|
|
|
- bin.builder.build_call(initializer, &[], "");
|
|
|
|
|
- DispatchType::Deploy
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ let dispatch_cfg_name = &storage_initializer
|
|
|
|
|
+ .map(|_| DispatchType::Deploy)
|
|
|
.unwrap_or(DispatchType::Call)
|
|
.unwrap_or(DispatchType::Call)
|
|
|
.to_string();
|
|
.to_string();
|
|
|
let cfg = bin.module.get_function(dispatch_cfg_name).unwrap();
|
|
let cfg = bin.module.get_function(dispatch_cfg_name).unwrap();
|