0

I am using a data separation pattern, keeping my data in a contract and the business logic in a separate contract that calls the storage one to add/update/delete records.

In order to send the Data struct as an argument in those CRUD functions, would it be acceptable to create a third "types" contract and inherit the types both from "logic" and "storage" contracts?

// Types.sol

contract Types {
  struct Data {
    ...attributes
  }
}
// Logic.sol

contract Logic is Types {
  function someFunction(type1 param1, type2 param2) {
    Data data = Data(param1, param2);
    storage.someFunction(data);
  }
}

// Storage.sol

contract Storage is Types {
  function someFunction(Data data) onlyLogic { ... }
}

1 Answer 1

0

No problem at all. Inheritance in Solidity is essentially fake. The reality is, at compile-time, you will end up with all the functions merged in a single smart contract. It's just a way to separate code mentally. If you extend a contract many times (with many is Types in your case), Solidity adds functions from Types contract only once in any case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.