DEV Community

Discussion on: AppStorage Pattern for State Variables in Solidity

Collapse
 
binzydev profile image
Binzy

The s. is pretty great. Hey have you run into any storage access issues? I cut a new facet and use a library get() function like someFunction() that returns the slot (hashed with keccak256). But it returns empty storage. It's definitely the same diamond contract but seems to get mixed up. Maybe I did something wrong?

library ArcaneBarracksStorage {
bytes32 constant namespace = keccak256("game.arcane.storage.barracks");

struct Storage {
    mapping (address => mapping (uint8 => uint256)) items;
}

function get() internal pure returns (Storage storage s) {
    bytes32 addr = namespace;
    assembly {
        s.slot := addr
    }
}
Enter fullscreen mode Exit fullscreen mode

}

Thread Thread
 
mudgen profile image
Nick Mudge

You will run into trouble if you declare state variables outside AppStorage or DiamondStorage or inherit contracts that do that.