Skip to content

Instantly share code, notes, and snippets.

@sorXCode
Created February 2, 2022 00:32
Show Gist options
  • Save sorXCode/1a90ab54efd93870c14df0a98b2c1100 to your computer and use it in GitHub Desktop.
Save sorXCode/1a90ab54efd93870c14df0a98b2c1100 to your computer and use it in GitHub Desktop.
ENS snippet
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract ENS {
// pricing: would be determined by number of characters in the desired name
// ownership: 1. one address can only have one ENS
// 2. user desired name is the ens
// 3. if name is taken, return 'unavailable'
// 4. extension is .w3bridge
// 5. ens purchased is valid for 1month
// -------------------
// Incentive for early adoptors, after 2weeks
// price -> 3char = 100; 4chars = 50; >=5 = 30
enum Price {
SHORT, // 3chars
MEDIUM, // 4chars
LONG // >=5chars
}
mapping(address => string) public address_ens_map;
mapping(string => bool) public registered_ens;
string constant EXTENSION = ".w3bridge";
// ?should we create an Error for 'unavailable'
// modifier checkConditions(string memory _name){
// // check whether address is mapped to a name already
// require(keccak256(abi.encodePacked(address_ens_map[msg.sender])) == keccak256(abi.encodePacked("")), "Sorry, you can only have one name per address");
// require(bytes(_name).length>=3, "Sorry, name too short.");
// require(!registered_ens[_name], "Sorry, this name is taken");
// _;
// }
// creates the ens for an address
function create_ens(string memory _name) public returns(string memory) {
if (bytes(_name).length<=2){
revert("Sorry, name too short.");
}
// check whether address is mapped to a name already
if (keccak256(abi.encodePacked(address_ens_map[msg.sender])) != keccak256(abi.encodePacked(""))){
revert("Sorry, you can only have one name per address");
}
if (registered_ens[_name]) {
revert("Sorry, this name is taken");
}
address_ens_map[msg.sender] = string(abi.encodePacked(_name, EXTENSION));
registered_ens[_name] = true;
return address_ens_map[msg.sender];
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
contract GeneralRoom {
enum ChargerMaker {
LENOVO,
HP_BIG_MOUTH,
HP_SMALL_MOUTH,
APPLE
}
enum LaptopSize{
LARGE,
MEDIUM,
SMALL
}
struct Laptop{
// suggestions: uint and enum
uint8 screen_size;
// suggestions: bytes, enum, string
bytes32 color;
// suggestions: enums, string
// chargers are identified by their maker e.g lenovo, hp, apple
ChargerMaker charger;
// suggestions: bool, enums
// valid options are {full_keyboard, or not_full_keyboard}
bool keyboard;
}
struct Chair{
// suggestions: bytes, enum, string
bytes color;
// suggestions: enumn, string
// valid optins are {big, small, medium}
// !Adventure! use struct for size
LaptopSize size;
string shape;
// to signify it's state {faulty or not faulty}
bool condition;
}
Laptop public jumoke_laptop;
Laptop abdul_laptop;
Laptop eric_laptop;
function getAdbulLaptop() public view returns(Laptop memory) {
return abdul_laptop;
}
function setAbdulLaptop(uint8 _screen, bytes32 _color, ChargerMaker _charger, bool _keyboard) public {
abdul_laptop = Laptop({
screen_size: _screen,
color: _color,
charger: _charger,
keyboard: _keyboard
});
}
function convertToByte32(string memory _value) public pure returns (bytes32){
return bytes32(bytes(_value));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment