0

I am trying to design architecture along with implementation of smart contracts. I have two main problems actually, they both can be found conceptual. To make it more understandable, I will not go over with my current implementation instead, I will simplify my questions with following piece of code.

    pragma solidity ^0.4.20;


    contract bigBrother is Ownable {
            // Option-1 Store goalPoint&assistPoint&prize here.
            // Add setter&getter methods
    }

    contract goalRegistry{
        mapping(address => uint) public totalPoints;
        uint goalPoint;
        uint assistPoint;
        address[] playerAddresses;
        uint prize;
        address[] legends;

        function getPointsByPlayer(address player) constant returns(uint){
            return totalPoints[player];
        }

        function addPlayer(address player) constant returns(uint){
            return playerAddresses.push(player);
        }

        // Option-2 Store everything here and add setter & getter

    }

    contract assistController is goalRegistry{
        function assistGoal(address player) constant returns(uint){
            totalPoints[player] += assistPoint;
            return totalPoints[player];
        }
    }

    contract goalController is goalRegistry{
        function scoreGoal(address player) constant returns(uint){
            totalPoints[player += goalPoint;
            return totalPoints[player];
        }
    }

I have read some about upgradeable smart contracts such https://hackernoon.com/upgradeable-smart-contracts-a7e9aef76fdd. Currently, I have an inheritance like following

  • AsistController is derived from goalRegistry.
  • goalController is derived from goalRegistry.

I have deployed all three contracts using truffle and assume the goalRegistry is at "StorageAddress". Later on, I decided to modify asistController and make re-deployment. I can't see any reason for newly deployed contract to point goalRegistry at "StorageAddress". It would possibly deploy a new goalRegistry and point the structs in new deployment address.

1) How would I achieve my goal(point "StorageAddress") with minimal additional gas cost?

I have constant variables that can be changed only by BigBrother like prize,goalPoint and assistPoint. And also, BigBrother can add some players to legends. It's obvious that I have to write a setterLegend method for it in goalRegistry contract. Then,I must write a new function in bigBrother that calls setterLegend. I have looked for some posts such Can a smart contract set a variable from an other known smart contract?

Another pattern that I thought for this problem is to store these variables in bigBrother. Therefore, It could be easily set from this contract, and other contracts may read from bigBrother contract. But, I also don't want goalRegistry is derived from bigBrother.

I am very confused about that it creates my next question. Only owner of BigBrother contract must be able to set goalPoint or prize value in goalRegistry basically.

2) What kind of design pattern should be followed for correct inheritance tree ?

Thanks a lot for your valuable time, Please ask me to clarify myself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.