Created
August 19, 2022 16:18
-
-
Save ashwinYardi/dc0319e0f884de9934c9d248b47256bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity ^0.8.0; | |
contract FacetA { | |
struct DiamondStorage { | |
uint firstVar; | |
uint secondVar; | |
} | |
function getStorage() internal pure returns(DiamondStorage storage ds) { | |
// Specifies a random position in contract storage | |
// This can be done with a keccak256 hash of a unique string as is | |
// done here or other schemes can be used | |
bytes32 storagePosition = keccak256("diamond.storage.facetA"); | |
// Set the position of our struct in contract storage | |
assembly {ds.slot := storagePosition} | |
} | |
function getVars() public view returns(uint, uint) { | |
DiamondStorage storage s = getStorage(); | |
return (s.firstVar, s.secondVar); | |
} | |
} | |
contract FacetB { | |
struct DiamondStorage { | |
string thirdVar; | |
string fourthVar; | |
} | |
function getStorage() internal pure returns(DiamondStorage storage ds) { | |
bytes32 storagePosition = keccak256("diamond.storage.facetB"); | |
assembly {ds.slot := storagePosition} | |
} | |
function setVars() public { | |
DiamondStorage storage s = getStorage(); | |
s.thirdVar = "Ashwin"; | |
s.fourthVar = "Yardi"; | |
} | |
function getVars() public view returns(string memory, string memory) { | |
DiamondStorage storage s = getStorage(); | |
return (s.thirdVar, s.fourthVar); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment