Created
March 2, 2022 06:03
-
-
Save 5hanth/537548a7186922104e3517b657b900d0 to your computer and use it in GitHub Desktop.
Linky Pinky Ponky
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
library AppTypes { | |
struct ListItem { | |
string content; | |
} | |
struct List { | |
uint256 id; | |
uint256 listItemsCount; | |
ListItem[] listItems; | |
} | |
struct State { | |
mapping(LIST => uint256) id; | |
mapping(uint256 => List) lists; | |
} | |
enum Model { | |
LIST | |
} | |
} |
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
import "./SVGList.sol"; | |
import "./AppTypes.sol"; | |
library Main { | |
using SVGList for AppTypes.List; | |
function newListWithContent(AppTypes.State storage currentState, string memory content) public returns(uint256 newListId) { | |
uint256 newListId = ++currentState.id[AppTypes.Model.LIST]; | |
AppTypes.List storage newList = currentState.lists[newListId]; | |
currentState.lists[currentState.id[AppTypes.Model.LIST]] = newList; | |
newList.id = newListId; | |
newList.addContent(content); | |
return newListId; | |
} | |
function addContentToList(AppTypes.State storage currentState, uint256 listId, string memory content) public { | |
AppTypes.List storage currentList = currentState.lists[listId]; | |
currentList.addContent(content); | |
} | |
} |
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
import "./Main.sol"; | |
import "./AppTypes.sol"; | |
contract Primary { | |
using Main for AppTypes.State; | |
AppTypes.State storage state; | |
function newListWithContent(string memory content) public returns(uint256 newListId) { | |
return state.newListWithContent(content); | |
} | |
function addContentToList(uint256 listId, string memory content) public { | |
state.addContentToList(listId, content); | |
} | |
function getContent(uint256 listId, uint256 index) public view returns (string memory) { | |
return state.getContent(listId, index); | |
} | |
function getId(AppTypes.Model model) public view returns (uint256) { | |
return state.id[model]; | |
} | |
} |
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
import "./AppTypes.sol"; | |
library SVGList { | |
function addContent(AppTypes.List storage currentList, string memory content) public { | |
AppTypes.ListItem storage newListItem = currentList.listItems[++currentList.listItemsCount]; | |
newListItem.content = content; | |
currentList.listItems[currentList.listItemsCount] = newListItem; | |
} | |
function getContent(AppTypes.List storage currentList, uint256 index) public view returns (string memory) { | |
return currentList.listItems[index].content; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment