Created
October 18, 2022 19:50
-
-
Save amarachiugwu/6dbb6672327f0a26c822f23a3e504f9c to your computer and use it in GitHub Desktop.
Unoptimized gas golfer contract
This file contains hidden or 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
| contract Golfer { | |
| struct Data{ | |
| //always a preset date | |
| uint256 timeStart; | |
| //30 days after the start | |
| uint256 timeFinish; | |
| //names are at most 3 characters long | |
| string name; | |
| bool active; | |
| address owner; | |
| } | |
| // sample data | |
| // [1,1,"tay",true,0xd9145CCE52D386f254917e481eB44e9943F39138] | |
| mapping(uint=>Data) data; | |
| function writeInto(Data memory d) public { | |
| data[0]=d; | |
| } | |
| function check() public view returns(Data memory d){ | |
| d=data[0]; | |
| } | |
| } |
This file contains hidden or 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
| // optimized gas golfer contract | |
| contract OptiGolfer { | |
| // uint constant timeStart = 1; | |
| // uint constant timeFinish = 1 + 30 days; | |
| struct Data{ | |
| //always a preset date | |
| uint8 timeStart; | |
| //30 days after the start | |
| uint24 timeFinish; | |
| //names are at most 3 characters long | |
| bytes7 name; | |
| bool active; | |
| address owner; | |
| } | |
| mapping(uint=>Data) data; | |
| function writeInto(Data memory d) public { | |
| data[0]=d; | |
| } | |
| function check() public view returns(Data memory d){ | |
| d=data[0]; | |
| } | |
| function getBytes(string memory _name) external pure returns(bytes7 name) { | |
| name = bytes7(abi.encodePacked(_name)); | |
| } | |
| } | |
| // sample data | |
| // [1,5,"0x74617900000000",true,"0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2"] | |
| // name==tay | |
| // active==true | |
| // owner=msg.sender |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment