I want to create two contracts in one ink file. The second contract use functions and mapping of the first contract. Here is an example
#[ink::contract]
mod contract_1 {
pub struct Struct1 {}
#[ink(storage)]
pub struct MyContract {}
impl MyContract {
#[ink(constructor)]
pub fn new() -> Self {}
#[ink(constructor)]
pub fn default() -> Self {}
#[ink(message)]
pub fn function_1(&self) -> Option<Struct1> {}
}
}
#[ink::contract]
mod contract_2 {
use super::contract_1::{MyContract, Struct1};
use ink_prelude::string::String;
use ink_storage::traits::SpreadAllocate;
// use ink_storage::Mapping;
#[ink(storage)]
#[derive(SpreadAllocate)]
pub struct Contract2 {
pub contract_parent: MyContract,
}
impl Contract2 {
#[ink(constructor)]
pub fn new() -> Self {
Self {
contract_parent: MyContract::default(),
}
}
#[ink(message)]
pub fn function_2(&self, variable: String) -> Option<Struct1> {
self.contract_parent.function_1(variable)
}
}
}
While compiling this ia ma getting an error "symbol call
is already defined".
It appears in the #[ink(storage)] of the second contract.
How to fix this compilation error?